diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-07-02 15:28:09 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-07-02 15:40:39 +0300 |
commit | 3336f268eb26aa0318cd3fa3f97116c43545f87b (patch) | |
tree | 047395a3b7bf0751a86c5676a9c103e168e47e3c /library/cpp/yt/string/string.h | |
parent | aa95a328ada306559bd361a96c5348829d0e562e (diff) | |
download | ydb-3336f268eb26aa0318cd3fa3f97116c43545f87b.tar.gz |
YT-21868: Reorganize files to prevent unclear missing include errors
Moving files around so that include of either `string_builder.h` or `format.h` would result in being able to use both `Format` and `TStringBuilder`
8a2abbea2ae7027c1cd3a243ab3de55bdd5d3d27
Diffstat (limited to 'library/cpp/yt/string/string.h')
-rw-r--r-- | library/cpp/yt/string/string.h | 83 |
1 files changed, 15 insertions, 68 deletions
diff --git a/library/cpp/yt/string/string.h b/library/cpp/yt/string/string.h index a131b40a2a..8257c1a5ea 100644 --- a/library/cpp/yt/string/string.h +++ b/library/cpp/yt/string/string.h @@ -1,6 +1,6 @@ #pragma once -#include "string_builder.h" +#include "format_arg.h" #include <util/datetime/base.h> @@ -52,37 +52,21 @@ void JoinToString( const TIterator& begin, const TIterator& end, const TFormatter& formatter, - TStringBuf delimiter = DefaultJoinToStringDelimiter) -{ - for (auto current = begin; current != end; ++current) { - if (current != begin) { - builder->AppendString(delimiter); - } - formatter(builder, *current); - } -} + TStringBuf delimiter = DefaultJoinToStringDelimiter); template <class TIterator, class TFormatter> TString JoinToString( const TIterator& begin, const TIterator& end, const TFormatter& formatter, - TStringBuf delimiter = DefaultJoinToStringDelimiter) -{ - TStringBuilder builder; - JoinToString(&builder, begin, end, formatter, delimiter); - return builder.Flush(); -} + TStringBuf delimiter = DefaultJoinToStringDelimiter); //! A handy shortcut with default formatter. template <class TIterator> TString JoinToString( const TIterator& begin, const TIterator& end, - TStringBuf delimiter = DefaultJoinToStringDelimiter) -{ - return JoinToString(begin, end, TDefaultFormatter(), delimiter); -} + TStringBuf delimiter = DefaultJoinToStringDelimiter); //! Joins a collection of given items into a string intermixing them with the delimiter. /*! @@ -94,35 +78,17 @@ template <class TCollection, class TFormatter> TString JoinToString( const TCollection& collection, const TFormatter& formatter, - TStringBuf delimiter = DefaultJoinToStringDelimiter) -{ - using std::begin; - using std::end; - return JoinToString(begin(collection), end(collection), formatter, delimiter); -} + TStringBuf delimiter = DefaultJoinToStringDelimiter); //! A handy shortcut with the default formatter. template <class TCollection> TString JoinToString( const TCollection& collection, - TStringBuf delimiter = DefaultJoinToStringDelimiter) -{ - return JoinToString(collection, TDefaultFormatter(), delimiter); -} + TStringBuf delimiter = DefaultJoinToStringDelimiter); //! Concatenates a bunch of TStringBuf-like instances into TString. template <class... Ts> -TString ConcatToString(Ts... args) -{ - size_t length = 0; - ((length += args.length()), ...); - - TString result; - result.reserve(length); - (result.append(args), ...); - - return result; -} +TString ConcatToString(Ts... args); //! Converts a range of items into strings. template <class TIter, class TFormatter> @@ -130,29 +96,14 @@ std::vector<TString> ConvertToStrings( const TIter& begin, const TIter& end, const TFormatter& formatter, - size_t maxSize = std::numeric_limits<size_t>::max()) -{ - std::vector<TString> result; - for (auto it = begin; it != end; ++it) { - TStringBuilder builder; - formatter(&builder, *it); - result.push_back(builder.Flush()); - if (result.size() == maxSize) { - break; - } - } - return result; -} + size_t maxSize = std::numeric_limits<size_t>::max()); //! A handy shortcut with the default formatter. template <class TIter> std::vector<TString> ConvertToStrings( const TIter& begin, const TIter& end, - size_t maxSize = std::numeric_limits<size_t>::max()) -{ - return ConvertToStrings(begin, end, TDefaultFormatter(), maxSize); -} + size_t maxSize = std::numeric_limits<size_t>::max()); //! Converts a given collection of items into strings. /*! @@ -164,21 +115,13 @@ template <class TCollection, class TFormatter> std::vector<TString> ConvertToStrings( const TCollection& collection, const TFormatter& formatter, - size_t maxSize = std::numeric_limits<size_t>::max()) -{ - using std::begin; - using std::end; - return ConvertToStrings(begin(collection), end(collection), formatter, maxSize); -} + size_t maxSize = std::numeric_limits<size_t>::max()); //! A handy shortcut with default formatter. template <class TCollection> std::vector<TString> ConvertToStrings( const TCollection& collection, - size_t maxSize = std::numeric_limits<size_t>::max()) -{ - return ConvertToStrings(collection, TDefaultFormatter(), maxSize); -} + size_t maxSize = std::numeric_limits<size_t>::max()); //////////////////////////////////////////////////////////////////////////////// @@ -222,3 +165,7 @@ TStringBuf FormatBool(bool value); //////////////////////////////////////////////////////////////////////////////// } // namespace NYT + +#define STRING_INL_H_ +#include "string-inl.h" +#undef STRING_INL_H_ |