diff options
author | antonovvk <antonovvk@yandex-team.ru> | 2022-02-10 16:47:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:52 +0300 |
commit | 37de222addabbef336dcaaea5f7c7645a629fc6d (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /util | |
parent | 37a63debdc21e372d99e1808cdd31aecf75018c3 (diff) | |
download | ydb-37de222addabbef336dcaaea5f7c7645a629fc6d.tar.gz |
Restoring authorship annotation for <antonovvk@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/draft/holder_vector.h | 14 | ||||
-rw-r--r-- | util/generic/buffer.h | 6 | ||||
-rw-r--r-- | util/str_stl.h | 34 | ||||
-rw-r--r-- | util/stream/format.h | 26 | ||||
-rw-r--r-- | util/string/cast.h | 18 | ||||
-rw-r--r-- | util/string/split.h | 74 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 176 | ||||
-rw-r--r-- | util/string/util.h | 22 |
8 files changed, 185 insertions, 185 deletions
diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h index 40f958cdd3..1c62055bd9 100644 --- a/util/draft/holder_vector.h +++ b/util/draft/holder_vector.h @@ -58,13 +58,13 @@ public: (*this)[i] = t.Release(); } - void PopBack() { - if (size()) { - D::Destroy(back()); - TBase::pop_back(); - } - } - + void PopBack() { + if (size()) { + D::Destroy(back()); + TBase::pop_back(); + } + } + T* Release(size_t i) { T* t = (*this)[i]; (*this)[i] = nullptr; diff --git a/util/generic/buffer.h b/util/generic/buffer.h index 8523dfd160..9576467404 100644 --- a/util/generic/buffer.h +++ b/util/generic/buffer.h @@ -70,11 +70,11 @@ public: inline char* Pos() noexcept { return Data_ + Pos_; } - + inline const char* Pos() const noexcept { return Data_ + Pos_; } - + /// Used space in bytes (do not mix with Capacity!) inline size_t Size() const noexcept { return Pos_; @@ -138,7 +138,7 @@ public: inline void Advance(size_t len) { Resize(Pos_ + len); } - + inline void Reserve(size_t len) { if (len > Len_) { DoReserve(len); diff --git a/util/str_stl.h b/util/str_stl.h index a7a026b880..f1e137181d 100644 --- a/util/str_stl.h +++ b/util/str_stl.h @@ -210,29 +210,29 @@ struct TEqualTo<std::pair<TFirst, TSecond>> { template <class T> struct TCIEqualTo { -}; - -template <> -struct TCIEqualTo<const char*> { +}; + +template <> +struct TCIEqualTo<const char*> { inline bool operator()(const char* a, const char* b) const { - return stricmp(a, b) == 0; - } -}; - -template <> -struct TCIEqualTo<TStringBuf> { + return stricmp(a, b) == 0; + } +}; + +template <> +struct TCIEqualTo<TStringBuf> { inline bool operator()(const TStringBuf a, const TStringBuf b) const { return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0; - } -}; - -template <> + } +}; + +template <> struct TCIEqualTo<TString> { inline bool operator()(const TString& a, const TString& b) const { return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0; - } -}; - + } +}; + template <class T> struct TLess: public std::less<T> { }; diff --git a/util/stream/format.h b/util/stream/format.h index 8589e84d76..b033208a1b 100644 --- a/util/stream/format.h +++ b/util/stream/format.h @@ -12,10 +12,10 @@ enum ENumberFormatFlag { HF_FULL = 0x01, /**< Output number with leading zeros. */ HF_ADDX = 0x02, /**< Output '0x' or '0b' before hex/bin digits. */ -}; +}; Y_DECLARE_FLAGS(ENumberFormat, ENumberFormatFlag) Y_DECLARE_OPERATORS_FOR_FLAGS(ENumberFormat) - + enum ESizeFormat { SF_QUANTITY, /**< Base 1000, usual suffixes. 1100 gets turned into "1.1K". */ SF_BYTES, /**< Base 1024, byte suffix. 1100 gets turned into "1.07KiB". */ @@ -89,20 +89,20 @@ namespace NFormatPrivate { } return o; } - + template <typename T, size_t Base> struct TBaseNumber { T Value; ENumberFormat Flags; - + template <typename OtherT> inline TBaseNumber(OtherT value, ENumberFormat flags) - : Value(value) - , Flags(flags) - { - } - }; - + : Value(value) + , Flags(flags) + { + } + }; + template <typename T, size_t Base> using TUnsignedBaseNumber = TBaseNumber<std::make_unsigned_t<std::remove_cv_t<T>>, Base>; @@ -255,11 +255,11 @@ static constexpr ::NFormatPrivate::TRightPad<const T*> RightPad(const T (&value) * @param value Value to output. * @param flags Output flags. */ -template <typename T> +template <typename T> static constexpr ::NFormatPrivate::TUnsignedBaseNumber<T, 16> Hex(const T& value, const ENumberFormat flags = HF_FULL | HF_ADDX) noexcept { return {value, flags}; -} - +} + /** * Output manipulator similar to `std::setbase(16)`. * diff --git a/util/string/cast.h b/util/string/cast.h index eee2ba1813..90e925c194 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -3,7 +3,7 @@ #include <util/system/defaults.h> #include <util/stream/str.h> #include <util/generic/string.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/typetraits.h> #include <util/generic/yexception.h> @@ -151,11 +151,11 @@ inline T FromString(const TChar* data) { } template <class T> -inline T FromString(const TStringBuf& s) { +inline T FromString(const TStringBuf& s) { return ::FromString<T>(s.data(), s.size()); -} - -template <class T> +} + +template <class T> inline T FromString(const TString& s) { return ::FromString<T>(s.data(), s.size()); } @@ -171,11 +171,11 @@ inline TString FromString<TString>(const TString& s) { } template <class T> -inline T FromString(const TWtringBuf& s) { +inline T FromString(const TWtringBuf& s) { return ::FromString<T, typename TWtringBuf::char_type>(s.data(), s.size()); -} - -template <class T> +} + +template <class T> inline T FromString(const TUtf16String& s) { return ::FromString<T, wchar16>(s.data(), s.size()); } diff --git a/util/string/split.h b/util/string/split.h index 17149d1785..bc46d9e64c 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -198,29 +198,29 @@ private: template <class Char> struct TFindFirstOf { inline TFindFirstOf(Char* set) - : Set(set) - { - } - + : Set(set) + { + } + inline Char* FindFirstOf(Char* b, Char* e) const noexcept { Char* ret = b; - for (; ret != e; ++ret) { + for (; ret != e; ++ret) { if (NStringSplitPrivate::Find(Set, *ret)) - break; - } - return 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(); - } - + } + Char* Set; -}; - -template <> +}; + +template <> struct TFindFirstOf<const char>: public TCompactStrSpn { inline TFindFirstOf(const char* set, const char* e) : TCompactStrSpn(set, e) @@ -229,37 +229,37 @@ struct TFindFirstOf<const char>: public TCompactStrSpn { inline TFindFirstOf(const char* set) : TCompactStrSpn(set) - { - } + { + } }; - + template <class Char> struct TSetDelimiter: private TFindFirstOf<const Char> { using TFindFirstOf<const Char>::TFindFirstOf; - + inline Char* Find(Char*& b, Char* e) const noexcept { Char* ret = const_cast<Char*>(this->FindFirstOf(b, e)); - if (ret != e) { - b = ret + 1; - return ret; - } - - return (b = e); - } - + if (ret != e) { + b = ret + 1; + return ret; + } + + return (b = e); + } + inline Char* Find(Char*& b) const noexcept { Char* ret = const_cast<Char*>(this->FindFirstOf(b)); - - if (*ret) { - b = ret + 1; - return ret; - } - - return (b = ret); - } -}; - + + if (*ret) { + b = ret + 1; + return ret; + } + + return (b = ret); + } +}; + namespace NSplitTargetHasPushBack { Y_HAS_MEMBER(push_back, PushBack); } diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index ee67fd8a29..43e59f2d75 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -22,113 +22,113 @@ static inline void OldSplit(char* pszBuf, T* pRes) { } } -template <class T1, class T2> -inline void Cmp(const T1& t1, const T2& t2) { - try { +template <class T1, class T2> +inline void Cmp(const T1& t1, const T2& t2) { + try { UNIT_ASSERT_EQUAL(t1.size(), t2.size()); - } catch (...) { - Print(t1); - Cerr << "---------------" << Endl; - Print(t2); - - throw; - } - + } catch (...) { + Print(t1); + Cerr << "---------------" << Endl; + Print(t2); + + throw; + } + auto i = t1.begin(); auto j = t2.begin(); for (; i != t1.end() && j != t2.end(); ++i, ++j) { - try { + try { UNIT_ASSERT_EQUAL(*i, *j); - } catch (...) { + } catch (...) { Cerr << "(" << *i << ")->(" << *j << ")" << Endl; - - throw; - } - } + + throw; + } + } } -template <class T> -inline void Print(const T& t) { +template <class T> +inline void Print(const T& t) { for (typename T::const_iterator i = t.begin(); i != t.end(); ++i) { Cerr << *i << Endl; - } + } } template <template <typename> class TConsumer, typename TResult, typename I, typename TDelimiter> -void TestDelimiterOnString(TResult& good, I* str, const TDelimiter& delim) { - TResult test; +void TestDelimiterOnString(TResult& good, I* str, const TDelimiter& delim) { + TResult test; TConsumer<TResult> consumer(&test); - SplitString(str, delim, consumer); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); + SplitString(str, delim, consumer); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); } template <template <typename> class TConsumer, typename TResult, typename I, typename TDelimiter> -void TestDelimiterOnRange(TResult& good, I* b, I* e, const TDelimiter& delim) { - TResult test; +void TestDelimiterOnRange(TResult& good, I* b, I* e, const TDelimiter& delim) { + TResult test; TConsumer<TResult> consumer(&test); - SplitString(b, e, delim, consumer); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); -} - -template <typename TConsumer, typename TResult, typename I> -void TestConsumerOnString(TResult& good, I* str, I* d) { - TResult test; - TContainerConsumer<TResult> consumer(&test); - TConsumer tested(&consumer); - TCharDelimiter<const I> delim(*d); - SplitString(str, delim, tested); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); -} - -template <typename TConsumer, typename TResult, typename I> -void TestConsumerOnRange(TResult& good, I* b, I* e, I* d) { - TResult test; - TContainerConsumer<TResult> consumer(&test); - TConsumer tested(&consumer); - TCharDelimiter<const I> delim(*d); - SplitString(b, e, delim, tested); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); -} + SplitString(b, e, delim, consumer); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); +} + +template <typename TConsumer, typename TResult, typename I> +void TestConsumerOnString(TResult& good, I* str, I* d) { + TResult test; + TContainerConsumer<TResult> consumer(&test); + TConsumer tested(&consumer); + TCharDelimiter<const I> delim(*d); + SplitString(str, delim, tested); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); +} + +template <typename TConsumer, typename TResult, typename I> +void TestConsumerOnRange(TResult& good, I* b, I* e, I* d) { + TResult test; + TContainerConsumer<TResult> consumer(&test); + TConsumer tested(&consumer); + TCharDelimiter<const I> delim(*d); + SplitString(b, e, delim, tested); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); +} using TStrokaConsumer = TContainerConsumer<TVector<TString>>; void TestLimitingConsumerOnString(TVector<TString>& good, const char* str, const char* d, size_t n, const char* last) { TVector<TString> test; - TStrokaConsumer consumer(&test); - TLimitingConsumer<TStrokaConsumer, const char> limits(n, &consumer); - TCharDelimiter<const char> delim(*d); - SplitString(str, delim, limits); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); + TStrokaConsumer consumer(&test); + TLimitingConsumer<TStrokaConsumer, const char> limits(n, &consumer); + TCharDelimiter<const char> delim(*d); + SplitString(str, delim, limits); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); UNIT_ASSERT_EQUAL(TString(limits.Last), TString(last)); // Quite unobvious behaviour. Why the last token is not added to slave consumer? -} +} void TestLimitingConsumerOnRange(TVector<TString>& good, const char* b, const char* e, const char* d, size_t n, const char* last) { TVector<TString> test; - TStrokaConsumer consumer(&test); - TLimitingConsumer<TStrokaConsumer, const char> limits(n, &consumer); - TCharDelimiter<const char> delim(*d); - SplitString(b, e, delim, limits); - Cmp(good, test); - UNIT_ASSERT_EQUAL(good, test); + TStrokaConsumer consumer(&test); + TLimitingConsumer<TStrokaConsumer, const char> limits(n, &consumer); + TCharDelimiter<const char> delim(*d); + SplitString(b, e, delim, limits); + Cmp(good, test); + UNIT_ASSERT_EQUAL(good, test); UNIT_ASSERT_EQUAL(TString(limits.Last), TString(last)); -} +} Y_UNIT_TEST_SUITE(SplitStringTest) { Y_UNIT_TEST(TestCharSingleDelimiter) { TString data("qw ab qwabcab"); TString canonic[] = {"qw", "ab", "", "qwabcab"}; TVector<TString> good(canonic, canonic + 4); - TCharDelimiter<const char> delim(' '); + TCharDelimiter<const char> delim(' '); TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim); - } + } Y_UNIT_TEST(TestWideSingleDelimiter) { TUtf16String data(u"qw ab qwabcab"); @@ -138,7 +138,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim); - } + } Y_UNIT_TEST(TestConvertToIntCharSingleDelimiter) { TString data("42 4242 -12345 0"); @@ -157,7 +157,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestConsumerOnString<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), " "); TestConsumerOnRange<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), data.end(), " "); - } + } Y_UNIT_TEST(TestCharKeepDelimiters) { TString data("qw ab qwabcab "); @@ -166,7 +166,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestConsumerOnString<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), " "); TestConsumerOnRange<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), data.end(), " "); - } + } Y_UNIT_TEST(TestCharLimit) { TString data("qw ab qwabcab "); @@ -175,17 +175,17 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestLimitingConsumerOnString(good, data.data(), " ", 3, " qwabcab "); TestLimitingConsumerOnRange(good, data.data(), data.end(), " ", 3, " qwabcab "); - } + } Y_UNIT_TEST(TestCharStringDelimiter) { TString data("qw ab qwababcab"); TString canonic[] = {"qw ", " qw", "", "c", ""}; TVector<TString> good(canonic, canonic + 5); - TStringDelimiter<const char> delim("ab"); + TStringDelimiter<const char> delim("ab"); TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim); - } + } Y_UNIT_TEST(TestWideStringDelimiter) { TUtf16String data(u"qw ab qwababcab"); @@ -196,17 +196,17 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim); - } + } Y_UNIT_TEST(TestCharSetDelimiter) { TString data("qw ab qwababccab"); TString canonic[] = {"q", " ab q", "abab", "", "ab"}; TVector<TString> good(canonic, canonic + 5); - TSetDelimiter<const char> delim("wc"); + TSetDelimiter<const char> delim("wc"); TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim); - } + } Y_UNIT_TEST(TestWideSetDelimiter) { TUtf16String data(u"qw ab qwababccab"); @@ -216,7 +216,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TSetDelimiter<const wchar16> delim(wideDelim.data()); TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim); - } + } Y_UNIT_TEST(TestWideSetDelimiterRange) { TUtf16String data(u"qw ab qwababccab"); @@ -224,19 +224,19 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TVector<TUtf16String> good(1); TUtf16String wideDelim(u"wc"); TSetDelimiter<const wchar16> delim(wideDelim.data()); - + TVector<TUtf16String> test; TContainerConsumer<TVector<TUtf16String>> consumer(&test); SplitString(data.data(), data.data(), delim, consumer); // Empty string is still inserted into consumer - Cmp(good, test); - - good.assign(canonic, canonic + 4); + Cmp(good, test); + + good.assign(canonic, canonic + 4); good.push_back(TUtf16String()); - test.clear(); + test.clear(); SplitString(data.data(), data.end() - 2, delim, consumer); - Cmp(good, test); - } - + Cmp(good, test); + } + Y_UNIT_TEST(TestSplit) { TString data("qw ab qwababcba"); TString canonic[] = {"qw ", " qw", "c"}; @@ -301,7 +301,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1)); UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception); } -} +} template <typename I, typename C> void TestStringSplitterCount(I* str, C delim, size_t good) { diff --git a/util/string/util.h b/util/string/util.h index 4901e8ba22..0d77a5042b 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -77,12 +77,12 @@ public: return s; } - const char* brk(const char* s, const char* e) const { - while (s < e && c_chars_table[(ui8)*s]) + const char* brk(const char* s, const char* e) const { + while (s < e && c_chars_table[(ui8)*s]) ++s; - return s; - } - + return s; + } + /// Return first character not in table, like strpbrk() for inverted table. /// That is, skip all characters in table const char* cbrk(const char* s) const { @@ -91,12 +91,12 @@ public: return s; } - const char* cbrk(const char* s, const char* e) const { - while (s < e && chars_table[(ui8)*s]) + const char* cbrk(const char* s, const char* e) const { + while (s < e && chars_table[(ui8)*s]) ++s; - return s; - } - + return s; + } + /// Offset of the first character not in table, like strspn(). size_t spn(const char* s) const { return cbrk(s) - s; @@ -172,7 +172,7 @@ public: void Do(char* s, size_t l) const { for (size_t i = 0; i < l && s[i]; i++) s[i] = ConvertChar(s[i]); - } + } void Do(TString& str) const; private: |