aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authormowgli <mowgli@yandex-team.ru>2022-02-10 16:49:25 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:25 +0300
commit56c39b3cf908e7202b1f7551a1653681e8015607 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util/string
parent89afbbe4ca0e02e386dd4df08f7945f190dc1b84 (diff)
downloadydb-56c39b3cf908e7202b1f7551a1653681e8015607.tar.gz
Restoring authorship annotation for <mowgli@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/join.h42
-rw-r--r--util/string/join_ut.cpp44
-rw-r--r--util/string/strip.h90
-rw-r--r--util/string/strip_ut.cpp14
-rw-r--r--util/string/vector.cpp4
5 files changed, 97 insertions, 97 deletions
diff --git a/util/string/join.h b/util/string/join.h
index 02f2d95544..b166fad1f3 100644
--- a/util/string/join.h
+++ b/util/string/join.h
@@ -22,9 +22,9 @@
template <typename TCharType, typename T>
inline std::enable_if_t<!std::is_arithmetic<std::remove_cv_t<T>>::value, void>
AppendToString(TBasicString<TCharType>& dst, const T& t) {
- dst.AppendNoAlias(ToString(t));
+ dst.AppendNoAlias(ToString(t));
}
-
+
template <typename TCharType, typename T>
inline std::enable_if_t<std::is_arithmetic<std::remove_cv_t<T>>::value, void>
AppendToString(TBasicString<TCharType>& dst, const T& t) {
@@ -34,12 +34,12 @@ AppendToString(TBasicString<TCharType>& dst, const T& t) {
template <typename TCharType>
inline void AppendToString(TBasicString<TCharType>& dst, const TCharType* t) {
- dst.append(t);
+ dst.append(t);
}
template <typename TCharType>
inline void AppendToString(TBasicString<TCharType>& dst, TBasicStringBuf<TCharType> t) {
- dst.append(t);
+ dst.append(t);
}
namespace NPrivate {
@@ -81,11 +81,11 @@ inline void AppendJoinNoReserve(TBasicString<TCharType>&, TBasicStringBuf<TCharT
template <typename TCharType, typename TFirst, typename... TRest>
inline void AppendJoinNoReserve(TBasicString<TCharType>& dst, TBasicStringBuf<TCharType> delim, const TFirst& f, const TRest&... r) {
- AppendToString(dst, delim);
- AppendToString(dst, f);
+ AppendToString(dst, delim);
+ AppendToString(dst, f);
AppendJoinNoReserve(dst, delim, r...);
-}
-
+}
+
template <typename... TValues>
inline void AppendJoin(TString& dst, const TStringBuf delim, const TValues&... values) {
const size_t appendLength = ::NPrivate::GetAppendLength(delim, values...);
@@ -95,21 +95,21 @@ inline void AppendJoin(TString& dst, const TStringBuf delim, const TValues&... v
AppendJoinNoReserve(dst, delim, values...);
}
-template <typename TFirst, typename... TRest>
+template <typename TFirst, typename... TRest>
inline TString Join(const TStringBuf delim, const TFirst& f, const TRest&... r) {
TString ret = ToString(f);
- AppendJoin(ret, delim, r...);
- return ret;
-}
-
-// Note that char delimeter @cdelim will be printed as single char string,
-// but any char value @v will be printed as corresponding numeric code.
-// For example, Join('a', 'a', 'a') will print "97a97" (see unit-test).
-template <typename... TValues>
+ AppendJoin(ret, delim, r...);
+ return ret;
+}
+
+// Note that char delimeter @cdelim will be printed as single char string,
+// but any char value @v will be printed as corresponding numeric code.
+// For example, Join('a', 'a', 'a') will print "97a97" (see unit-test).
+template <typename... TValues>
inline TString Join(char cdelim, const TValues&... v) {
- return Join(TStringBuf(&cdelim, 1), v...);
-}
-
+ return Join(TStringBuf(&cdelim, 1), v...);
+}
+
namespace NPrivate {
template <typename TCharType, typename TIter>
inline TBasicString<TCharType> JoinRange(TBasicStringBuf<TCharType> delim, const TIter beg, const TIter end) {
@@ -131,7 +131,7 @@ namespace NPrivate {
return out;
}
-
+
} // namespace NPrivate
template <typename TIter>
diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp
index 8bd7545b2a..3ed2b2459c 100644
--- a/util/string/join_ut.cpp
+++ b/util/string/join_ut.cpp
@@ -5,27 +5,27 @@
#include <util/stream/output.h>
-struct TCustomData {
+struct TCustomData {
TVector<int> Ints;
-};
-
+};
+
TString ToString(const TCustomData& d) {
- return JoinSeq("__", d.Ints);
-}
-
+ return JoinSeq("__", d.Ints);
+}
+
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");
- UNIT_ASSERT_EQUAL(Join("", "", ""), "");
- 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");
+ UNIT_ASSERT_EQUAL(Join("", "", ""), "");
+ 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};
TVector<int> vv(v, v + 3);
@@ -37,7 +37,7 @@ Y_UNIT_TEST_SUITE(JoinStringTest) {
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
static const char* const result = "1 22 333";
@@ -151,13 +151,13 @@ Y_UNIT_TEST_SUITE(JoinStringTest) {
Y_UNIT_TEST(CustomToString) {
TCustomData d1{{1, 2, 3, 4, 5}};
TCustomData d2{{0, -1, -2}};
- UNIT_ASSERT_EQUAL(Join(" ", d1, d2), "1__2__3__4__5 0__-1__-2");
- }
-
+ UNIT_ASSERT_EQUAL(Join(" ", d1, d2), "1__2__3__4__5 0__-1__-2");
+ }
+
Y_UNIT_TEST(JoinChars) {
- // Note that char delimeter is printed as single char string,
- // but joined char values are printed as their numeric codes! O_o
- UNIT_ASSERT_EQUAL(Join('a', 'a', 'a'), "97a97");
- UNIT_ASSERT_EQUAL(Join("a", "a", "a"), "aaa");
- }
+ // Note that char delimeter is printed as single char string,
+ // but joined char values are printed as their numeric codes! O_o
+ UNIT_ASSERT_EQUAL(Join('a', 'a', 'a'), "97a97");
+ UNIT_ASSERT_EQUAL(Join("a", "a", "a"), "aaa");
+ }
}
diff --git a/util/string/strip.h b/util/string/strip.h
index b2097bf4e3..d5ef6da96d 100644
--- a/util/string/strip.h
+++ b/util/string/strip.h
@@ -62,53 +62,53 @@ inline void StripRangeEnd(const It& b, It& e) noexcept {
StripRangeEnd(b, e, IsAsciiSpaceAdapter(b));
}
-template <bool stripBeg, bool stripEnd>
-struct TStripImpl {
+template <bool stripBeg, bool stripEnd>
+struct TStripImpl {
template <class It, class TStripCriterion>
static inline bool StripRange(It& b, It& e, TStripCriterion&& criterion) noexcept {
- const size_t oldLen = e - b;
-
- if (stripBeg) {
+ const size_t oldLen = e - b;
+
+ if (stripBeg) {
StripRangeBegin(b, e, criterion);
- }
-
- if (stripEnd) {
+ }
+
+ if (stripEnd) {
StripRangeEnd(b, e, criterion);
- }
-
- const size_t newLen = e - b;
- return newLen != oldLen;
- }
-
+ }
+
+ const size_t newLen = e - b;
+ return newLen != oldLen;
+ }
+
template <class T, class TStripCriterion>
static inline bool StripString(const T& from, T& to, TStripCriterion&& criterion) {
auto b = from.begin();
auto e = from.end();
-
+
if (StripRange(b, e, criterion)) {
to = T(b, e - b);
-
- return true;
- }
-
- to = from;
-
- return false;
- }
-
+
+ return true;
+ }
+
+ to = from;
+
+ return false;
+ }
+
template <class T, class TStripCriterion>
static inline T StripString(const T& from, TStripCriterion&& criterion) {
- T ret;
+ T ret;
StripString(from, ret, criterion);
- return ret;
- }
-
- template <class T>
- static inline T StripString(const T& from) {
- return StripString(from, IsAsciiSpaceAdapter(from.begin()));
- }
-};
-
+ return ret;
+ }
+
+ template <class T>
+ static inline T StripString(const T& from) {
+ return StripString(from, IsAsciiSpaceAdapter(from.begin()));
+ }
+};
+
template <class It, class TStripCriterion>
inline bool StripRange(It& b, It& e, TStripCriterion&& criterion) noexcept {
return TStripImpl<true, true>::StripRange(b, e, criterion);
@@ -154,19 +154,19 @@ static inline T StripString(const T& from, TStripCriterion&& criterion) {
template <class T>
static inline T StripString(const T& from) {
- return TStripImpl<true, true>::StripString(from);
+ return TStripImpl<true, true>::StripString(from);
+}
+
+template <class T>
+static inline T StripStringLeft(const T& from) {
+ return TStripImpl<true, false>::StripString(from);
+}
+
+template <class T>
+static inline T StripStringRight(const T& from) {
+ return TStripImpl<false, true>::StripString(from);
}
-template <class T>
-static inline T StripStringLeft(const T& from) {
- return TStripImpl<true, false>::StripString(from);
-}
-
-template <class T>
-static inline T StripStringRight(const T& from) {
- return TStripImpl<false, true>::StripString(from);
-}
-
template <class T, class TStripCriterion>
static inline T StripStringLeft(const T& from, TStripCriterion&& criterion) {
return TStripImpl<true, false>::StripString(from, criterion);
diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp
index 5f3ec0a032..d1029d1498 100644
--- a/util/string/strip_ut.cpp
+++ b/util/string/strip_ut.cpp
@@ -8,9 +8,9 @@ Y_UNIT_TEST_SUITE(TStripStringTest) {
Y_UNIT_TEST(TestStrip) {
struct TTest {
const char* Str;
- const char* StripLeftRes;
- const char* StripRightRes;
- const char* StripRes;
+ const char* StripLeftRes;
+ const char* StripRightRes;
+ const char* StripRes;
};
static const TTest tests[] = {
{" 012 ", "012 ", " 012", "012"},
@@ -28,15 +28,15 @@ Y_UNIT_TEST_SUITE(TStripStringTest) {
for (const auto& test : tests) {
TString inputStr(test.Str);
-
+
TString s;
- Strip(inputStr, s);
+ Strip(inputStr, s);
UNIT_ASSERT_EQUAL(s, test.StripRes);
-
+
UNIT_ASSERT_EQUAL(StripString(inputStr), test.StripRes);
UNIT_ASSERT_EQUAL(StripStringLeft(inputStr), test.StripLeftRes);
UNIT_ASSERT_EQUAL(StripStringRight(inputStr), test.StripRightRes);
-
+
TStringBuf inputStrBuf(test.Str);
UNIT_ASSERT_EQUAL(StripString(inputStrBuf), test.StripRes);
UNIT_ASSERT_EQUAL(StripStringLeft(inputStrBuf), test.StripLeftRes);
diff --git a/util/string/vector.cpp b/util/string/vector.cpp
index e57691a7d4..9ba401f0a2 100644
--- a/util/string/vector.cpp
+++ b/util/string/vector.cpp
@@ -81,8 +81,8 @@ void ::NPrivate::SplitStringImpl(TVector<TUtf16String>* res, const wchar16* ptr,
TUtf16String JoinStrings(const TVector<TUtf16String>& v, const TWtringBuf delim) {
return JoinStrings(v.begin(), v.end(), delim);
-}
-
+}
+
TUtf16String JoinStrings(const TVector<TUtf16String>& v, size_t index, size_t count, const TWtringBuf delim) {
const size_t f = Min(index, v.size());
const size_t l = f + Min(count, v.size() - f);