aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/string.h
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.ru>2022-02-10 16:49:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:19 +0300
commitf31097c96270919a1f49360bdaaa69ea4f3fefab (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/yt/string/string.h
parentcec37806d8847aa3db53bafc9e251d4aaf325c12 (diff)
downloadydb-f31097c96270919a1f49360bdaaa69ea4f3fefab.tar.gz
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/string/string.h')
-rw-r--r--library/cpp/yt/string/string.h346
1 files changed, 173 insertions, 173 deletions
diff --git a/library/cpp/yt/string/string.h b/library/cpp/yt/string/string.h
index 92c7a2f472..ae6c99caab 100644
--- a/library/cpp/yt/string/string.h
+++ b/library/cpp/yt/string/string.h
@@ -1,9 +1,9 @@
-#pragma once
-
-#include "string_builder.h"
-
-#include <library/cpp/yt/exception/exception.h>
-
+#pragma once
+
+#include "string_builder.h"
+
+#include <library/cpp/yt/exception/exception.h>
+
#include <util/datetime/base.h>
#include <util/generic/string.h>
@@ -14,184 +14,184 @@
#include <set>
#include <map>
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-//! Formatters enable customizable way to turn an object into a string.
-//! This default implementation uses |FormatValue|.
-struct TDefaultFormatter
-{
- template <class T>
- void operator()(TStringBuilderBase* builder, const T& obj) const
- {
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+//! Formatters enable customizable way to turn an object into a string.
+//! This default implementation uses |FormatValue|.
+struct TDefaultFormatter
+{
+ template <class T>
+ void operator()(TStringBuilderBase* builder, const T& obj) const
+ {
FormatValue(builder, obj, TStringBuf("v"));
- }
-};
-
+ }
+};
+
static constexpr TStringBuf DefaultJoinToStringDelimiter = ", ";
static constexpr TStringBuf DefaultKeyValueDelimiter = ": ";
static constexpr TStringBuf DefaultRangeEllipsisFormat = "...";
-
+
// ASCII characters from 0x20 = ' ' to 0x7e = '~' are printable.
static constexpr char PrintableASCIILow = 0x20;
static constexpr char PrintableASCIIHigh = 0x7e;
static constexpr TStringBuf Int2Hex = "0123456789abcdef";
-//! Joins a range of items into a string intermixing them with the delimiter.
-/*!
- * \param builder String builder where the output goes.
- * \param begin Iterator pointing to the first item (inclusive).
- * \param end Iterator pointing to the last item (not inclusive).
- * \param formatter Formatter to apply to the items.
- * \param delimiter A delimiter to be inserted between items: ", " by default.
- * \return The resulting combined string.
- */
-template <class TIterator, class TFormatter>
-void JoinToString(
- TStringBuilderBase* builder,
- 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);
- }
-}
-
-template <class TIterator, class TFormatter>
+//! Joins a range of items into a string intermixing them with the delimiter.
+/*!
+ * \param builder String builder where the output goes.
+ * \param begin Iterator pointing to the first item (inclusive).
+ * \param end Iterator pointing to the last item (not inclusive).
+ * \param formatter Formatter to apply to the items.
+ * \param delimiter A delimiter to be inserted between items: ", " by default.
+ * \return The resulting combined string.
+ */
+template <class TIterator, class TFormatter>
+void JoinToString(
+ TStringBuilderBase* builder,
+ 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);
+ }
+}
+
+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();
-}
-
-//! A handy shortcut with default formatter.
-template <class TIterator>
+ const TIterator& begin,
+ const TIterator& end,
+ const TFormatter& formatter,
+ TStringBuf delimiter = DefaultJoinToStringDelimiter)
+{
+ TStringBuilder builder;
+ JoinToString(&builder, begin, end, formatter, delimiter);
+ return builder.Flush();
+}
+
+//! 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);
-}
-
-//! Joins a collection of given items into a string intermixing them with the delimiter.
-/*!
- * \param collection A collection containing the items to be joined.
- * \param formatter Formatter to apply to the items.
- * \param delimiter A delimiter to be inserted between items; ", " by default.
- */
-template <class TCollection, class TFormatter>
+ const TIterator& begin,
+ const TIterator& end,
+ TStringBuf delimiter = DefaultJoinToStringDelimiter)
+{
+ return JoinToString(begin, end, TDefaultFormatter(), delimiter);
+}
+
+//! Joins a collection of given items into a string intermixing them with the delimiter.
+/*!
+ * \param collection A collection containing the items to be joined.
+ * \param formatter Formatter to apply to the items.
+ * \param delimiter A delimiter to be inserted between items; ", " by default.
+ */
+template <class TCollection, class TFormatter>
TString JoinToString(
- const TCollection& collection,
- const TFormatter& formatter,
- TStringBuf delimiter = DefaultJoinToStringDelimiter)
-{
+ const TCollection& collection,
+ const TFormatter& formatter,
+ TStringBuf delimiter = DefaultJoinToStringDelimiter)
+{
using std::begin;
using std::end;
- return JoinToString(begin(collection), end(collection), formatter, delimiter);
-}
-
-//! A handy shortcut with the default formatter.
-template <class TCollection>
+ return JoinToString(begin(collection), end(collection), formatter, delimiter);
+}
+
+//! A handy shortcut with the default formatter.
+template <class TCollection>
TString JoinToString(
- const TCollection& collection,
- TStringBuf delimiter = DefaultJoinToStringDelimiter)
-{
- return JoinToString(collection, TDefaultFormatter(), delimiter);
-}
-
-//! 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;
-}
-
-//! Converts a range of items into strings.
-template <class TIter, class TFormatter>
+ const TCollection& collection,
+ TStringBuf delimiter = DefaultJoinToStringDelimiter)
+{
+ return JoinToString(collection, TDefaultFormatter(), delimiter);
+}
+
+//! 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;
+}
+
+//! Converts a range of items into strings.
+template <class TIter, class TFormatter>
std::vector<TString> ConvertToStrings(
- const TIter& begin,
- const TIter& end,
- const TFormatter& formatter,
- size_t maxSize = std::numeric_limits<size_t>::max())
-{
+ 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;
-}
-
-//! A handy shortcut with the default formatter.
-template <class TIter>
+ for (auto it = begin; it != end; ++it) {
+ TStringBuilder builder;
+ formatter(&builder, *it);
+ result.push_back(builder.Flush());
+ if (result.size() == maxSize) {
+ break;
+ }
+ }
+ return result;
+}
+
+//! 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);
-}
-
-//! Converts a given collection of items into strings.
-/*!
- * \param collection A collection containing the items to be converted.
- * \param formatter Formatter to apply to the items.
- * \param maxSize Size limit for the resulting vector.
- */
-template <class TCollection, class TFormatter>
+ const TIter& begin,
+ const TIter& end,
+ size_t maxSize = std::numeric_limits<size_t>::max())
+{
+ return ConvertToStrings(begin, end, TDefaultFormatter(), maxSize);
+}
+
+//! Converts a given collection of items into strings.
+/*!
+ * \param collection A collection containing the items to be converted.
+ * \param formatter Formatter to apply to the items.
+ * \param maxSize Size limit for the resulting vector.
+ */
+template <class TCollection, class TFormatter>
std::vector<TString> ConvertToStrings(
- const TCollection& collection,
- const TFormatter& formatter,
- size_t maxSize = std::numeric_limits<size_t>::max())
-{
+ 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);
-}
-
-//! A handy shortcut with default formatter.
-template <class TCollection>
+}
+
+//! 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);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-void UnderscoreCaseToCamelCase(TStringBuilderBase* builder, TStringBuf str);
-TString UnderscoreCaseToCamelCase(TStringBuf str);
-
-void CamelCaseToUnderscoreCase(TStringBuilderBase* builder, TStringBuf str);
-TString CamelCaseToUnderscoreCase(TStringBuf str);
+ const TCollection& collection,
+ size_t maxSize = std::numeric_limits<size_t>::max())
+{
+ return ConvertToStrings(collection, TDefaultFormatter(), maxSize);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void UnderscoreCaseToCamelCase(TStringBuilderBase* builder, TStringBuf str);
+TString UnderscoreCaseToCamelCase(TStringBuf str);
+
+void CamelCaseToUnderscoreCase(TStringBuilderBase* builder, TStringBuf str);
+TString CamelCaseToUnderscoreCase(TStringBuf str);
TString TrimLeadingWhitespaces(const TString& str);
TString Trim(const TString& str, const TString& whitespaces);
-
+
////////////////////////////////////////////////////////////////////////////////
//! Implemented for |[u]i(32|64)|.
@@ -200,22 +200,22 @@ char* WriteIntToBufferBackwards(char* ptr, T value);
////////////////////////////////////////////////////////////////////////////////
-struct TCaseInsensitiveStringHasher
-{
- size_t operator()(TStringBuf arg) const;
-};
-
-struct TCaseInsensitiveStringEqualityComparer
-{
- bool operator()(TStringBuf lhs, TStringBuf rhs) const;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-bool TryParseBool(TStringBuf value, bool* result);
-bool ParseBool(TStringBuf value);
+struct TCaseInsensitiveStringHasher
+{
+ size_t operator()(TStringBuf arg) const;
+};
+
+struct TCaseInsensitiveStringEqualityComparer
+{
+ bool operator()(TStringBuf lhs, TStringBuf rhs) const;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+bool TryParseBool(TStringBuf value, bool* result);
+bool ParseBool(TStringBuf value);
TStringBuf FormatBool(bool value);
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT
+} // namespace NYT