diff options
author | albert <albert@yandex-team.ru> | 2022-02-10 16:48:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:15 +0300 |
commit | a817f5de12611ec73085eba17f8ec7740a46bdb7 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /util/generic | |
parent | 9f25ef3232c288ca664ceee6c376cf64e4349a2e (diff) | |
download | ydb-a817f5de12611ec73085eba17f8ec7740a46bdb7.tar.gz |
Restoring authorship annotation for <albert@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/strbase.h | 42 | ||||
-rw-r--r-- | util/generic/strbuf.cpp | 6 | ||||
-rw-r--r-- | util/generic/strbuf.h | 216 | ||||
-rw-r--r-- | util/generic/strbuf_ut.cpp | 48 | ||||
-rw-r--r-- | util/generic/string.h | 90 | ||||
-rw-r--r-- | util/generic/typetraits.h | 2 | ||||
-rw-r--r-- | util/generic/yexception.h | 8 |
7 files changed, 206 insertions, 206 deletions
diff --git a/util/generic/strbase.h b/util/generic/strbase.h index e6bdf8e9b1..ab39fc7537 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -132,9 +132,9 @@ public: } inline size_t IterOff(const_iterator it) const noexcept { - return begin() <= it && end() > it ? size_t(it - begin()) : npos; - } - + return begin() <= it && end() > it ? size_t(it - begin()) : npos; + } + inline const_iterator begin() const noexcept { return Ptr(); } @@ -197,26 +197,26 @@ public: return !empty(); } -public: // style-guide compliant methods +public: // style-guide compliant methods constexpr const TCharType* Data() const noexcept { - return Ptr(); - } - + return Ptr(); + } + constexpr size_t Size() const noexcept { - return Len(); - } - + return Len(); + } + Y_PURE_FUNCTION constexpr bool Empty() const noexcept { - return 0 == Len(); - } - + return 0 == Len(); + } + private: static inline TStringView LegacySubString(const TStringView view, size_t p, size_t n) noexcept { p = Min(p, view.length()); return view.substr(p, n); } -public: +public: // ~~~ Comparison ~~~ : FAMILY0(int, compare) static int compare(const TSelf& s1, const TSelf& s2) noexcept { return s1.AsStringView().compare(s2.AsStringView()); @@ -469,8 +469,8 @@ public: return npos; } return AsStringView().rfind(c, pos - 1); - } - + } + inline size_t rfind(const TStringView str, size_t pos = npos) const { return AsStringView().rfind(str.data(), pos, str.size()); } @@ -549,7 +549,7 @@ public: } inline size_t copy(TCharType* pc, size_t n, size_t pos) const { - if (pos > Len()) { + if (pos > Len()) { throw std::out_of_range("TStringBase::copy"); } @@ -557,16 +557,16 @@ public: } inline size_t copy(TCharType* pc, size_t n) const noexcept { - return CopyImpl(pc, n, 0); + return CopyImpl(pc, n, 0); } inline size_t strcpy(TCharType* pc, size_t n) const noexcept { if (n) { - n = copy(pc, n - 1); - pc[n] = 0; + n = copy(pc, n - 1); + pc[n] = 0; } - return n; + return n; } inline TDerived copy() const Y_WARN_UNUSED_RESULT { diff --git a/util/generic/strbuf.cpp b/util/generic/strbuf.cpp index 2845c1e220..668602ca16 100644 --- a/util/generic/strbuf.cpp +++ b/util/generic/strbuf.cpp @@ -1,8 +1,8 @@ #include "strbuf.h" - -#include <util/stream/output.h> + +#include <util/stream/output.h> #include <ostream> - + std::ostream& operator<<(std::ostream& os, TStringBuf buf) { os.write(buf.data(), buf.size()); return os; diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index a794baa72d..70b9360d58 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -16,8 +16,8 @@ private: using TdSelf = TBasicStringBuf; using TBase = TStringBase<TdSelf, TCharType, TTraits>; using TStringView = std::basic_string_view<TCharType>; - -public: + +public: using char_type = TCharType; // TODO: DROP using traits_type = TTraits; @@ -99,8 +99,8 @@ public: constexpr inline TBasicStringBuf(const TCharType* data, size_t size) noexcept : TStringView(data, size) - { - } + { + } constexpr TBasicStringBuf(const TCharType* data) noexcept /* @@ -108,26 +108,26 @@ public: * while std::string_view (using std::char_traits) will abort in such case */ : TStringView(data, TBase::StrLen(data)) - { - } + { + } constexpr inline TBasicStringBuf(const TCharType* beg, const TCharType* end) noexcept : TStringView(beg, end - beg) { } - + template <typename D, typename T> inline TBasicStringBuf(const TStringBase<D, TCharType, T>& str) noexcept : TStringView(str.data(), str.size()) - { - } + { + } - template <typename T, typename A> + template <typename T, typename A> inline TBasicStringBuf(const std::basic_string<TCharType, T, A>& str) noexcept : TStringView(str) - { - } - + { + } + template <typename TCharTraits> constexpr TBasicStringBuf(std::basic_string_view<TCharType, TCharTraits> view) noexcept : TStringView(view) @@ -143,12 +143,12 @@ public: * * This means, that a class with default ctor can not be a constant member of another class with default ctor. */ - } + } inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos, size_t n) noexcept : TBasicStringBuf(src) { - Skip(pos).Trunc(n); + Skip(pos).Trunc(n); } inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos) noexcept @@ -162,14 +162,14 @@ public: return TBasicStringBuf(data() + pos, n); } -public: - void Clear() { - *this = TdSelf(); - } - +public: + void Clear() { + *this = TdSelf(); + } + constexpr bool IsInited() const noexcept { return data() != nullptr; - } + } public: /** @@ -184,8 +184,8 @@ public: * @returns Whether the split was actually performed. */ inline bool TrySplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept { - return TrySplitOn(TBase::find(delim), l, r); - } + return TrySplitOn(TBase::find(delim), l, r); + } /** * Tries to split string in two parts using given delimiter character. @@ -199,8 +199,8 @@ public: * @returns Whether the split was actually performed. */ inline bool TryRSplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept { - return TrySplitOn(TBase::rfind(delim), l, r); - } + return TrySplitOn(TBase::rfind(delim), l, r); + } /** * Tries to split string in two parts using given delimiter sequence. @@ -234,11 +234,11 @@ public: inline void Split(TCharType delim, TdSelf& l, TdSelf& r) const noexcept { SplitTemplate(delim, l, r); - } - + } + inline void RSplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept { RSplitTemplate(delim, l, r); - } + } inline void Split(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { SplitTemplate(delim, l, r); @@ -249,14 +249,14 @@ public: } private: - // splits on a delimiter at a given position; delimiter is excluded + // splits on a delimiter at a given position; delimiter is excluded void DoSplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len) const noexcept { Y_ASSERT(pos != TBase::npos); - // make a copy in case one of l/r is really *this + // make a copy in case one of l/r is really *this const TdSelf tok = SubStr(pos + len); - l = Head(pos); - r = tok; + l = Head(pos); + r = tok; } public: @@ -268,39 +268,39 @@ public: // s.TrySplitOn(s.find('z'), ...) is false, but s.TrySplitOn(100500, ...) is true. bool TrySplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { - if (TBase::npos == pos) - return false; + if (TBase::npos == pos) + return false; DoSplitOn(pos, l, r, len); - return true; - } - + return true; + } + void SplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { if (!TrySplitOn(pos, l, r, len)) { - l = *this; - r = TdSelf(); + l = *this; + r = TdSelf(); } - } + } bool TrySplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { return TrySplitOn(pos, l, r, 0); - } - + } + void SplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { SplitOn(pos, l, r, 0); - } - + } + /* // Not implemented intentionally, use TrySplitOn() instead void RSplitOn(size_t pos, TdSelf& l, TdSelf& r) const noexcept; void RSplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept; */ - + public: Y_PURE_FUNCTION inline TdSelf After(TCharType c) const noexcept { - TdSelf l, r; + TdSelf l, r; return TrySplit(c, l, r) ? r : *this; - } + } Y_PURE_FUNCTION inline TdSelf Before(TCharType c) const noexcept { TdSelf l, r; @@ -308,10 +308,10 @@ public: } Y_PURE_FUNCTION inline TdSelf RAfter(TCharType c) const noexcept { - TdSelf l, r; + TdSelf l, r; return TryRSplit(c, l, r) ? r : *this; - } - + } + Y_PURE_FUNCTION inline TdSelf RBefore(TCharType c) const noexcept { TdSelf l, r; return TryRSplit(c, l, r) ? l : *this; @@ -346,43 +346,43 @@ public: public: // returns tail, including pos - TdSelf SplitOffAt(size_t pos) { - const TdSelf tok = SubStr(pos); - Trunc(pos); - return tok; - } - + TdSelf SplitOffAt(size_t pos) { + const TdSelf tok = SubStr(pos); + Trunc(pos); + return tok; + } + // returns head, tail includes pos - TdSelf NextTokAt(size_t pos) { - const TdSelf tok = Head(pos); - Skip(pos); - return tok; - } - - TdSelf SplitOffOn(size_t pos) { - TdSelf tok; - SplitOn(pos, *this, tok); - return tok; - } - - TdSelf NextTokOn(size_t pos) { - TdSelf tok; - SplitOn(pos, tok, *this); - return tok; - } + TdSelf NextTokAt(size_t pos) { + const TdSelf tok = Head(pos); + Skip(pos); + return tok; + } + + TdSelf SplitOffOn(size_t pos) { + TdSelf tok; + SplitOn(pos, *this, tok); + return tok; + } + + TdSelf NextTokOn(size_t pos) { + TdSelf tok; + SplitOn(pos, tok, *this); + return tok; + } /* // See comment on RSplitOn() above TdSelf RSplitOffOn(size_t pos); TdSelf RNextTokOn(size_t pos); */ - + public: TdSelf SplitOff(TCharType delim) { - TdSelf tok; - Split(delim, *this, tok); - return tok; - } - + TdSelf tok; + Split(delim, *this, tok); + return tok; + } + TdSelf RSplitOff(TCharType delim) { TdSelf tok; RSplit(delim, tok, *this); @@ -419,8 +419,8 @@ public: TdSelf NextTok(TCharType delim) { return NextTokTemplate(delim); - } - + } + TdSelf RNextTok(TCharType delim) { return RNextTokTemplate(delim); } @@ -433,29 +433,29 @@ public: return RNextTokTemplate(delim); } -public: // string subsequences +public: // string subsequences /// Cut last @c shift characters (or less if length is less than @c shift) inline TdSelf& Chop(size_t shift) noexcept { this->remove_suffix(std::min(shift, size())); - return *this; - } + return *this; + } /// Cut first @c shift characters (or less if length is less than @c shift) inline TdSelf& Skip(size_t shift) noexcept { this->remove_prefix(std::min(shift, size())); - return *this; - } + return *this; + } /// Sets the start pointer to a position relative to the end inline TdSelf& RSeek(size_t tailSize) noexcept { if (size() > tailSize) { //WARN: removing TStringView:: will lead to an infinite recursion *this = TStringView::substr(size() - tailSize, tailSize); - } - - return *this; - } - + } + + return *this; + } + // coverity[exn_spec_violation] inline TdSelf& Trunc(size_t targetSize) noexcept { // Coverity false positive issue @@ -463,30 +463,30 @@ public: // string subsequences // fun_call_w_exception: Called function TStringView::substr throws an exception of type "std::out_of_range". // Suppress this issue because we pass argument pos=0 and string_view can't throw std::out_of_range. *this = TStringView::substr(0, targetSize); //WARN: removing TStringView:: will lead to an infinite recursion - return *this; - } + return *this; + } Y_PURE_FUNCTION inline TdSelf SubStr(size_t beg) const noexcept { - return TdSelf(*this).Skip(beg); - } + return TdSelf(*this).Skip(beg); + } Y_PURE_FUNCTION inline TdSelf SubStr(size_t beg, size_t len) const noexcept { - return SubStr(beg).Trunc(len); - } - + return SubStr(beg).Trunc(len); + } + Y_PURE_FUNCTION inline TdSelf Head(size_t pos) const noexcept { - return TdSelf(*this).Trunc(pos); - } - + return TdSelf(*this).Trunc(pos); + } + Y_PURE_FUNCTION inline TdSelf Tail(size_t pos) const noexcept { - return SubStr(pos); - } - + return SubStr(pos); + } + Y_PURE_FUNCTION inline TdSelf Last(size_t len) const noexcept { - return TdSelf(*this).RSeek(len); - } - -private: + return TdSelf(*this).RSeek(len); + } + +private: template <typename TDelimiterType> TdSelf NextTokTemplate(TDelimiterType delim) { TdSelf tok; diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index e155946ea2..69cde785af 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -10,10 +10,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_EQUAL(*str.data(), 'q'); UNIT_ASSERT_EQUAL(str.size(), 6); - + TStringBuf str1("qwe\0rty"sv); - TStringBuf str2(str1.data()); - UNIT_ASSERT_VALUES_UNEQUAL(str1, str2); + TStringBuf str2(str1.data()); + UNIT_ASSERT_VALUES_UNEQUAL(str1, str2); UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7); UNIT_ASSERT_VALUES_EQUAL(str2.size(), 3); @@ -139,33 +139,33 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT(TStringBuf().empty()); UNIT_ASSERT(!TStringBuf("q").empty()); } - + Y_UNIT_TEST(TestShift) { - TStringBuf qw("qwerty"); - TStringBuf str; - - str = qw; - str.Chop(10); + TStringBuf qw("qwerty"); + TStringBuf str; + + str = qw; + str.Chop(10); UNIT_ASSERT(str.empty()); - - str = qw; + + str = qw; UNIT_ASSERT_EQUAL(str.SubStr(2), TStringBuf("erty")); UNIT_ASSERT_EQUAL(str.Skip(3), qw.SubStr(3)); - str.Chop(1); + str.Chop(1); UNIT_ASSERT_EQUAL(str, TStringBuf("rt")); - } - + } + Y_UNIT_TEST(TestSplit) { - TStringBuf qw("qwerty"); - TStringBuf lt, rt; - - rt = qw; - lt = rt.NextTok('r'); + TStringBuf qw("qwerty"); + TStringBuf lt, rt; + + rt = qw; + lt = rt.NextTok('r'); UNIT_ASSERT_EQUAL(lt, TStringBuf("qwe")); UNIT_ASSERT_EQUAL(rt, TStringBuf("ty")); - - lt = qw; - rt = lt.SplitOff('r'); + + lt = qw; + rt = lt.SplitOff('r'); UNIT_ASSERT_EQUAL(lt, TStringBuf("qwe")); UNIT_ASSERT_EQUAL(rt, TStringBuf("ty")); @@ -174,8 +174,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { TStringBuf ty = rt.NextTok('r'); // no 'r' in "ty" UNIT_ASSERT_EQUAL(rt.size(), 0); UNIT_ASSERT_EQUAL(ty, TStringBuf("ty")); - } - + } + Y_UNIT_TEST(TestNextTok) { TStringBuf buf("12q45q"); TStringBuf tok; diff --git a/util/generic/string.h b/util/generic/string.h index 9829891afe..8cd8aa6917 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -248,7 +248,7 @@ public: return StdStr(); #endif - } + } inline const_reference operator[](size_t pos) const noexcept { Y_ASSERT(pos <= length()); @@ -362,8 +362,8 @@ public: #else return 1 == RefCount(); #endif - } - + } + // ~~~ Size and capacity ~~~ TBasicString& resize(size_t n, TCharType c = ' ') { // remove or append MutRef().resize(n, c); @@ -500,9 +500,9 @@ public: explicit TBasicString(const TBasicStringBuf<TCharType, TTraits> s) : TBasicString(s.data(), s.size()) - { - } - + { + } + template <typename Traits> explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s) : TBasicString(s.data(), s.size()) @@ -648,12 +648,12 @@ public: TBasicString& AssignNoAlias(const TBasicStringBuf<TCharType, TTraits> s) { return AssignNoAlias(s.data(), s.size()); - } - + } + TBasicString& AssignNoAlias(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) { - return AssignNoAlias(s.SubString(spos, sn)); - } - + return AssignNoAlias(s.SubString(spos, sn)); + } + /** * WARN: * Certain invocations of this method will result in link-time error. @@ -675,9 +675,9 @@ public: } TBasicString& operator=(const TBasicString& s) { - return assign(s); - } - + return assign(s); + } + TBasicString& operator=(TBasicString&& s) noexcept { swap(s); return *this; @@ -691,18 +691,18 @@ public: } TBasicString& operator=(const TBasicStringBuf<TCharType, TTraits> s) { - return assign(s); - } - + return assign(s); + } + TBasicString& operator=(std::initializer_list<TCharType> il) { return assign(il.begin(), il.end()); } TBasicString& operator=(const TCharType* s) { - return assign(s); - } + return assign(s); + } TBasicString& operator=(std::nullptr_t) = delete; - + TBasicString& operator=(TExplicitType<TCharType> ch) { return assign(ch); } @@ -771,20 +771,20 @@ public: TBasicString& AppendNoAlias(const TBasicStringBuf<TCharType, TTraits> s) { return AppendNoAlias(s.data(), s.size()); - } - + } + TBasicString& AppendNoAlias(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) { - return AppendNoAlias(s.SubString(spos, sn)); - } - + return AppendNoAlias(s.SubString(spos, sn)); + } + TBasicString& append(const TBasicStringBuf<TCharType, TTraits> s) { return append(s.data(), s.size()); - } - + } + TBasicString& append(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) { - return append(s.SubString(spos, sn)); - } - + return append(s.SubString(spos, sn)); + } + TBasicString& append(const TCharType* pc, size_t pos, size_t n, size_t pc_len = TBase::npos) { return append(pc + pos, Min(n, pc_len - pos)); } @@ -882,8 +882,8 @@ public: #endif s1 += s2; return std::move(s1); - } - + } + friend TBasicString operator+(TBasicString&& s1, const TBasicStringBuf<TCharType, TTraits> s2) Y_WARN_UNUSED_RESULT { s1 += s2; return std::move(s1); @@ -968,8 +968,8 @@ public: MutRef().insert(size_t(0), n, c); return *this; - } - + } + TBasicString& prepend(TCharType c) { MutRef().insert(size_t(0), 1, c); @@ -977,9 +977,9 @@ public: } TBasicString& prepend(const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { - return insert(0, s, spos, sn); - } - + return insert(0, s, spos, sn); + } + // ~~~ Insertion ~~~ : FAMILY1(TBasicString&, insert, size_t pos); TBasicString& insert(size_t pos, const TBasicString& s) { MutRef().insert(pos, s.ConstRef()); @@ -1033,8 +1033,8 @@ public: MutRef().insert(pos, s, spos, sn); return *this; - } - + } + // ~~~ Removing ~~~ TBasicString& remove(size_t pos, size_t n) Y_NOEXCEPT { if (pos < length()) { @@ -1097,14 +1097,14 @@ public: MutRef().replace(pos, n, s, len); return *this; - } - + } + TBasicString& replace(size_t pos, size_t n, const TCharType* s, size_t spos, size_t sn) Y_NOEXCEPT { MutRef().replace(pos, n, s + spos, sn - spos); return *this; - } - + } + TBasicString& replace(size_t pos, size_t n1, size_t n2, TCharType c) Y_NOEXCEPT { MutRef().replace(pos, n1, n2, c); @@ -1113,7 +1113,7 @@ public: TBasicString& replace(size_t pos, size_t n, const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) Y_NOEXCEPT { MutRef().replace(pos, n, s, spos, sn); - + return *this; } @@ -1131,7 +1131,7 @@ public: */ TBasicString Quote() const { extern TBasicString EscapeC(const TBasicString&); - + return TBasicString() + '"' + EscapeC(*this) + '"'; } diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h index 5ca96f4df1..d165bd1a06 100644 --- a/util/generic/typetraits.h +++ b/util/generic/typetraits.h @@ -161,7 +161,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {}; template <class T> \ struct THas##name \ : TBaseHas##name<T, std::is_class<T>::value || std::is_union<T>::value> {} - + #define Y_HAS_MEMBER_IMPL_1(name) Y_HAS_MEMBER_IMPL_2(name, name) /* @def Y_HAS_MEMBER diff --git a/util/generic/yexception.h b/util/generic/yexception.h index e73b517df5..b0c604e8c4 100644 --- a/util/generic/yexception.h +++ b/util/generic/yexception.h @@ -57,7 +57,7 @@ namespace NPrivateException { } TStringBuf AsStrBuf() const; - + private: void ZeroTerminate() noexcept; @@ -83,9 +83,9 @@ class yexception: public NPrivateException::yexception { }; Y_DECLARE_OUT_SPEC(inline, yexception, stream, value) { - stream << value.AsStrBuf(); -} - + stream << value.AsStrBuf(); +} + class TSystemError: public yexception { public: TSystemError(int status) |