aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorasavin <asavin@yandex-team.ru>2022-02-10 16:49:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:56 +0300
commitfa977fb6c7b468a86cf33f948fdae8e0c83d3cad (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library
parent0cbe97538e6c240dfb7424ac5c2173cd6a489734 (diff)
downloadydb-fa977fb6c7b468a86cf33f948fdae8e0c83d3cad.tar.gz
Restoring authorship annotation for <asavin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/string_utils/quote/quote.cpp68
-rw-r--r--library/cpp/string_utils/quote/quote_ut.cpp126
2 files changed, 97 insertions, 97 deletions
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp
index 9f6d8d5c9d..e523350b80 100644
--- a/library/cpp/string_utils/quote/quote.cpp
+++ b/library/cpp/string_utils/quote/quote.cpp
@@ -22,18 +22,18 @@
} while (0)
-namespace {
- class TFromHexZeroTerm {
- public:
+namespace {
+ class TFromHexZeroTerm {
+ public:
static inline char x2c(const char*& x) {
if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
- return '%';
- ui8 c = 0;
+ return '%';
+ ui8 c = 0;
GETXC;
GETXC;
- return c;
- }
+ return c;
+ }
static inline char x2c(TStringBuf& x) {
if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
@@ -44,24 +44,24 @@ namespace {
GETSBXC;
return c;
}
- };
-
- class TFromHexLenLimited {
- public:
- TFromHexLenLimited(const char* end)
- : End(end)
- {
- }
-
+ };
+
+ class TFromHexLenLimited {
+ public:
+ TFromHexLenLimited(const char* end)
+ : End(end)
+ {
+ }
+
inline char x2c(const char*& x) {
- if (x + 2 > End)
- return '%';
- return TFromHexZeroTerm::x2c(x);
- }
-
- private:
- const char* End;
- };
+ if (x + 2 > End)
+ return '%';
+ return TFromHexZeroTerm::x2c(x);
+ }
+
+ private:
+ const char* End;
+ };
}
static inline char d2x(unsigned x) {
@@ -122,12 +122,12 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha
return to;
}
-template <class It1, class It2, class It3, class FromHex>
+template <class It1, class It2, class It3, class FromHex>
static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) {
(void)fromHex;
- while (from != end) {
- switch (*from) {
+ while (from != end) {
+ switch (*from) {
case '%':
++from;
*to++ = fromHex.x2c(from);
@@ -138,12 +138,12 @@ static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) {
break;
default:
*to++ = *from++;
- }
- }
- *to = 0;
- return to;
-}
-
+ }
+ }
+ *to = 0;
+ return to;
+}
+
// CGIEscape returns pointer to the end of the result string
// so as it could be possible to populate single long buffer
// with several calls to CGIEscape in a row.
@@ -216,7 +216,7 @@ void Quote(TString& url, const char* safe) {
char* CGIUnescape(char* to, const char* from) {
return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm());
-}
+}
char* CGIUnescape(char* to, const char* from, size_t len) {
return Unescape(to, from, from + len, TFromHexLenLimited(from + len));
diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp
index 829bdfd166..6c552b279e 100644
--- a/library/cpp/string_utils/quote/quote_ut.cpp
+++ b/library/cpp/string_utils/quote/quote_ut.cpp
@@ -55,74 +55,74 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) {
}
Y_UNIT_TEST(TestValidZeroTerm) {
- char r[10];
-
- CGIUnescape(r, "1234");
- UNIT_ASSERT_VALUES_EQUAL(r, "1234");
-
- CGIUnescape(r, "%3d");
- UNIT_ASSERT_VALUES_EQUAL(r, "=");
-
- CGIUnescape(r, "12%3D34");
- UNIT_ASSERT_VALUES_EQUAL(r, "12=34");
- }
-
+ char r[10];
+
+ CGIUnescape(r, "1234");
+ UNIT_ASSERT_VALUES_EQUAL(r, "1234");
+
+ CGIUnescape(r, "%3d");
+ UNIT_ASSERT_VALUES_EQUAL(r, "=");
+
+ CGIUnescape(r, "12%3D34");
+ UNIT_ASSERT_VALUES_EQUAL(r, "12=34");
+ }
+
Y_UNIT_TEST(TestInvalidZeroTerm) {
- char r[10];
-
- CGIUnescape(r, "%");
- UNIT_ASSERT_VALUES_EQUAL(r, "%");
-
- CGIUnescape(r, "%3");
- UNIT_ASSERT_VALUES_EQUAL(r, "%3");
-
- CGIUnescape(r, "%3g");
- UNIT_ASSERT_VALUES_EQUAL(r, "%3g");
-
- CGIUnescape(r, "12%3g34");
- UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34");
-
+ char r[10];
+
+ CGIUnescape(r, "%");
+ UNIT_ASSERT_VALUES_EQUAL(r, "%");
+
+ CGIUnescape(r, "%3");
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3");
+
+ CGIUnescape(r, "%3g");
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3g");
+
+ CGIUnescape(r, "12%3g34");
+ UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34");
+
CGIUnescape(r, "%3u123");
- UNIT_ASSERT_VALUES_EQUAL(r, "%3u123");
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3u123");
+ }
+
Y_UNIT_TEST(TestValidNotZeroTerm) {
- char r[10];
-
- CGIUnescape(r, "123456789", 4);
- UNIT_ASSERT_VALUES_EQUAL(r, "1234");
-
- CGIUnescape(r, "%3d1234", 3);
- UNIT_ASSERT_VALUES_EQUAL(r, "=");
-
- CGIUnescape(r, "12%3D345678", 7);
- UNIT_ASSERT_VALUES_EQUAL(r, "12=34");
- }
-
+ char r[10];
+
+ CGIUnescape(r, "123456789", 4);
+ UNIT_ASSERT_VALUES_EQUAL(r, "1234");
+
+ CGIUnescape(r, "%3d1234", 3);
+ UNIT_ASSERT_VALUES_EQUAL(r, "=");
+
+ CGIUnescape(r, "12%3D345678", 7);
+ UNIT_ASSERT_VALUES_EQUAL(r, "12=34");
+ }
+
Y_UNIT_TEST(TestInvalidNotZeroTerm) {
- char r[10];
-
- CGIUnescape(r, "%3d", 1);
- UNIT_ASSERT_VALUES_EQUAL(r, "%");
-
- CGIUnescape(r, "%3d", 2);
- UNIT_ASSERT_VALUES_EQUAL(r, "%3");
-
- CGIUnescape(r, "%3g1234", 3);
- UNIT_ASSERT_VALUES_EQUAL(r, "%3g");
-
- CGIUnescape(r, "12%3g345678", 7);
- UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34");
-
+ char r[10];
+
+ CGIUnescape(r, "%3d", 1);
+ UNIT_ASSERT_VALUES_EQUAL(r, "%");
+
+ CGIUnescape(r, "%3d", 2);
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3");
+
+ CGIUnescape(r, "%3g1234", 3);
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3g");
+
+ CGIUnescape(r, "12%3g345678", 7);
+ UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34");
+
CGIUnescape(r, "%3u1234", 2);
- UNIT_ASSERT_VALUES_EQUAL(r, "%3");
-
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3");
+
CGIUnescape(r, "%3u1234", 3);
- UNIT_ASSERT_VALUES_EQUAL(r, "%3u");
-
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3u");
+
CGIUnescape(r, "%3u1234", 4);
- UNIT_ASSERT_VALUES_EQUAL(r, "%3u1");
- }
+ UNIT_ASSERT_VALUES_EQUAL(r, "%3u1");
+ }
Y_UNIT_TEST(StrokaOutParameterInplace) {
TString s;
@@ -176,8 +176,8 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) {
CGIUnescape(s);
UNIT_ASSERT_VALUES_EQUAL(s, "");
}
-}
-
+}
+
Y_UNIT_TEST_SUITE(TUrlEscapeTest) {
Y_UNIT_TEST(EscapeEscaped) {
TString s;