diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | 6170310e8721e225f64ddabf7a7358253d7a1249 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/string_utils | |
parent | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (diff) | |
download | ydb-6170310e8721e225f64ddabf7a7358253d7a1249.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils')
-rw-r--r-- | library/cpp/string_utils/base64/base64.cpp | 14 | ||||
-rw-r--r-- | library/cpp/string_utils/base64/base64.h | 4 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.cpp | 12 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.h | 8 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote_ut.cpp | 72 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url_ut.cpp | 2 |
6 files changed, 56 insertions, 56 deletions
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index 92060ad00f..05c201f0de 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -246,14 +246,14 @@ size_t Base64Decode(void* dst, const char* b, const char* e) { } TString Base64DecodeUneven(const TStringBuf s) { - if (s.length() % 4 == 0) { - return Base64Decode(s); - } - - // padding to 4 + if (s.length() % 4 == 0) { + return Base64Decode(s); + } + + // padding to 4 return Base64Decode(TString(s) + TString(4 - (s.length() % 4), '=')); -} - +} + char* Base64Encode(char* outstr, const unsigned char* instr, size_t len) { static const TImpl IMPL = GetImpl(); if (Y_LIKELY(len < 8)) { diff --git a/library/cpp/string_utils/base64/base64.h b/library/cpp/string_utils/base64/base64.h index 7941dd4d03..f778a6425a 100644 --- a/library/cpp/string_utils/base64/base64.h +++ b/library/cpp/string_utils/base64/base64.h @@ -88,9 +88,9 @@ inline TString Base64StrictDecode(const TStringBuf src) { } /// @} -/// Works with strings which length is not divisible by 4. +/// Works with strings which length is not divisible by 4. TString Base64DecodeUneven(const TStringBuf s); - + //encode constexpr size_t Base64EncodeBufSize(const size_t len) noexcept { return (len + 2) / 3 * 4 + 1; diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index 672e122d3d..e523350b80 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -276,14 +276,14 @@ TString UrlUnescapeRet(const TStringBuf from) { return to; } -char* UrlEscape(char* to, const char* from, bool forceEscape) { +char* UrlEscape(char* to, const char* from, bool forceEscape) { from = FixZero(from); while (*from) { - const bool escapePercent = (*from == '%') && - (forceEscape || !((*(from + 1) && IsAsciiHex(*(from + 1)) && *(from + 2) && IsAsciiHex(*(from + 2))))); - - if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') { + const bool escapePercent = (*from == '%') && + (forceEscape || !((*(from + 1) && IsAsciiHex(*(from + 1)) && *(from + 2) && IsAsciiHex(*(from + 2))))); + + if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') { *to++ = '%'; *to++ = d2x((unsigned char)*from >> 4); *to++ = d2x((unsigned char)*from & 0xF); @@ -297,7 +297,7 @@ char* UrlEscape(char* to, const char* from, bool forceEscape) { return to; } -void UrlEscape(TString& url, bool forceEscape) { +void UrlEscape(TString& url, bool forceEscape) { TTempBuf tempBuf(CgiEscapeBufLen(url.size())); char* to = tempBuf.Data(); url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape)); diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 9163769fc4..3b7221154e 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -48,11 +48,11 @@ void Quote(TString& url, const char* safe = "/"); //UrlEscape: // Can't be used for cgi parameters ('&' character is not escaped)! -// escapes only '%' not followed by two hex-digits or if forceEscape set to ture, -// and chars outside [32, 126] range. +// escapes only '%' not followed by two hex-digits or if forceEscape set to ture, +// and chars outside [32, 126] range. // Can't handle '\0'-chars in TString. -char* UrlEscape(char* to, const char* from, bool forceEscape = false); -void UrlEscape(TString& url, bool forceEscape = false); +char* UrlEscape(char* to, const char* from, bool forceEscape = false); +void UrlEscape(TString& url, bool forceEscape = false); TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); //UrlUnescape: diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 5f6fb583a3..6c552b279e 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -178,25 +178,25 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { } } -Y_UNIT_TEST_SUITE(TUrlEscapeTest) { - Y_UNIT_TEST(EscapeEscaped) { - TString s; - - s = "hello%3dworld"; +Y_UNIT_TEST_SUITE(TUrlEscapeTest) { + Y_UNIT_TEST(EscapeEscaped) { + TString s; + + s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s), "hello%3dworld"); - UrlEscape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); - } - - Y_UNIT_TEST(EscapeUnescape) { - TString s; - - s = "hello%3dworld"; - UrlEscape(s); - UrlUnescape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello=world"); - } - + UrlEscape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); + } + + Y_UNIT_TEST(EscapeUnescape) { + TString s; + + s = "hello%3dworld"; + UrlEscape(s); + UrlUnescape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello=world"); + } + Y_UNIT_TEST(EscapeUnescapeRet) { TString s; @@ -204,23 +204,23 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s)), "hello=world"); } - Y_UNIT_TEST(EscapeEscapedForce) { - TString s; - - s = "hello%3dworld"; + Y_UNIT_TEST(EscapeEscapedForce) { + TString s; + + s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s, true), "hello%253dworld"); - UrlEscape(s, true); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%253dworld"); - } - - Y_UNIT_TEST(EscapeUnescapeForce) { - TString s; - - s = "hello%3dworld"; - UrlEscape(s, true); - UrlUnescape(s); - UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); - } + UrlEscape(s, true); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%253dworld"); + } + + Y_UNIT_TEST(EscapeUnescapeForce) { + TString s; + + s = "hello%3dworld"; + UrlEscape(s, true); + UrlUnescape(s); + UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); + } Y_UNIT_TEST(EscapeUnescapeForceRet) { TString s; @@ -228,8 +228,8 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { s = "hello%3dworld"; UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s, true)), "hello%3dworld"); } -} - +} + Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { Y_UNIT_TEST(StrokaOutParameterInplace) { TString s; diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index a103661002..1588013893 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -97,7 +97,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", CutHttpPrefix("ftp://ya.ru")); UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true)); + UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true)); UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz")); UNIT_ASSERT_VALUES_EQUAL("https://ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz", true)); UNIT_ASSERT_VALUES_EQUAL("", CutHttpPrefix("https://")); // is that right? |