diff options
author | babenko <babenko@yandex-team.com> | 2024-10-13 17:47:48 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-10-13 17:58:33 +0300 |
commit | a03ad07f802b86bbf071acbe1358f7e00ca4be34 (patch) | |
tree | 97119051e524f85854516f141e818b81a0f24a39 /library/cpp/yt/string/format.h | |
parent | 9a90e464060c2d7a036a1b94b1076f7ea7e0cc95 (diff) | |
download | ydb-a03ad07f802b86bbf071acbe1358f7e00ca4be34.tar.gz |
Extract string_builder
commit_hash:1573c88f09db79bab2755c9c2c3ffd0bc219b2d2
Diffstat (limited to 'library/cpp/yt/string/format.h')
-rw-r--r-- | library/cpp/yt/string/format.h | 60 |
1 files changed, 1 insertions, 59 deletions
diff --git a/library/cpp/yt/string/format.h b/library/cpp/yt/string/format.h index a6ab1f76f4..5e5a76db9d 100644 --- a/library/cpp/yt/string/format.h +++ b/library/cpp/yt/string/format.h @@ -1,6 +1,7 @@ #pragma once #include "format_string.h" +#include "string_builder.h" #include <util/generic/string.h> @@ -61,65 +62,6 @@ TString Format(TFormatString<TArgs...> format, TArgs&&... args); //////////////////////////////////////////////////////////////////////////////// -// StringBuilder(Base) definition. - -//! A simple helper for constructing strings by a sequence of appends. -class TStringBuilderBase -{ -public: - virtual ~TStringBuilderBase() = default; - - char* Preallocate(size_t size); - - void Reserve(size_t size); - - size_t GetLength() const; - - TStringBuf GetBuffer() const; - - void Advance(size_t size); - - void AppendChar(char ch); - void AppendChar(char ch, int n); - - void AppendString(TStringBuf str); - void AppendString(const char* str); - - template <size_t Length, class... TArgs> - void AppendFormat(const char (&format)[Length], TArgs&&... args); - template <class... TArgs> - void AppendFormat(TStringBuf format, TArgs&&... args); - - void Reset(); - -protected: - char* Begin_ = nullptr; - char* Current_ = nullptr; - char* End_ = nullptr; - - virtual void DoReset() = 0; - virtual void DoReserve(size_t newLength) = 0; - - static constexpr size_t MinBufferLength = 128; -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TStringBuilder - : public TStringBuilderBase -{ -public: - TString Flush(); - -protected: - TString Buffer_; - - void DoReset() override; - void DoReserve(size_t size) override; -}; - -//////////////////////////////////////////////////////////////////////////////// - template <class... TArgs> void Format(TStringBuilderBase* builder, TFormatString<TArgs...> format, TArgs&&... args); |