aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authorsandello <sandello@yandex-team.ru>2022-02-10 16:49:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:52 +0300
commit0cdbcf332f1f329f0a3d6759462ad71e7867ac08 (patch)
tree6866207854e212f8179cb77bd1e2435e49743f66 /util/string
parent3f5911a056d3dbc4bfd724740244a3a9c11575ef (diff)
downloadydb-0cdbcf332f1f329f0a3d6759462ad71e7867ac08.tar.gz
Restoring authorship annotation for <sandello@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/escape.cpp78
-rw-r--r--util/string/escape_ut.cpp24
2 files changed, 51 insertions, 51 deletions
diff --git a/util/string/escape.cpp b/util/string/escape.cpp
index cd09a7dbd0..66e5cb167e 100644
--- a/util/string/escape.cpp
+++ b/util/string/escape.cpp
@@ -7,30 +7,30 @@
/// @todo: escape trigraphs (eg "??/" is "\")
-/* REFEREBCES FOR ESCAPE SEQUENCE INTERPRETATION:
- * C99 p. 6.4.3 Universal character names.
- * C99 p. 6.4.4.4 Character constants.
- *
- * <simple-escape-sequence> ::= {
- * \' , \" , \? , \\ ,
- * \a , \b , \f , \n , \r , \t , \v
- * }
- *
- * <octal-escape-sequence> ::= \ <octal-digit> {1, 3}
- * <hexadecimal-escape-sequence> ::= \x <hexadecimal-digit> +
- * <universal-character-name> ::= \u <hexadecimal-digit> {4}
- * || \U <hexadecimal-digit> {8}
- *
- * NOTE (6.4.4.4.7):
- * Each octal or hexadecimal escape sequence is the longest sequence of characters that can
- * constitute the escape sequence.
- *
+/* REFEREBCES FOR ESCAPE SEQUENCE INTERPRETATION:
+ * C99 p. 6.4.3 Universal character names.
+ * C99 p. 6.4.4.4 Character constants.
+ *
+ * <simple-escape-sequence> ::= {
+ * \' , \" , \? , \\ ,
+ * \a , \b , \f , \n , \r , \t , \v
+ * }
+ *
+ * <octal-escape-sequence> ::= \ <octal-digit> {1, 3}
+ * <hexadecimal-escape-sequence> ::= \x <hexadecimal-digit> +
+ * <universal-character-name> ::= \u <hexadecimal-digit> {4}
+ * || \U <hexadecimal-digit> {8}
+ *
+ * NOTE (6.4.4.4.7):
+ * Each octal or hexadecimal escape sequence is the longest sequence of characters that can
+ * constitute the escape sequence.
+ *
* THEREFORE:
- * - Octal escape sequence spans until rightmost non-octal-digit character.
- * - Octal escape sequence always terminates after three octal digits.
- * - Hexadecimal escape sequence spans until rightmost non-hexadecimal-digit character.
- * - Universal character name consists of exactly 4 or 8 hexadecimal digit.
- *
+ * - Octal escape sequence spans until rightmost non-octal-digit character.
+ * - Octal escape sequence always terminates after three octal digits.
+ * - Hexadecimal escape sequence spans until rightmost non-hexadecimal-digit character.
+ * - Universal character name consists of exactly 4 or 8 hexadecimal digit.
+ *
* by kerzum@
* It is also required to escape trigraphs that are enabled in compilers by default and
* are also processed inside string literals
@@ -39,7 +39,7 @@
* Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
* Replacement: [ ] { } # \ ^ | ~
*
- */
+ */
namespace {
template <typename TChar>
static inline char HexDigit(TChar value) {
@@ -152,24 +152,24 @@ template <class TChar>
TBasicString<TChar>& EscapeCImpl(const TChar* str, size_t len, TBasicString<TChar>& r) {
using TEscapeUtil = ::TEscapeUtil<TChar>;
- TChar buffer[TEscapeUtil::ESCAPE_C_BUFFER_SIZE];
+ TChar buffer[TEscapeUtil::ESCAPE_C_BUFFER_SIZE];
- size_t i, j;
- for (i = 0, j = 0; i < len; ++i) {
- size_t rlen = TEscapeUtil::EscapeC(str[i], (i + 1 < len ? str[i + 1] : 0), buffer);
+ size_t i, j;
+ for (i = 0, j = 0; i < len; ++i) {
+ size_t rlen = TEscapeUtil::EscapeC(str[i], (i + 1 < len ? str[i + 1] : 0), buffer);
- if (rlen > 1) {
- r.append(str + j, i - j);
- j = i + 1;
- r.append(buffer, rlen);
- }
+ if (rlen > 1) {
+ r.append(str + j, i - j);
+ j = i + 1;
+ r.append(buffer, rlen);
+ }
}
-
- if (j > 0) {
- r.append(str + j, len - j);
- } else {
+
+ if (j > 0) {
+ r.append(str + j, len - j);
+ } else {
r.append(str, len);
- }
+ }
return r;
}
@@ -415,7 +415,7 @@ TString EscapeC(const TString& str) {
TUtf16String EscapeC(const TUtf16String& str) {
return EscapeC(str.data(), str.size());
}
-
+
TString& UnescapeC(const TStringBuf str, TString& s) {
return UnescapeC(str.data(), str.size(), s);
}
diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp
index cd38ecffd3..9df568e958 100644
--- a/util/string/escape_ut.cpp
+++ b/util/string/escape_ut.cpp
@@ -21,7 +21,7 @@ namespace {
}
static const TExample CommonTestData[] = {
- // Should be valid UTF-8.
+ // Should be valid UTF-8.
{"http://ya.ru/", "http://ya.ru/"},
{"http://ya.ru/\\x17\\n", "http://ya.ru/\x17\n"},
@@ -31,12 +31,12 @@ static const TExample CommonTestData[] = {
"0"sv},
{"http://ya.ru/\\0\\0001", "http://ya.ru/\0\x00"
"1"sv},
-
+
{R"(\2\4\00678)", "\2\4\6"
"78"sv}, // \6 -> \006 because next char '7' is "octal"
{R"(\2\4\689)", "\2\4\6"
"89"sv}, // \6 -> \6 because next char '8' is not "octal"
-
+
{R"(\"Hello\", Alice said.)", "\"Hello\", Alice said."},
{"Slash\\\\dash!", "Slash\\dash!"},
{R"(There\nare\r\nnewlines.)", "There\nare\r\nnewlines."},
@@ -45,7 +45,7 @@ static const TExample CommonTestData[] = {
{"There are questions \\x3F\\x3F?", "There are questions ???"},
{"There are questions \\x3F?", "There are questions ??"},
};
-
+
Y_UNIT_TEST_SUITE(TEscapeCTest) {
Y_UNIT_TEST(TestStrokaEscapeC) {
for (const auto& e : CommonTestData) {
@@ -53,18 +53,18 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) {
TString source(e.Source);
TString actual(EscapeC(e.Source));
TString actual2(UnescapeC(e.Expected));
-
+
UNIT_ASSERT_VALUES_EQUAL(e.Expected, actual);
UNIT_ASSERT_VALUES_EQUAL(e.Source, actual2);
- }
-
+ }
+
UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\x17\\n\\xAB", EscapeC(TString("http://ya.ru/\x17\n\xab")));
UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\x17\n\xab", UnescapeC(TString("http://ya.ru/\\x17\\n\\xAB")));
UNIT_ASSERT_VALUES_EQUAL("h", EscapeC('h'));
UNIT_ASSERT_VALUES_EQUAL("h", UnescapeC(TString("h")));
UNIT_ASSERT_VALUES_EQUAL("\\xFF", EscapeC('\xFF'));
UNIT_ASSERT_VALUES_EQUAL("\xFF", UnescapeC(TString("\\xFF")));
-
+
UNIT_ASSERT_VALUES_EQUAL("\\377f", EscapeC(TString("\xff"
"f")));
UNIT_ASSERT_VALUES_EQUAL("\xff"
@@ -85,11 +85,11 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) {
TUtf16String source(UTF8ToWide(e.Source));
TUtf16String actual(EscapeC(source));
TUtf16String actual2(UnescapeC(expected));
-
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
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"));
UNIT_ASSERT_VALUES_EQUAL(u"h", EscapeC(u'h'));
UNIT_ASSERT_VALUES_EQUAL(u"\\xFF", EscapeC(wchar16(255)));