diff options
author | eeight <eeight@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
commit | 475c0a46f28166e83fd263badc7546377cddcabe (patch) | |
tree | 39c5a49b8aaad78fe390b6f1f2886bdbda40f3e7 /util/string | |
parent | a6e0145a095c7bb3770d6e07aee301de5c73f96e (diff) | |
download | ydb-475c0a46f28166e83fd263badc7546377cddcabe.tar.gz |
Restoring authorship annotation for <eeight@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/ascii.h | 8 | ||||
-rw-r--r-- | util/string/cast.h | 24 | ||||
-rw-r--r-- | util/string/escape.cpp | 18 | ||||
-rw-r--r-- | util/string/escape_ut.cpp | 10 | ||||
-rw-r--r-- | util/string/fuzzing/collapse/main.cpp | 2 | ||||
-rw-r--r-- | util/string/join.h | 2 | ||||
-rw-r--r-- | util/string/reverse.cpp | 66 | ||||
-rw-r--r-- | util/string/reverse.h | 32 | ||||
-rw-r--r-- | util/string/split.h | 104 | ||||
-rw-r--r-- | util/string/strip.cpp | 10 | ||||
-rw-r--r-- | util/string/strip.h | 10 | ||||
-rw-r--r-- | util/string/strip_ut.cpp | 6 | ||||
-rw-r--r-- | util/string/vector.h | 2 |
13 files changed, 147 insertions, 147 deletions
diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..68c3a963f9 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -31,12 +31,12 @@ namespace NPrivate { using type = T; }; -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING template <class String> struct TDereference<TBasicCharRef<String>> { using type = typename String::value_type; }; -#endif +#endif template <class T> using TDereferenced = typename TDereference<T>::type; @@ -52,12 +52,12 @@ namespace NPrivate { return c >= static_cast<T>(0) && c <= static_cast<T>(127); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING template <class String> bool RangeOk(const TBasicCharRef<String>& c) { return RangeOk(static_cast<typename String::value_type>(c)); } -#endif +#endif } constexpr bool IsAscii(const int c) noexcept { diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..d4f6a876d8 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -343,15 +343,15 @@ template <class TInt, int base, class TStringType> inline TInt IntFromString(const TStringType& str) { return IntFromString<TInt, base>(str.data(), str.size()); } - -static inline TString ToString(const TStringBuf str) { - return TString(str); -} - -static inline TUtf16String ToWtring(const TWtringBuf wtr) { - return TUtf16String(wtr); -} - -static inline TUtf32String ToUtf32String(const TUtf32StringBuf wtr) { - return TUtf32String(wtr); -} + +static inline TString ToString(const TStringBuf str) { + return TString(str); +} + +static inline TUtf16String ToWtring(const TWtringBuf wtr) { + return TUtf16String(wtr); +} + +static inline TUtf32String ToUtf32String(const TUtf32StringBuf wtr) { + return TUtf32String(wtr); +} diff --git a/util/string/escape.cpp b/util/string/escape.cpp index cd09a7dbd0..ea35b5fb15 100644 --- a/util/string/escape.cpp +++ b/util/string/escape.cpp @@ -283,12 +283,12 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) { } case 'U': - if (CountHex<8>(p + 1, pe) != 8) { + if (CountHex<8>(p + 1, pe) != 8) { res.append(*p); - } else { + } else { AppendUnicode(res, IntFromString<ui32, 16>(p + 1, 8)); - p += 8; - } + p += 8; + } break; case 'x': if (ui32 v = CountHex<2>(p + 1, pe)) { @@ -319,8 +319,8 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) { ++p; } else { - const auto r = std::basic_string_view<TChar>(p, pe - p).find('\\'); - const auto n = r != std::string::npos ? p + r : pe; + const auto r = std::basic_string_view<TChar>(p, pe - p).find('\\'); + const auto n = r != std::string::npos ? p + r : pe; res.append(p, n); p = n; @@ -338,17 +338,17 @@ TBasicString<TChar>& UnescapeCImpl(const TChar* p, size_t sz, TBasicString<TChar template <class TChar> TChar* UnescapeC(const TChar* str, size_t len, TChar* buf) { struct TUnboundedString { - void append(TChar ch) noexcept { + void append(TChar ch) noexcept { *P++ = ch; } - void append(const TChar* b, const TChar* e) noexcept { + void append(const TChar* b, const TChar* e) noexcept { while (b != e) { append(*b++); } } - void AppendNoAlias(const TChar* s, size_t l) noexcept { + void AppendNoAlias(const TChar* s, size_t l) noexcept { append(s, s + l); } diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp index cd38ecffd3..c79c2833a8 100644 --- a/util/string/escape_ut.cpp +++ b/util/string/escape_ut.cpp @@ -140,9 +140,9 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) { UNIT_ASSERT_VALUES_EQUAL(x.Source, TStringBuf(buf, end)); } } - - Y_UNIT_TEST(TestCapitalUEscapes) { - UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\U00000020"), " "); - UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\Uxxx"), "Uxxx"); - } + + Y_UNIT_TEST(TestCapitalUEscapes) { + UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\U00000020"), " "); + UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\Uxxx"), "Uxxx"); + } } diff --git a/util/string/fuzzing/collapse/main.cpp b/util/string/fuzzing/collapse/main.cpp index e7b09f0f55..e26ec54f79 100644 --- a/util/string/fuzzing/collapse/main.cpp +++ b/util/string/fuzzing/collapse/main.cpp @@ -6,7 +6,7 @@ extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { Collapse(w); TString s((const char*)data, size); - CollapseInPlace(s); + CollapseInPlace(s); return 0; // Non-zero return values are reserved for future use. } diff --git a/util/string/join.h b/util/string/join.h index b166fad1f3..b848bea1d3 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -2,7 +2,7 @@ #include <util/generic/string.h> #include <util/generic/typetraits.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include "cast.h" /* diff --git a/util/string/reverse.cpp b/util/string/reverse.cpp index 167cd11f49..3d67e95b04 100644 --- a/util/string/reverse.cpp +++ b/util/string/reverse.cpp @@ -1,33 +1,33 @@ -#include "reverse.h" - -#include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/charset/wide_specific.h> - -#include <algorithm> - -void ReverseInPlace(TString& string) { - auto* begin = string.begin(); - std::reverse(begin, begin + string.size()); -} - -void ReverseInPlace(TUtf16String& string) { - auto* begin = string.begin(); - const auto len = string.size(); - auto* end = begin + string.size(); - - TVector<wchar16> buffer(len); - wchar16* rbegin = buffer.data() + len; - for (wchar16* p = begin; p < end;) { - const size_t symbolSize = W16SymbolSize(p, end); - rbegin -= symbolSize; - std::copy(p, p + symbolSize, rbegin); - p += symbolSize; - } - std::copy(buffer.begin(), buffer.end(), begin); -} - -void ReverseInPlace(TUtf32String& string) { - auto* begin = string.begin(); - std::reverse(begin, begin + string.size()); -} +#include "reverse.h" + +#include <util/generic/string.h> +#include <util/generic/vector.h> +#include <util/charset/wide_specific.h> + +#include <algorithm> + +void ReverseInPlace(TString& string) { + auto* begin = string.begin(); + std::reverse(begin, begin + string.size()); +} + +void ReverseInPlace(TUtf16String& string) { + auto* begin = string.begin(); + const auto len = string.size(); + auto* end = begin + string.size(); + + TVector<wchar16> buffer(len); + wchar16* rbegin = buffer.data() + len; + for (wchar16* p = begin; p < end;) { + const size_t symbolSize = W16SymbolSize(p, end); + rbegin -= symbolSize; + std::copy(p, p + symbolSize, rbegin); + p += symbolSize; + } + std::copy(buffer.begin(), buffer.end(), begin); +} + +void ReverseInPlace(TUtf32String& string) { + auto* begin = string.begin(); + std::reverse(begin, begin + string.size()); +} diff --git a/util/string/reverse.h b/util/string/reverse.h index 80f8b00887..6adf17f08b 100644 --- a/util/string/reverse.h +++ b/util/string/reverse.h @@ -1,16 +1,16 @@ -#pragma once - -#include <util/generic/fwd.h> - -void ReverseInPlace(TString& string); - -/** NB. UTF-16 is variable-length encoding because of the surrogate pairs. - * This function takes this into account and treats a surrogate pair as a single symbol. - * Ex. if [C D] is a surrogate pair, - * A B [C D] E - * will become - * E [C D] B A - */ -void ReverseInPlace(TUtf16String& string); - -void ReverseInPlace(TUtf32String& string); +#pragma once + +#include <util/generic/fwd.h> + +void ReverseInPlace(TString& string); + +/** NB. UTF-16 is variable-length encoding because of the surrogate pairs. + * This function takes this into account and treats a surrogate pair as a single symbol. + * Ex. if [C D] is a surrogate pair, + * A B [C D] E + * will become + * E [C D] B A + */ +void ReverseInPlace(TUtf16String& string); + +void ReverseInPlace(TUtf32String& string); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..951b3cc7d4 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -21,7 +21,7 @@ // NOTE: Check StringSplitter below to get more convenient split string interface. -namespace NStringSplitPrivate { +namespace NStringSplitPrivate { template <class T, class I, class = void> struct TIsConsumer: std::false_type {}; @@ -36,21 +36,21 @@ namespace NStringSplitPrivate { template <class T, class I> constexpr bool TIsConsumerV = TIsConsumer<T, I>::value; - template <class T> - T* Find(T* str, std::common_type_t<T> ch) { - for (; *str; ++str) { - if (*str == ch) { - return str; - } - } - - return nullptr; - } - + template <class T> + T* Find(T* str, std::common_type_t<T> ch) { + for (; *str; ++str) { + if (*str == ch) { + return str; + } + } + + return nullptr; + } + } template <class I, class TDelim, class TConsumer> -std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> +std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> SplitString(I b, I e, const TDelim& d, TConsumer&& c) { I l, i; @@ -61,7 +61,7 @@ SplitString(I b, I e, const TDelim& d, TConsumer&& c) { } template <class I, class TDelim, class TConsumer> -std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> +std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> SplitString(I b, const TDelim& d, TConsumer&& c) { I l, i; @@ -73,7 +73,7 @@ SplitString(I b, const TDelim& d, TConsumer&& c) { template <class I1, class I2> static inline I1* FastStrChr(I1* str, I2 f) noexcept { - I1* ret = NStringSplitPrivate::Find(str, f); + I1* ret = NStringSplitPrivate::Find(str, f); if (!ret) { ret = str + std::char_traits<I1>::length(str); @@ -84,21 +84,21 @@ static inline I1* FastStrChr(I1* str, I2 f) noexcept { template <class I> static inline I* FastStrStr(I* str, I* f, size_t l) noexcept { - std::basic_string_view<I> strView(str); - const auto ret = strView.find(*f); - - if (ret != std::string::npos) { - std::basic_string_view<I> fView(f, l); - strView = strView.substr(ret); - for (; strView.size() >= l; strView = strView.substr(1)) { - if (strView.substr(0, l) == fView) { - break; - } - } - - return strView.size() >= l ? strView.data() : strView.data() + strView.size(); - } else { - return strView.data() + strView.size(); + std::basic_string_view<I> strView(str); + const auto ret = strView.find(*f); + + if (ret != std::string::npos) { + std::basic_string_view<I> fView(f, l); + strView = strView.substr(ret); + for (; strView.size() >= l; strView = strView.substr(1)) { + if (strView.substr(0, l) == fView) { + break; + } + } + + return strView.size() >= l ? strView.data() : strView.data() + strView.size(); + } else { + return strView.data() + strView.size(); } } @@ -117,12 +117,12 @@ struct TStringDelimiter { } inline Char* Find(Char*& b, Char* e) const noexcept { - const auto ret = std::basic_string_view<Char>(b, e - b).find(Delim, 0, Len); + const auto ret = std::basic_string_view<Char>(b, e - b).find(Delim, 0, Len); - if (ret != std::string::npos) { - const auto result = b + ret; - b = result + Len; - return result; + if (ret != std::string::npos) { + const auto result = b + ret; + b = result + Len; + return result; } return (b = e); @@ -131,7 +131,7 @@ struct TStringDelimiter { inline Char* Find(Char*& b) const noexcept { Char* ret = FastStrStr(b, Delim, Len); - b = *ret ? ret + Len : ret; + b = *ret ? ret + Len : ret; return ret; } @@ -148,12 +148,12 @@ struct TCharDelimiter { } inline Char* Find(Char*& b, Char* e) const noexcept { - const auto ret = std::basic_string_view<Char>(b, e - b).find(Ch); + const auto ret = std::basic_string_view<Char>(b, e - b).find(Ch); - if (ret != std::string::npos) { - const auto result = b + ret; - b = result + 1; - return result; + if (ret != std::string::npos) { + const auto result = b + ret; + b = result + 1; + return result; } return (b = e); @@ -205,16 +205,16 @@ struct TFindFirstOf { inline Char* FindFirstOf(Char* b, Char* e) const noexcept { Char* ret = b; for (; ret != e; ++ret) { - if (NStringSplitPrivate::Find(Set, *ret)) + if (NStringSplitPrivate::Find(Set, *ret)) break; } return ret; } inline Char* FindFirstOf(Char* b) const noexcept { - const std::basic_string_view<Char> bView(b); - const auto ret = bView.find_first_of(Set); - return ret != std::string::npos ? b + ret : b + bView.size(); + const std::basic_string_view<Char> bView(b); + const auto ret = bView.find_first_of(Set); + return ret != std::string::npos ? b + ret : b + bView.size(); } Char* Set; @@ -489,7 +489,7 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { * \endcode */ -namespace NStringSplitPrivate { +namespace NStringSplitPrivate { Y_HAS_MEMBER(push_back, PushBack); Y_HAS_MEMBER(insert, Insert); Y_HAS_MEMBER(data, Data); @@ -1042,30 +1042,30 @@ namespace NStringSplitPrivate { template <class Iterator> auto StringSplitter(Iterator begin, Iterator end) { - return ::NStringSplitPrivate::MakeStringSplitter(TIteratorRange<Iterator>(begin, end)); + return ::NStringSplitPrivate::MakeStringSplitter(TIteratorRange<Iterator>(begin, end)); } template <class Char> auto StringSplitter(const Char* begin, const Char* end) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, end)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, end)); } template <class Char> auto StringSplitter(const Char* begin, size_t len) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, len)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, len)); } template <class Char> auto StringSplitter(const Char* str) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(str)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(str)); } template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0> auto StringSplitter(String& s) { - return ::NStringSplitPrivate::MakeStringSplitter(::NStringSplitPrivate::TStringBufOf<String>(s.data(), s.size())); + return ::NStringSplitPrivate::MakeStringSplitter(::NStringSplitPrivate::TStringBufOf<String>(s.data(), s.size())); } template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0> auto StringSplitter(String&& s) { - return ::NStringSplitPrivate::MakeStringSplitter(std::move(s)); + return ::NStringSplitPrivate::MakeStringSplitter(std::move(s)); } diff --git a/util/string/strip.cpp b/util/string/strip.cpp index c921571cf0..0b942ca06f 100644 --- a/util/string/strip.cpp +++ b/util/string/strip.cpp @@ -1,23 +1,23 @@ #include "strip.h" #include "ascii.h" -#include <util/string/reverse.h> - +#include <util/string/reverse.h> + bool Collapse(const TString& from, TString& to, size_t maxLen) { return CollapseImpl<TString, bool (*)(unsigned char)>(from, to, maxLen, IsAsciiSpace); } void CollapseText(const TString& from, TString& to, size_t maxLen) { Collapse(from, to, maxLen); - StripInPlace(to); + StripInPlace(to); if (to.size() >= maxLen) { to.remove(maxLen - 5); // " ..." - ReverseInPlace(to); + ReverseInPlace(to); size_t pos = to.find_first_of(" .,;"); if (pos != TString::npos && pos < 32) { to.remove(0, pos + 1); } - ReverseInPlace(to); + ReverseInPlace(to); to.append(" ..."); } } diff --git a/util/string/strip.h b/util/string/strip.h index d5ef6da96d..81b97add83 100644 --- a/util/string/strip.h +++ b/util/string/strip.h @@ -183,7 +183,7 @@ static inline bool Strip(const TString& from, TString& to) { } /// Removes leading and trailing spaces from the string. -inline TString& StripInPlace(TString& s) { +inline TString& StripInPlace(TString& s) { Strip(s, s); return s; } @@ -233,14 +233,14 @@ bool CollapseImpl(const TStringType& from, TStringType& to, size_t maxLen, const bool Collapse(const TString& from, TString& to, size_t maxLen = 0); /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) -inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { +inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { Collapse(s, s, maxLen); return s; } - + /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) -inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT; -inline TString Collapse(const TString& s, size_t maxLen) { +inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT; +inline TString Collapse(const TString& s, size_t maxLen) { TString ret; Collapse(s, ret, maxLen); return ret; diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index d1029d1498..2118e583d8 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -116,12 +116,12 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { s = TString(" a b c "); TString s2 = s; - CollapseInPlace(s2); + CollapseInPlace(s2); UNIT_ASSERT(s == s2); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == s2.c_str()); // Collapse() does not change the string at all -#endif +#endif } Y_UNIT_TEST(TestCollapseText) { diff --git a/util/string/vector.h b/util/string/vector.h index e36c348bbe..0c9f4d39ac 100644 --- a/util/string/vector.h +++ b/util/string/vector.h @@ -7,7 +7,7 @@ #include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/generic/vector.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/yassert.h> #define KEEP_EMPTY_TOKENS 0x01 |