aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authorpkalinnikov <pkalinnikov@yandex-team.ru>2022-02-10 16:50:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:15 +0300
commit9e33e026829d561d6fd46d72b88c367952e08075 (patch)
tree2af190fca83ac522e9a7e29de1daae32582064b4 /util/string
parentba5325cc01aabb81effc91ff1bdbb461313cbd00 (diff)
downloadydb-9e33e026829d561d6fd46d72b88c367952e08075.tar.gz
Restoring authorship annotation for <pkalinnikov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/escape.cpp76
-rw-r--r--util/string/escape.h14
-rw-r--r--util/string/escape_ut.cpp52
-rw-r--r--util/string/hex.cpp4
-rw-r--r--util/string/hex.h8
5 files changed, 77 insertions, 77 deletions
diff --git a/util/string/escape.cpp b/util/string/escape.cpp
index cd09a7dbd0..bbe8bbd0d2 100644
--- a/util/string/escape.cpp
+++ b/util/string/escape.cpp
@@ -242,9 +242,9 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
default:
res.append(*p);
break;
- case 'a':
- res.append('\a');
- break;
+ case 'a':
+ res.append('\a');
+ break;
case 'b':
res.append('\b');
break;
@@ -260,9 +260,9 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
case 't':
res.append('\t');
break;
- case 'v':
- res.append('\v');
- break;
+ case 'v':
+ res.append('\v');
+ break;
case 'u': {
ui16 cp[2];
@@ -318,13 +318,13 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) {
}
++p;
- } else {
+ } else {
const auto r = std::basic_string_view<TChar>(p, pe - p).find('\\');
const auto n = r != std::string::npos ? p + r : pe;
res.append(p, n);
p = n;
- }
+ }
}
return res;
@@ -363,43 +363,43 @@ template TUtf16String& UnescapeCImpl<TUtf16String::TChar>(const TUtf16String::TC
template char* UnescapeC<char>(const char* str, size_t len, char* buf);
-template <class TChar>
-size_t UnescapeCCharLen(const TChar* begin, const TChar* end) {
+template <class TChar>
+size_t UnescapeCCharLen(const TChar* begin, const TChar* end) {
if (begin >= end) {
- return 0;
+ return 0;
}
if (*begin != '\\') {
- return 1;
+ return 1;
}
if (++begin == end) {
- return 1;
+ return 1;
}
-
- switch (*begin) {
- default:
- return 2;
- case 'u':
- return CountHex<4>(begin + 1, end) == 4 ? 6 : 2;
- case 'U':
- return CountHex<8>(begin + 1, end) == 8 ? 10 : 2;
- case 'x':
- return 2 + CountHex<2>(begin + 1, end);
- case '0':
- case '1':
- case '2':
- case '3':
- return 1 + CountOct<3>(begin, end); // >= 2
- case '4':
- case '5':
- case '6':
- case '7':
- return 1 + CountOct<2>(begin, end); // >= 2
- }
-}
-
-template size_t UnescapeCCharLen<char>(const char* begin, const char* end);
+
+ switch (*begin) {
+ default:
+ return 2;
+ case 'u':
+ return CountHex<4>(begin + 1, end) == 4 ? 6 : 2;
+ case 'U':
+ return CountHex<8>(begin + 1, end) == 8 ? 10 : 2;
+ case 'x':
+ return 2 + CountHex<2>(begin + 1, end);
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ return 1 + CountOct<3>(begin, end); // >= 2
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ return 1 + CountOct<2>(begin, end); // >= 2
+ }
+}
+
+template size_t UnescapeCCharLen<char>(const char* begin, const char* end);
template size_t UnescapeCCharLen<TUtf16String::TChar>(const TUtf16String::TChar* begin, const TUtf16String::TChar* end);
-
+
TString& EscapeC(const TStringBuf str, TString& s) {
return EscapeC(str.data(), str.size(), s);
}
diff --git a/util/string/escape.h b/util/string/escape.h
index b01be65b0e..9ab9cf574d 100644
--- a/util/string/escape.h
+++ b/util/string/escape.h
@@ -61,10 +61,10 @@ TUtf16String& UnescapeC(const TWtringBuf str, TUtf16String& res);
TString UnescapeC(const TStringBuf str);
TUtf16String UnescapeC(const TWtringBuf wtr);
-
-/// Returns number of chars in escape sequence.
-/// - 0, if begin >= end
-/// - 1, if [begin, end) starts with an unescaped char
-/// - at least 2 (including '\'), if [begin, end) starts with an escaped symbol
-template <class TChar>
-size_t UnescapeCCharLen(const TChar* begin, const TChar* end);
+
+/// Returns number of chars in escape sequence.
+/// - 0, if begin >= end
+/// - 1, if [begin, end) starts with an unescaped char
+/// - at least 2 (including '\'), if [begin, end) starts with an escaped symbol
+template <class TChar>
+size_t UnescapeCCharLen(const TChar* begin, const TChar* end);
diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp
index cd38ecffd3..c3e6e3a05b 100644
--- a/util/string/escape_ut.cpp
+++ b/util/string/escape_ut.cpp
@@ -103,33 +103,33 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) {
// UNIT_ASSERT_VALUES_EQUAL("[x]?z", EscapeC(TString("??(x??)?z")));
UNIT_ASSERT_VALUES_EQUAL("\\x3F?x\\x3F\\x3F?z", EscapeC(TString("??x???z")));
}
-
+
Y_UNIT_TEST(TestUnescapeCCharLen) {
- auto test = [](const char* str, size_t len) {
- UNIT_ASSERT_EQUAL(UnescapeCCharLen(str, str + strlen(str)), len);
- };
-
- test("", 0);
- test("abc", 1);
- test("\\", 1);
- test("\\\\", 2);
- test("\\#", 2);
- test("\\n10", 2);
- test("\\r\\n", 2);
- test("\\x05abc", 4);
- test("\\u11117777", 6);
- test("\\u123yyy", 2);
- test("\\U11117777cccc", 10);
- test("\\U111yyy", 2);
- test("\\0\\1", 2);
- test("\\01\\1", 3);
- test("\\012\\1", 4);
- test("\\0123\\1", 4);
- test("\\4\\1", 2);
- test("\\40\\1", 3);
- test("\\400\\1", 3);
- test("\\4xxx", 2);
- }
+ auto test = [](const char* str, size_t len) {
+ UNIT_ASSERT_EQUAL(UnescapeCCharLen(str, str + strlen(str)), len);
+ };
+
+ test("", 0);
+ test("abc", 1);
+ test("\\", 1);
+ test("\\\\", 2);
+ test("\\#", 2);
+ test("\\n10", 2);
+ test("\\r\\n", 2);
+ test("\\x05abc", 4);
+ test("\\u11117777", 6);
+ test("\\u123yyy", 2);
+ test("\\U11117777cccc", 10);
+ test("\\U111yyy", 2);
+ test("\\0\\1", 2);
+ test("\\01\\1", 3);
+ test("\\012\\1", 4);
+ test("\\0123\\1", 4);
+ test("\\4\\1", 2);
+ test("\\40\\1", 3);
+ test("\\400\\1", 3);
+ test("\\4xxx", 2);
+ }
Y_UNIT_TEST(TestUnbounded) {
char buf[100000];
diff --git a/util/string/hex.cpp b/util/string/hex.cpp
index 667397987f..75aa031639 100644
--- a/util/string/hex.cpp
+++ b/util/string/hex.cpp
@@ -56,8 +56,8 @@ TString HexEncode(const void* in, size_t len) {
TString HexDecode(const void* in, size_t len) {
TString ret;
- ret.ReserveAndResize(len >> 1);
- HexDecode(in, len, ret.begin());
+ ret.ReserveAndResize(len >> 1);
+ HexDecode(in, len, ret.begin());
return ret;
}
diff --git a/util/string/hex.h b/util/string/hex.h
index af3d2d528f..81f9dd42ec 100644
--- a/util/string/hex.h
+++ b/util/string/hex.h
@@ -32,8 +32,8 @@ TString HexEncode(const void* in, size_t len);
inline TString HexEncode(const TStringBuf h) {
return HexEncode(h.data(), h.size());
-}
-
+}
+
//! Convert a hex string @c in of @c len chars (case-insensitive) to array of ints stored at @c ptr and return this array.
/*! @note len must be even (len % 2 == 0), otherwise an exception will be thrown.
* @return @c ptr, which is an array of chars, where each char holds the numeric value
@@ -52,8 +52,8 @@ void* HexDecode(const void* in, size_t len, void* ptr);
* @example HexDecode("beef", 4) => {190, 239}
*/
TString HexDecode(const void* in, size_t len);
-
+
//! Convert an ASCII hex-string (case-insensitive) to the binary form. Note that h.Size() must be even (+h % 2 == 0).
inline TString HexDecode(const TStringBuf h) {
return HexDecode(h.data(), h.size());
-}
+}