aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authorRuslan Kovalev <ruslan.a.kovalev@gmail.com>2022-02-10 16:46:44 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:44 +0300
commit59e19371de37995fcb36beb16cd6ec030af960bc (patch)
treefa68e36093ebff8b805462e9e6d331fe9d348214 /util/string
parent89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff)
downloadydb-59e19371de37995fcb36beb16cd6ec030af960bc.tar.gz
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/cast.h4
-rw-r--r--util/string/escape.cpp80
-rw-r--r--util/string/escape.h38
-rw-r--r--util/string/escape_ut.cpp2
-rw-r--r--util/string/hex.h2
-rw-r--r--util/string/split.h2
-rw-r--r--util/string/subst_ut.cpp180
-rw-r--r--util/string/type_ut.cpp4
-rw-r--r--util/string/util.h4
-rw-r--r--util/string/vector.h2
10 files changed, 159 insertions, 159 deletions
diff --git a/util/string/cast.h b/util/string/cast.h
index 90e925c194..a18a116811 100644
--- a/util/string/cast.h
+++ b/util/string/cast.h
@@ -1,11 +1,11 @@
-#pragma once
+#pragma once
#include <util/system/defaults.h>
#include <util/stream/str.h>
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
#include <util/generic/typetraits.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
/*
* specialized for all arithmetic types
diff --git a/util/string/escape.cpp b/util/string/escape.cpp
index cd09a7dbd0..3898d6ac69 100644
--- a/util/string/escape.cpp
+++ b/util/string/escape.cpp
@@ -3,7 +3,7 @@
#include <util/system/defaults.h>
#include <util/charset/utf8.h>
-#include <util/charset/wide.h>
+#include <util/charset/wide.h>
/// @todo: escape trigraphs (eg "??/" is "\")
@@ -168,10 +168,10 @@ TBasicString<TChar>& EscapeCImpl(const TChar* str, size_t len, TBasicString<TCha
if (j > 0) {
r.append(str + j, len - j);
} else {
- r.append(str, len);
+ r.append(str, len);
}
-
- return r;
+
+ return r;
}
template TString& EscapeCImpl<TString::TChar>(const TString::TChar* str, size_t len, TString& r);
@@ -186,23 +186,23 @@ namespace {
WriteUTF8Char(v, sz, (ui8*)buf);
s.AppendNoAlias(buf, sz);
}
-
+
inline void AppendUnicode(TUtf16String& s, wchar32 v) {
WriteSymbol(v, s);
}
-
+
template <ui32 sz, typename TChar>
inline size_t CountHex(const TChar* p, const TChar* pe) {
auto b = p;
auto e = Min(p + sz, pe);
-
+
while (b < e && IsHexDigit(*b)) {
++b;
}
return b - p;
- }
-
+ }
+
template <size_t sz, typename TChar, typename T>
inline bool ParseHex(const TChar* p, const TChar* pe, T& t) noexcept {
return (p + sz <= pe) && TryIntFromString<16>(p, sz, t);
@@ -211,36 +211,36 @@ namespace {
template <ui32 sz, typename TChar>
inline size_t CountOct(const TChar* p, const TChar* pe) {
ui32 maxsz = Min<size_t>(sz, pe - p);
-
+
if (3 == sz && 3 == maxsz && !(*p >= '0' && *p <= '3')) {
maxsz = 2;
}
-
+
for (ui32 i = 0; i < maxsz; ++i, ++p) {
if (!IsOctDigit(*p)) {
return i;
}
}
-
+
return maxsz;
- }
-}
-
+ }
+}
+
template <class TChar, class TStr>
static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
const TChar* pe = p + sz;
-
+
while (p != pe) {
- if ('\\' == *p) {
- ++p;
-
+ if ('\\' == *p) {
+ ++p;
+
if (p == pe) {
- return res;
+ return res;
}
-
+
switch (*p) {
default:
- res.append(*p);
+ res.append(*p);
break;
case 'a':
res.append('\a');
@@ -297,7 +297,7 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
} else {
res.append(*p);
}
-
+
break;
case '0':
case '1':
@@ -315,7 +315,7 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
res.append((TChar)IntFromString<ui32, 8>(p, v));
p += v - 1;
} break;
- }
+ }
++p;
} else {
@@ -325,11 +325,11 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
res.append(p, n);
p = n;
}
- }
-
- return res;
-}
-
+ }
+
+ return res;
+}
+
template <class TChar>
TBasicString<TChar>& UnescapeCImpl(const TChar* p, size_t sz, TBasicString<TChar>& res) {
return DoUnescapeC(p, sz, res);
@@ -402,12 +402,12 @@ template size_t UnescapeCCharLen<TUtf16String::TChar>(const TUtf16String::TChar*
TString& EscapeC(const TStringBuf str, TString& s) {
return EscapeC(str.data(), str.size(), s);
-}
-
+}
+
TUtf16String& EscapeC(const TWtringBuf str, TUtf16String& w) {
return EscapeC(str.data(), str.size(), w);
-}
-
+}
+
TString EscapeC(const TString& str) {
return EscapeC(str.data(), str.size());
}
@@ -418,16 +418,16 @@ TUtf16String EscapeC(const TUtf16String& str) {
TString& UnescapeC(const TStringBuf str, TString& s) {
return UnescapeC(str.data(), str.size(), s);
-}
-
+}
+
TUtf16String& UnescapeC(const TWtringBuf str, TUtf16String& w) {
return UnescapeC(str.data(), str.size(), w);
-}
-
+}
+
TString UnescapeC(const TStringBuf str) {
return UnescapeC(str.data(), str.size());
-}
-
+}
+
TUtf16String UnescapeC(const TWtringBuf str) {
return UnescapeC(str.data(), str.size());
-}
+}
diff --git a/util/string/escape.h b/util/string/escape.h
index b01be65b0e..fe69e21edd 100644
--- a/util/string/escape.h
+++ b/util/string/escape.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
@@ -6,21 +6,21 @@
template <class TChar>
TBasicString<TChar>& EscapeCImpl(const TChar* str, size_t len, TBasicString<TChar>&);
-template <class TChar>
+template <class TChar>
TBasicString<TChar>& UnescapeCImpl(const TChar* str, size_t len, TBasicString<TChar>&);
-
+
template <class TChar>
TChar* UnescapeC(const TChar* str, size_t len, TChar* buf);
template <typename TChar>
static inline TBasicString<TChar>& EscapeC(const TChar* str, size_t len, TBasicString<TChar>& s) {
- return EscapeCImpl(str, len, s);
-}
-
-template <typename TChar>
+ return EscapeCImpl(str, len, s);
+}
+
+template <typename TChar>
static inline TBasicString<TChar> EscapeC(const TChar* str, size_t len) {
TBasicString<TChar> s;
- return EscapeC(str, len, s);
+ return EscapeC(str, len, s);
}
template <typename TChar>
@@ -30,16 +30,16 @@ static inline TBasicString<TChar> EscapeC(const TBasicStringBuf<TChar>& str) {
template <typename TChar>
static inline TBasicString<TChar>& UnescapeC(const TChar* str, size_t len, TBasicString<TChar>& s) {
- return UnescapeCImpl(str, len, s);
-}
-
-template <typename TChar>
+ return UnescapeCImpl(str, len, s);
+}
+
+template <typename TChar>
static inline TBasicString<TChar> UnescapeC(const TChar* str, size_t len) {
TBasicString<TChar> s;
- return UnescapeCImpl(str, len, s);
-}
-
-template <typename TChar>
+ return UnescapeCImpl(str, len, s);
+}
+
+template <typename TChar>
static inline TBasicString<TChar> EscapeC(TChar ch) {
return EscapeC(&ch, 1);
}
@@ -51,14 +51,14 @@ static inline TBasicString<TChar> EscapeC(const TChar* str) {
TString& EscapeC(const TStringBuf str, TString& res);
TUtf16String& EscapeC(const TWtringBuf str, TUtf16String& res);
-
+
// these two need to be methods, because of TBasicString::Quote implementation
TString EscapeC(const TString& str);
TUtf16String EscapeC(const TUtf16String& str);
-
+
TString& UnescapeC(const TStringBuf str, TString& res);
TUtf16String& UnescapeC(const TWtringBuf str, TUtf16String& res);
-
+
TString UnescapeC(const TStringBuf str);
TUtf16String UnescapeC(const TWtringBuf wtr);
diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp
index cd38ecffd3..17555e0e0c 100644
--- a/util/string/escape_ut.cpp
+++ b/util/string/escape_ut.cpp
@@ -87,7 +87,7 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) {
TUtf16String actual2(UnescapeC(expected));
UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- UNIT_ASSERT_VALUES_EQUAL(source, actual2);
+ UNIT_ASSERT_VALUES_EQUAL(source, actual2);
}
UNIT_ASSERT_VALUES_EQUAL(u"http://ya.ru/\\x17\\n\\u1234", EscapeC(u"http://ya.ru/\x17\n\u1234"));
diff --git a/util/string/hex.h b/util/string/hex.h
index af3d2d528f..bfe5c9a785 100644
--- a/util/string/hex.h
+++ b/util/string/hex.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <util/generic/string.h>
#include <util/generic/yexception.h>
diff --git a/util/string/split.h b/util/string/split.h
index bc46d9e64c..e6190ceafe 100644
--- a/util/string/split.h
+++ b/util/string/split.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include "strspn.h"
#include "cast.h"
diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp
index 21eccef779..2a966992be 100644
--- a/util/string/subst_ut.cpp
+++ b/util/string/subst_ut.cpp
@@ -1,124 +1,124 @@
-#include "join.h"
+#include "join.h"
#include "subst.h"
#include <string>
#include <library/cpp/testing/unittest/registar.h>
Y_UNIT_TEST_SUITE(TStringSubst) {
- static const size_t MIN_FROM_CTX = 4;
+ static const size_t MIN_FROM_CTX = 4;
static const TVector<TString> ALL_FROM{TString("F"), TString("FF")};
static const TVector<TString> ALL_TO{TString(""), TString("T"), TString("TT"), TString("TTT")};
-
+
static void AssertSubstGlobal(const TString& sFrom, const TString& sTo, const TString& from, const TString& to, const size_t fromPos, const size_t numSubst) {
TString s = sFrom;
- size_t res = SubstGlobal(s, from, to, fromPos);
- UNIT_ASSERT_VALUES_EQUAL_C(res, numSubst,
- TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
- if (numSubst) {
- UNIT_ASSERT_STRINGS_EQUAL_C(s, sTo,
- TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
- } else {
- // ensure s didn't trigger copy-on-write
- UNIT_ASSERT_VALUES_EQUAL_C(s.c_str(), sFrom.c_str(),
- TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
- }
- }
-
+ size_t res = SubstGlobal(s, from, to, fromPos);
+ UNIT_ASSERT_VALUES_EQUAL_C(res, numSubst,
+ TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
+ if (numSubst) {
+ UNIT_ASSERT_STRINGS_EQUAL_C(s, sTo,
+ TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
+ } else {
+ // ensure s didn't trigger copy-on-write
+ UNIT_ASSERT_VALUES_EQUAL_C(s.c_str(), sFrom.c_str(),
+ TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo);
+ }
+ }
+
Y_UNIT_TEST(TestSubstGlobalNoSubstA) {
- for (const auto& from : ALL_FROM) {
+ for (const auto& from : ALL_FROM) {
const size_t fromSz = from.size();
- const size_t minSz = fromSz;
- const size_t maxSz = fromSz + MIN_FROM_CTX;
- for (size_t sz = minSz; sz <= maxSz; ++sz) {
- for (size_t fromPos = 0; fromPos < sz; ++fromPos) {
+ const size_t minSz = fromSz;
+ const size_t maxSz = fromSz + MIN_FROM_CTX;
+ for (size_t sz = minSz; sz <= maxSz; ++sz) {
+ for (size_t fromPos = 0; fromPos < sz; ++fromPos) {
TString s{sz, '.'};
- for (const auto& to : ALL_TO) {
- AssertSubstGlobal(s, s, from, to, fromPos, 0);
- }
- }
- }
- }
- }
-
+ for (const auto& to : ALL_TO) {
+ AssertSubstGlobal(s, s, from, to, fromPos, 0);
+ }
+ }
+ }
+ }
+ }
+
Y_UNIT_TEST(TestSubstGlobalNoSubstB) {
- for (const auto& from : ALL_FROM) {
+ for (const auto& from : ALL_FROM) {
const size_t fromSz = from.size();
- const size_t minSz = fromSz;
- const size_t maxSz = fromSz + MIN_FROM_CTX;
- for (size_t sz = minSz; sz <= maxSz; ++sz) {
- for (size_t fromPos = 0; fromPos <= sz - fromSz; ++fromPos) {
- for (size_t fromBeg = 0; fromBeg < fromPos; ++fromBeg) {
- const auto parts = {
+ const size_t minSz = fromSz;
+ const size_t maxSz = fromSz + MIN_FROM_CTX;
+ for (size_t sz = minSz; sz <= maxSz; ++sz) {
+ for (size_t fromPos = 0; fromPos <= sz - fromSz; ++fromPos) {
+ for (size_t fromBeg = 0; fromBeg < fromPos; ++fromBeg) {
+ const auto parts = {
TString{fromBeg, '.'},
TString{sz - fromSz - fromBeg, '.'}};
TString s = JoinSeq(from, parts);
- for (const auto& to : ALL_TO) {
- AssertSubstGlobal(s, s, from, to, fromPos, 0);
- }
- }
- }
- }
- }
- }
-
+ for (const auto& to : ALL_TO) {
+ AssertSubstGlobal(s, s, from, to, fromPos, 0);
+ }
+ }
+ }
+ }
+ }
+ }
+
static void DoTestSubstGlobal(TVector<TString>& parts, const size_t minBeg, const size_t sz,
const TString& from, const size_t fromPos, const size_t numSubst) {
- const size_t numLeft = numSubst - parts.size();
+ const size_t numLeft = numSubst - parts.size();
for (size_t fromBeg = minBeg; fromBeg <= sz - numLeft * from.size(); ++fromBeg) {
- if (parts.empty()) {
- parts.emplace_back(fromBeg, '.');
- } else {
- parts.emplace_back(fromBeg - minBeg, '.');
- }
-
- if (numLeft == 1) {
+ if (parts.empty()) {
+ parts.emplace_back(fromBeg, '.');
+ } else {
+ parts.emplace_back(fromBeg - minBeg, '.');
+ }
+
+ if (numLeft == 1) {
parts.emplace_back(sz - fromBeg - from.size(), '.');
TString sFrom = JoinSeq(from, parts);
UNIT_ASSERT_VALUES_EQUAL_C(sFrom.size(), sz, sFrom);
- for (const auto& to : ALL_TO) {
+ for (const auto& to : ALL_TO) {
TString sTo = JoinSeq(to, parts);
- AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst);
- }
- parts.pop_back();
- } else {
+ AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst);
+ }
+ parts.pop_back();
+ } else {
DoTestSubstGlobal(parts, fromBeg + from.size(), sz, from, fromPos, numSubst);
- }
-
- parts.pop_back();
- }
- }
-
- static void DoTestSubstGlobal(size_t numSubst) {
+ }
+
+ parts.pop_back();
+ }
+ }
+
+ static void DoTestSubstGlobal(size_t numSubst) {
TVector<TString> parts;
- for (const auto& from : ALL_FROM) {
+ for (const auto& from : ALL_FROM) {
const size_t fromSz = from.size();
- const size_t minSz = numSubst * fromSz;
- const size_t maxSz = numSubst * (fromSz + MIN_FROM_CTX);
- for (size_t sz = minSz; sz <= maxSz; ++sz) {
- const size_t maxPos = sz - numSubst * fromSz;
- for (size_t fromPos = 0; fromPos <= maxPos; ++fromPos) {
- DoTestSubstGlobal(parts, fromPos, sz, from, fromPos, numSubst);
- }
- }
- }
- }
-
+ const size_t minSz = numSubst * fromSz;
+ const size_t maxSz = numSubst * (fromSz + MIN_FROM_CTX);
+ for (size_t sz = minSz; sz <= maxSz; ++sz) {
+ const size_t maxPos = sz - numSubst * fromSz;
+ for (size_t fromPos = 0; fromPos <= maxPos; ++fromPos) {
+ DoTestSubstGlobal(parts, fromPos, sz, from, fromPos, numSubst);
+ }
+ }
+ }
+ }
+
Y_UNIT_TEST(TestSubstGlobalSubst1) {
- DoTestSubstGlobal(1);
- }
-
+ DoTestSubstGlobal(1);
+ }
+
Y_UNIT_TEST(TestSubstGlobalSubst2) {
- DoTestSubstGlobal(2);
- }
-
+ DoTestSubstGlobal(2);
+ }
+
Y_UNIT_TEST(TestSubstGlobalSubst3) {
- DoTestSubstGlobal(3);
- }
-
+ DoTestSubstGlobal(3);
+ }
+
Y_UNIT_TEST(TestSubstGlobalSubst4) {
- DoTestSubstGlobal(4);
- }
-
+ DoTestSubstGlobal(4);
+ }
+
Y_UNIT_TEST(TestSubstGlobalOld) {
TString s;
s = "aaa";
@@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
SubstGlobal(s, " ~ ", " ");
UNIT_ASSERT_EQUAL(s, TString("Москва Париж"));
}
-
+
Y_UNIT_TEST(TestSubstGlobalOldRet) {
const TString s1 = "aaa";
const TString s2 = SubstGlobalCopy(s1, "a", "bb");
diff --git a/util/string/type_ut.cpp b/util/string/type_ut.cpp
index 03e7af62bd..60cb35e6a5 100644
--- a/util/string/type_ut.cpp
+++ b/util/string/type_ut.cpp
@@ -20,11 +20,11 @@ Y_UNIT_TEST_SUITE(TStringClassify) {
UNIT_ASSERT(IsTrue("true"));
UNIT_ASSERT(IsTrue("t"));
UNIT_ASSERT(IsTrue("da"));
-
+
UNIT_ASSERT(!IsTrue(""));
UNIT_ASSERT(!IsTrue("tr"));
UNIT_ASSERT(!IsTrue("foobar"));
- }
+ }
Y_UNIT_TEST(TestIsFalse) {
UNIT_ASSERT(IsFalse("0"));
diff --git a/util/string/util.h b/util/string/util.h
index 0d77a5042b..cd1fa56429 100644
--- a/util/string/util.h
+++ b/util/string/util.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
//THIS FILE A COMPAT STUB HEADER
@@ -8,7 +8,7 @@
#include <util/system/defaults.h>
#include <util/generic/string.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
/// @addtogroup Strings_Miscellaneous
/// @{
diff --git a/util/string/vector.h b/util/string/vector.h
index e36c348bbe..59769fd92e 100644
--- a/util/string/vector.h
+++ b/util/string/vector.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include "cast.h"
#include "split.h"