diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /library/cpp/string_utils | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils')
-rw-r--r-- | library/cpp/string_utils/quote/quote.cpp | 22 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.h | 40 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote_ut.cpp | 12 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.cpp | 14 |
4 files changed, 44 insertions, 44 deletions
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e523350b80..a445636fd6 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -77,9 +77,9 @@ static inline const char* FixZero(const char* s) noexcept { // '%', '&', '+', ',', // '#', '<', '=', '>', // '[', '\\',']', '?', -// ':', '{', '}', +// ':', '{', '}', // all below ' ' (0x20) and above '~' (0x7E). -// ' ' converted to '+' +// ' ' converted to '+' static const bool chars_to_url_escape[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //0 @@ -111,7 +111,7 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha *to++ = d2x((unsigned char)*from >> 4); *to++ = d2x((unsigned char)*from & 0xF); } else { - *to++ = (*from == ' ' ? '+' : *from); + *to++ = (*from == ' ' ? '+' : *from); } ++from; @@ -123,7 +123,7 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha } template <class It1, class It2, class It3, class FromHex> -static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) { +static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) { (void)fromHex; while (from != end) { @@ -167,8 +167,8 @@ TString CGIEscapeRet(const TStringBuf url) { to.ReserveAndResize(CgiEscapeBufLen(url.size())); to.resize(CGIEscape(to.begin(), url.data(), url.size()) - to.data()); return to; -} - +} + TString& AppendCgiEscaped(const TStringBuf value, TString& to) { const size_t origLength = to.length(); to.ReserveAndResize(origLength + CgiEscapeBufLen(value.size())); @@ -215,11 +215,11 @@ void Quote(TString& url, const char* safe) { } char* CGIUnescape(char* to, const char* from) { - return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm()); + 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)); +char* CGIUnescape(char* to, const char* from, size_t len) { + return Unescape(to, from, from + len, TFromHexLenLimited(from + len)); } void CGIUnescape(TString& url) { @@ -240,8 +240,8 @@ TString CGIUnescapeRet(const TStringBuf from) { to.ReserveAndResize(CgiUnescapeBufLen(from.size())); to.resize(CGIUnescape(to.begin(), from.data(), from.size()) - to.data()); return to; -} - +} + char* UrlUnescape(char* to, TStringBuf from) { while (!from.empty()) { char ch = from[0]; diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3b7221154e..55150d31f6 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -3,11 +3,11 @@ #include <util/generic/strbuf.h> #include <util/generic/string.h> -//CGIEscape*: -// ' ' converted to '+', -// Some punctuation and chars outside [32, 126] range are converted to %xx -// Use function CgiEscapeBufLen to determine number of characters needed for 'char* to' parameter. -// Returns pointer to the end of the result string +//CGIEscape*: +// ' ' converted to '+', +// Some punctuation and chars outside [32, 126] range are converted to %xx +// Use function CgiEscapeBufLen to determine number of characters needed for 'char* to' parameter. +// Returns pointer to the end of the result string char* CGIEscape(char* to, const char* from); char* CGIEscape(char* to, const char* from, size_t len); inline char* CGIEscape(char* to, const TStringBuf from) { @@ -24,12 +24,12 @@ inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) { return CgiEscapeBuf(static_cast<char*>(tmp), s); } -//CgiUnescape*: -// Decodes '%xx' to bytes, '+' to space. -// Use function CgiUnescapeBufLen to determine number of characters needed for 'char* to' parameter. -// If pointer returned, then this is pointer to the end of the result string. -char* CGIUnescape(char* to, const char* from); -char* CGIUnescape(char* to, const char* from, size_t len); +//CgiUnescape*: +// Decodes '%xx' to bytes, '+' to space. +// Use function CgiUnescapeBufLen to determine number of characters needed for 'char* to' parameter. +// If pointer returned, then this is pointer to the end of the result string. +char* CGIUnescape(char* to, const char* from); +char* CGIUnescape(char* to, const char* from, size_t len); void CGIUnescape(TString& url); TString CGIUnescapeRet(const TStringBuf from); @@ -40,29 +40,29 @@ inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) { return CgiUnescapeBuf(static_cast<char*>(tmp), s); } -//Quote: -// Is like CGIEscape, also skips encoding of user-supplied 'safe' characters. +//Quote: +// Is like CGIEscape, also skips encoding of user-supplied 'safe' characters. char* Quote(char* to, const char* from, const char* safe = "/"); char* Quote(char* to, const TStringBuf s, const char* safe = "/"); void Quote(TString& url, const char* safe = "/"); -//UrlEscape: -// Can't be used for cgi parameters ('&' character is not escaped)! +//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. // Can't handle '\0'-chars in TString. 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: -// '+' is NOT converted to space! -// %xx converted to bytes, other characters are copied unchanged. + +//UrlUnescape: +// '+' is NOT converted to space! +// %xx converted to bytes, other characters are copied unchanged. char* UrlUnescape(char* to, TStringBuf from); void UrlUnescape(TString& url); TString UrlUnescapeRet(const TStringBuf from); -//*BufLen: how much characters you should allocate for 'char* to' buffers. +//*BufLen: how much characters you should allocate for 'char* to' buffers. constexpr size_t CgiEscapeBufLen(const size_t len) noexcept { return 3 * len + 1; } diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 6c552b279e..056589b3eb 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -24,10 +24,10 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) { UNIT_ASSERT_VALUES_EQUAL(CgiEscape(tmp, "!@#$%^&*(){}[]\" "), TStringBuf("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); } - + Y_UNIT_TEST(StrokaRet) { UNIT_ASSERT_VALUES_EQUAL(CGIEscapeRet("!@#$%^&*(){}[]\" "), TString("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); - } + } Y_UNIT_TEST(StrokaAppendRet) { TString param; @@ -82,7 +82,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { CGIUnescape(r, "12%3g34"); UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34"); - CGIUnescape(r, "%3u123"); + CGIUnescape(r, "%3u123"); UNIT_ASSERT_VALUES_EQUAL(r, "%3u123"); } @@ -114,13 +114,13 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { CGIUnescape(r, "12%3g345678", 7); UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34"); - CGIUnescape(r, "%3u1234", 2); + CGIUnescape(r, "%3u1234", 2); UNIT_ASSERT_VALUES_EQUAL(r, "%3"); - CGIUnescape(r, "%3u1234", 3); + CGIUnescape(r, "%3u1234", 3); UNIT_ASSERT_VALUES_EQUAL(r, "%3u"); - CGIUnescape(r, "%3u1234", 4); + CGIUnescape(r, "%3u1234", 4); UNIT_ASSERT_VALUES_EQUAL(r, "%3u1"); } diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d69..82887bd3a0 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -241,11 +241,11 @@ TStringBuf GetOnlyHost(const TStringBuf url) noexcept { TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept { const size_t off = url.find('/', GetHttpPrefixSize(url)); - TStringBuf hostUnused, path; - if (!url.TrySplitAt(off, hostUnused, path)) + TStringBuf hostUnused, path; + if (!url.TrySplitAt(off, hostUnused, path)) return "/"; - - return trimFragment ? path.Before('#') : path; + + return trimFragment ? path.Before('#') : path; } // this strange creature returns 2nd level domain, possibly with port @@ -311,15 +311,15 @@ TStringBuf CutMPrefix(const TStringBuf url) noexcept { } static inline bool IsSchemeChar(char c) noexcept { - return IsAsciiAlnum(c); //what about '+' ?.. + return IsAsciiAlnum(c); //what about '+' ?.. } static bool HasPrefix(const TStringBuf url) noexcept { - TStringBuf scheme, unused; + TStringBuf scheme, unused; if (!url.TrySplit(TStringBuf("://"), scheme, unused)) return false; - return AllOf(scheme, IsSchemeChar); + return AllOf(scheme, IsSchemeChar); } TString AddSchemePrefix(const TString& url) { |