diff options
author | kaa <kaa@yandex-team.ru> | 2022-02-10 16:49:28 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:28 +0300 |
commit | f49cf886c755668578b0214ab9eae8ecdc1395a8 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util | |
parent | b99e8e1b6e3468f81111414c917adc2d334b2c3c (diff) | |
download | ydb-f49cf886c755668578b0214ab9eae8ecdc1395a8.tar.gz |
Restoring authorship annotation for <kaa@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/string/join.h | 28 | ||||
-rw-r--r-- | util/string/join_ut.cpp | 24 | ||||
-rw-r--r-- | util/string/split.h | 30 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 10 |
4 files changed, 46 insertions, 46 deletions
diff --git a/util/string/join.h b/util/string/join.h index cb271d278c..b166fad1f3 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -1,10 +1,10 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> -#include <util/generic/typetraits.h> +#include <util/generic/typetraits.h> #include <util/string/cast.h> #include "cast.h" - + /* * Default implementation of AppendToString uses a temporary TString object which is inefficient. You can overload it * for your type to speed up string joins. If you already have an Out() or operator<<() implementation you can simply @@ -30,18 +30,18 @@ inline std::enable_if_t<std::is_arithmetic<std::remove_cv_t<T>>::value, void> AppendToString(TBasicString<TCharType>& dst, const T& t) { char buf[512]; dst.append(buf, ToString<std::remove_cv_t<T>>(t, buf, sizeof(buf))); -} - +} + template <typename TCharType> inline void AppendToString(TBasicString<TCharType>& dst, const TCharType* t) { dst.append(t); -} - +} + template <typename TCharType> inline void AppendToString(TBasicString<TCharType>& dst, TBasicStringBuf<TCharType> t) { dst.append(t); -} - +} + namespace NPrivate { template <typename T> inline size_t GetLength(const T&) { @@ -73,8 +73,8 @@ namespace NPrivate { size_t GetAppendLength(const TStringBuf delim, const TFirst& f, const TRest&... r) { return delim.length() + ::NPrivate::GetLength(f) + ::NPrivate::GetAppendLength(delim, r...); } -} - +} + template <typename TCharType> inline void AppendJoinNoReserve(TBasicString<TCharType>&, TBasicStringBuf<TCharType>) { } @@ -130,7 +130,7 @@ namespace NPrivate { } return out; - } + } } // namespace NPrivate @@ -172,7 +172,7 @@ inline TBasicString<TCharType> JoinSeq(std::basic_string_view<TCharType> delim, using std::begin; using std::end; return JoinRange(delim, begin(data), end(data)); -} +} template <typename TCharType, typename TContainer> inline TBasicString<TCharType> JoinSeq(const TCharType* delim, const TContainer& data) { diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp index 3604e75a4e..3ed2b2459c 100644 --- a/util/string/join_ut.cpp +++ b/util/string/join_ut.cpp @@ -1,10 +1,10 @@ -#include "join.h" - +#include "join.h" + #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/vector.h> - +#include <util/generic/vector.h> + #include <util/stream/output.h> - + struct TCustomData { TVector<int> Ints; }; @@ -16,7 +16,7 @@ TString ToString(const TCustomData& d) { Y_UNIT_TEST_SUITE(JoinStringTest) { Y_UNIT_TEST(ScalarItems) { UNIT_ASSERT_EQUAL(Join(',', 10, 11.1, "foobar"), "10,11.1,foobar"); - UNIT_ASSERT_EQUAL(Join(", ", 10, 11.1, "foobar"), "10, 11.1, foobar"); + UNIT_ASSERT_EQUAL(Join(", ", 10, 11.1, "foobar"), "10, 11.1, foobar"); UNIT_ASSERT_EQUAL(Join(", ", 10, 11.1, TString("foobar")), "10, 11.1, foobar"); UNIT_ASSERT_EQUAL(Join('#', 0, "a", "foobar", -1.4, TStringBuf("aaa")), "0#a#foobar#-1.4#aaa"); @@ -24,19 +24,19 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(Join("", "a", "b", "c"), "abc"); UNIT_ASSERT_EQUAL(Join("", "a", "b", "", "c"), "abc"); UNIT_ASSERT_EQUAL(Join(" ", "a", "b", "", "c"), "a b c"); - } + } Y_UNIT_TEST(IntContainerItems) { - int v[] = {1, 2, 3}; + int v[] = {1, 2, 3}; TVector<int> vv(v, v + 3); - UNIT_ASSERT_EQUAL(JoinSeq(" ", vv), "1 2 3"); - UNIT_ASSERT_EQUAL(JoinSeq(" ", vv), JoinRange(" ", vv.begin(), vv.end())); + UNIT_ASSERT_EQUAL(JoinSeq(" ", vv), "1 2 3"); + UNIT_ASSERT_EQUAL(JoinSeq(" ", vv), JoinRange(" ", vv.begin(), vv.end())); UNIT_ASSERT_EQUAL(JoinRange(" ", v, v + 2), "1 2"); UNIT_ASSERT_EQUAL(JoinSeq(" ", {}), ""); UNIT_ASSERT_EQUAL(JoinSeq(" ", {42}), "42"); UNIT_ASSERT_EQUAL(JoinSeq(" ", {1, 2, 3}), "1 2 3"); UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), "1 2 3"); - } + } Y_UNIT_TEST(StrContainerItems) { // try various overloads and template type arguments @@ -160,4 +160,4 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(Join('a', 'a', 'a'), "97a97"); UNIT_ASSERT_EQUAL(Join("a", "a", "a"), "aaa"); } -} +} diff --git a/util/string/split.h b/util/string/split.h index 29fafd7890..bc46d9e64c 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -10,7 +10,7 @@ #include <util/generic/store_policy.h> #include <util/generic/strbuf.h> #include <util/generic/string.h> -#include <util/generic/typetraits.h> +#include <util/generic/typetraits.h> #include <util/generic/vector.h> #include <util/generic/ylimits.h> #include <util/system/compat.h> @@ -260,28 +260,28 @@ struct TSetDelimiter: private TFindFirstOf<const Char> { } }; -namespace NSplitTargetHasPushBack { +namespace NSplitTargetHasPushBack { Y_HAS_MEMBER(push_back, PushBack); -} - +} + template <class T, class = void> struct TConsumerBackInserter; - + template <class T> struct TConsumerBackInserter<T, std::enable_if_t<NSplitTargetHasPushBack::TClassHasPushBack<T>::value>> { static void DoInsert(T* C, const typename T::value_type& i) { - C->push_back(i); - } -}; - -template <class T> + C->push_back(i); + } +}; + +template <class T> struct TConsumerBackInserter<T, std::enable_if_t<!NSplitTargetHasPushBack::TClassHasPushBack<T>::value>> { static void DoInsert(T* C, const typename T::value_type& i) { - C->insert(C->end(), i); - } -}; - -template <class T> + C->insert(C->end(), i); + } +}; + +template <class T> struct TContainerConsumer { inline TContainerConsumer(T* c) noexcept : C(c) diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 02b00b95a9..43e59f2d75 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -25,7 +25,7 @@ static inline void OldSplit(char* pszBuf, T* pRes) { template <class T1, class T2> inline void Cmp(const T1& t1, const T2& t2) { try { - UNIT_ASSERT_EQUAL(t1.size(), t2.size()); + UNIT_ASSERT_EQUAL(t1.size(), t2.size()); } catch (...) { Print(t1); Cerr << "---------------" << Endl; @@ -39,9 +39,9 @@ inline void Cmp(const T1& t1, const T2& t2) { for (; i != t1.end() && j != t2.end(); ++i, ++j) { try { - UNIT_ASSERT_EQUAL(*i, *j); + UNIT_ASSERT_EQUAL(*i, *j); } catch (...) { - Cerr << "(" << *i << ")->(" << *j << ")" << Endl; + Cerr << "(" << *i << ")->(" << *j << ")" << Endl; throw; } @@ -50,8 +50,8 @@ inline void Cmp(const T1& t1, const T2& t2) { template <class T> inline void Print(const T& t) { - for (typename T::const_iterator i = t.begin(); i != t.end(); ++i) { - Cerr << *i << Endl; + for (typename T::const_iterator i = t.begin(); i != t.end(); ++i) { + Cerr << *i << Endl; } } |