diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /library/cpp/string_utils/quote | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/quote')
-rw-r--r-- | library/cpp/string_utils/quote/quote.cpp | 48 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.h | 18 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote_ut.cpp | 14 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/ut/ya.make | 16 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/ya.make | 20 |
5 files changed, 58 insertions, 58 deletions
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e523350b80..9350765b01 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -1,8 +1,8 @@ #include "quote.h" #include <util/memory/tempbuf.h> -#include <util/string/ascii.h> -#include <util/string/cstriter.h> +#include <util/string/ascii.h> +#include <util/string/cstriter.h> #include <cctype> @@ -14,14 +14,14 @@ ++x; \ } while (0) -#define GETSBXC \ - do { \ - c *= 16; \ - c += (x[0] >= 'A' ? ((x[0] & 0xdf) - 'A') + 10 : (x[0] - '0')); \ - x.Skip(1); \ - } while (0) - - +#define GETSBXC \ + do { \ + c *= 16; \ + c += (x[0] >= 'A' ? ((x[0] & 0xdf) - 'A') + 10 : (x[0] - '0')); \ + x.Skip(1); \ + } while (0) + + namespace { class TFromHexZeroTerm { public: @@ -40,8 +40,8 @@ namespace { return '%'; ui8 c = 0; - GETSBXC; - GETSBXC; + GETSBXC; + GETSBXC; return c; } }; @@ -68,7 +68,7 @@ static inline char d2x(unsigned x) { return (char)((x < 10) ? ('0' + x) : ('A' + x - 10)); } -static inline const char* FixZero(const char* s) noexcept { +static inline const char* FixZero(const char* s) noexcept { return s ? s : ""; } @@ -155,15 +155,15 @@ char* CGIEscape(char* to, const char* from, size_t len) { return Escape(to, from, from + len); } -void CGIEscape(TString& url) { +void CGIEscape(TString& url) { TTempBuf tempBuf(CgiEscapeBufLen(url.size())); char* to = tempBuf.Data(); url.AssignNoAlias(to, CGIEscape(to, url.data(), url.size())); } -TString CGIEscapeRet(const TStringBuf url) { - TString to; +TString CGIEscapeRet(const TStringBuf url) { + TString to; to.ReserveAndResize(CgiEscapeBufLen(url.size())); to.resize(CGIEscape(to.begin(), url.data(), url.size()) - to.data()); return to; @@ -207,7 +207,7 @@ char* Quote(char* to, const TStringBuf s, const char* safe) { return Quote(to, s.data(), s.data() + s.size(), safe); } -void Quote(TString& url, const char* safe) { +void Quote(TString& url, const char* safe) { TTempBuf tempBuf(CgiEscapeBufLen(url.size())); char* to = tempBuf.Data(); @@ -222,7 +222,7 @@ char* CGIUnescape(char* to, const char* from, size_t len) { return Unescape(to, from, from + len, TFromHexLenLimited(from + len)); } -void CGIUnescape(TString& url) { +void CGIUnescape(TString& url) { if (url.empty()) { return; } @@ -235,8 +235,8 @@ void CGIUnescape(TString& url) { } } -TString CGIUnescapeRet(const TStringBuf from) { - TString to; +TString CGIUnescapeRet(const TStringBuf from) { + TString to; to.ReserveAndResize(CgiUnescapeBufLen(from.size())); to.resize(CGIUnescape(to.begin(), from.data(), from.size()) - to.data()); return to; @@ -245,7 +245,7 @@ TString CGIUnescapeRet(const TStringBuf from) { char* UrlUnescape(char* to, TStringBuf from) { while (!from.empty()) { char ch = from[0]; - from.Skip(1); + from.Skip(1); if ('%' == ch && 2 <= from.length()) ch = TFromHexZeroTerm::x2c(from); *to++ = ch; @@ -256,7 +256,7 @@ char* UrlUnescape(char* to, TStringBuf from) { return to; } -void UrlUnescape(TString& url) { +void UrlUnescape(TString& url) { if (url.empty()) { return; } @@ -269,8 +269,8 @@ void UrlUnescape(TString& url) { } } -TString UrlUnescapeRet(const TStringBuf from) { - TString to; +TString UrlUnescapeRet(const TStringBuf from) { + TString to; to.ReserveAndResize(CgiUnescapeBufLen(from.size())); to.resize(UrlUnescape(to.begin(), from) - to.data()); return to; diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3b7221154e..605a5cd858 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h> //CGIEscape*: // ' ' converted to '+', @@ -13,8 +13,8 @@ char* CGIEscape(char* to, const char* from, size_t len); inline char* CGIEscape(char* to, const TStringBuf from) { return CGIEscape(to, from.data(), from.size()); } -void CGIEscape(TString& url); -TString CGIEscapeRet(const TStringBuf url); +void CGIEscape(TString& url); +TString CGIEscapeRet(const TStringBuf url); TString& AppendCgiEscaped(const TStringBuf value, TString& to); inline TStringBuf CgiEscapeBuf(char* to, const TStringBuf from) { @@ -30,8 +30,8 @@ inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) { // 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); +void CGIUnescape(TString& url); +TString CGIUnescapeRet(const TStringBuf from); inline TStringBuf CgiUnescapeBuf(char* to, const TStringBuf from) { return TStringBuf(to, CGIUnescape(to, from.data(), from.size())); @@ -44,13 +44,13 @@ inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) { // 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 = "/"); +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. -// Can't handle '\0'-chars in TString. +// 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); @@ -59,8 +59,8 @@ TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); // '+' 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); +void UrlUnescape(TString& url); +TString UrlUnescapeRet(const TStringBuf from); //*BufLen: how much characters you should allocate for 'char* to' buffers. constexpr size_t CgiEscapeBufLen(const size_t len) noexcept { diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 6c552b279e..46015c8046 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) { char r[] = {'1', '2', '3', '4'}; char buf[sizeof(r) * 3 + 2]; - TString ret(buf, CGIEscape(buf, r, sizeof(r))); + TString ret(buf, CGIEscape(buf, r, sizeof(r))); UNIT_ASSERT_EQUAL(ret, "1234"); } @@ -125,7 +125,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { } Y_UNIT_TEST(StrokaOutParameterInplace) { - TString s; + TString s; s = "hello%3dworld"; CGIUnescape(s); @@ -149,7 +149,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { } Y_UNIT_TEST(StrokaOutParameterNotInplace) { - TString s, sCopy; + TString s, sCopy; s = "hello%3dworld"; sCopy = s; @@ -232,7 +232,7 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { Y_UNIT_TEST(StrokaOutParameterInplace) { - TString s; + TString s; s = "hello%3dworld"; UrlUnescape(s); @@ -256,7 +256,7 @@ Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { } Y_UNIT_TEST(StrokaOutParameterNotInplace) { - TString s, sCopy; + TString s, sCopy; s = "hello%3dworld"; sCopy = s; @@ -297,7 +297,7 @@ Y_UNIT_TEST_SUITE(TQuoteTest) { char r[100]; Quote(r, "/path;tail/path,tail/"); UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", r); - TString s("/path;tail/path,tail/"); + TString s("/path;tail/path,tail/"); Quote(s); UNIT_ASSERT_VALUES_EQUAL("/path%3Btail/path%2Ctail/", s.c_str()); } @@ -306,7 +306,7 @@ Y_UNIT_TEST_SUITE(TQuoteTest) { char r[100]; Quote(r, "/path;tail/path,tail/", ";,"); UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", r); - TString s("/path;tail/path,tail/"); + TString s("/path;tail/path,tail/"); Quote(s, ";,"); UNIT_ASSERT_VALUES_EQUAL("%2Fpath;tail%2Fpath,tail%2F", s.c_str()); } diff --git a/library/cpp/string_utils/quote/ut/ya.make b/library/cpp/string_utils/quote/ut/ya.make index eca955144f..50a6c0d85b 100644 --- a/library/cpp/string_utils/quote/ut/ya.make +++ b/library/cpp/string_utils/quote/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/string_utils/quote) - -OWNER(vladon) - -SRCS( - quote_ut.cpp -) - -END() + +OWNER(vladon) + +SRCS( + quote_ut.cpp +) + +END() diff --git a/library/cpp/string_utils/quote/ya.make b/library/cpp/string_utils/quote/ya.make index 55bb3cf939..d48130fe24 100644 --- a/library/cpp/string_utils/quote/ya.make +++ b/library/cpp/string_utils/quote/ya.make @@ -1,10 +1,10 @@ -LIBRARY() - -OWNER(g:util) - -SRCS( - quote.cpp - quote.h -) - -END() +LIBRARY() + +OWNER(g:util) + +SRCS( + quote.cpp + quote.h +) + +END() |