diff options
author | luckybug <luckybug@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:27 +0300 |
commit | b455da0978714a8b8dd026fc564b36dea5948f79 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util | |
parent | a6d369648d0e4e2d446acfd469aced762d3c0492 (diff) | |
download | ydb-b455da0978714a8b8dd026fc564b36dea5948f79.tar.gz |
Restoring authorship annotation for <luckybug@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/string/join.h | 54 | ||||
-rw-r--r-- | util/string/join_ut.cpp | 150 |
2 files changed, 102 insertions, 102 deletions
diff --git a/util/string/join.h b/util/string/join.h index 595674b58e..b166fad1f3 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -197,22 +197,22 @@ JoinSeq(TCharType delim, const TContainer& data) { return JoinSeq(delimBuf, data); } -/** \brief Functor for streaming iterative objects from TIterB e to TIterE b, separated with delim. - * Difference from JoinSeq, JoinRange, Join is the lack of TString object - all depends on operator<< for the type and - * realization of IOutputStream - */ +/** \brief Functor for streaming iterative objects from TIterB e to TIterE b, separated with delim. + * Difference from JoinSeq, JoinRange, Join is the lack of TString object - all depends on operator<< for the type and + * realization of IOutputStream + */ template <class TIterB, class TIterE> struct TRangeJoiner { - friend constexpr IOutputStream& operator<<(IOutputStream& stream, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { + friend constexpr IOutputStream& operator<<(IOutputStream& stream, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { if (rangeJoiner.b != rangeJoiner.e) { - stream << *rangeJoiner.b; - + stream << *rangeJoiner.b; + for (auto it = std::next(rangeJoiner.b); it != rangeJoiner.e; ++it) - stream << rangeJoiner.delim << *it; - } - return stream; - } - + stream << rangeJoiner.delim << *it; + } + return stream; + } + constexpr TRangeJoiner(TStringBuf delim, TIterB&& b, TIterE&& e) : delim(delim) , b(std::forward<TIterB>(b)) @@ -220,27 +220,27 @@ struct TRangeJoiner { { } -private: - const TStringBuf delim; - const TIterB b; - const TIterE e; -}; - +private: + const TStringBuf delim; + const TIterB b; + const TIterE e; +}; + template <class TIterB, class TIterE = TIterB> constexpr auto MakeRangeJoiner(TStringBuf delim, TIterB&& b, TIterE&& e) { - return TRangeJoiner<TIterB, TIterE>(delim, std::forward<TIterB>(b), std::forward<TIterE>(e)); -} - + return TRangeJoiner<TIterB, TIterE>(delim, std::forward<TIterB>(b), std::forward<TIterE>(e)); +} + template <class TContainer> constexpr auto MakeRangeJoiner(TStringBuf delim, const TContainer& data) { - return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); -} - + return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); +} + template <class TVal> constexpr auto MakeRangeJoiner(TStringBuf delim, const std::initializer_list<TVal>& data) { - return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); -} - + return MakeRangeJoiner(delim, std::cbegin(data), std::cend(data)); +} + /* We force (std::initializer_list<TStringBuf>) input type for (TString) and (const char*) types because: * # When (std::initializer_list<TString>) is used, TString objects are copied into the initializer_list object. * Storing TStringBufs instead is faster, even with COW-enabled strings. diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp index 60a44d08ad..3ed2b2459c 100644 --- a/util/string/join_ut.cpp +++ b/util/string/join_ut.cpp @@ -51,98 +51,98 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(JoinRange(" ", vchar.begin(), vchar.end()), result); UNIT_ASSERT_EQUAL(JoinRange(" ", vbuf.begin(), vbuf.end()), result); UNIT_ASSERT_EQUAL(JoinRange(" ", vstring.begin(), vstring.end()), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", v, v + 3); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vchar.begin(), vchar.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vbuf.begin(), vbuf.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vstring.begin(), vstring.end()); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", v, v + 3); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vchar.begin(), vchar.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vbuf.begin(), vbuf.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vstring.begin(), vstring.end()); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // vectors UNIT_ASSERT_EQUAL(JoinSeq(" ", vchar), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", vbuf), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", vstring), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vchar); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vbuf); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", vstring); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vchar); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vbuf); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", vstring); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // initializer lists with type deduction UNIT_ASSERT_EQUAL(JoinSeq(" ", {v[0], v[1], v[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vchar[0], vchar[1], vchar[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vbuf[0], vbuf[1], vbuf[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", {vstring[0], vstring[1], vstring[2]}), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {v[0], v[1], v[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vchar[0], vchar[1], vchar[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vbuf[0], vbuf[1], vbuf[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", {vstring[0], vstring[1], vstring[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {v[0], v[1], v[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vchar[0], vchar[1], vchar[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vbuf[0], vbuf[1], vbuf[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", {vstring[0], vstring[1], vstring[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // initializer lists with explicit types UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}), result); UNIT_ASSERT_EQUAL(JoinSeq(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}), result); - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } - { - TStringStream stream; - stream << MakeRangeJoiner(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}); - UNIT_ASSERT_EQUAL(stream.Str(), result); - } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{v[0], v[1], v[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<const char*>{vchar[0], vchar[1], vchar[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<TStringBuf>{vbuf[0], vbuf[1], vbuf[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } + { + TStringStream stream; + stream << MakeRangeJoiner(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}); + UNIT_ASSERT_EQUAL(stream.Str(), result); + } // c-style array UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), result); |