diff options
author | leo <leo@yandex-team.ru> | 2022-02-10 16:46:40 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:40 +0300 |
commit | 99609724f661f7e21d1cb08e8d80e87c3632fdb3 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/string_utils | |
parent | 980edcd3304699edf9d4e4d6a656e585028e2a72 (diff) | |
download | ydb-99609724f661f7e21d1cb08e8d80e87c3632fdb3.tar.gz |
Restoring authorship annotation for <leo@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils')
-rw-r--r-- | library/cpp/string_utils/base64/base64.cpp | 10 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.cpp | 34 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.cpp | 90 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.h | 10 |
4 files changed, 72 insertions, 72 deletions
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index ab1078e889..05c201f0de 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -89,7 +89,7 @@ static const char base64_bkw[] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; - + static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size"); // Base64 for url encoding, RFC3548 @@ -133,13 +133,13 @@ static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, s } else { *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')]; *outstr++ = pad; - } + } *outstr++ = pad; - } + } *outstr = 0; - return outstr; -} + return outstr; +} static char* Base64EncodePlain(char* outstr, const unsigned char* instr, size_t len) { return Base64EncodeImpl<false>(outstr, instr, len); diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index 1288c8c4ec..e523350b80 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -112,12 +112,12 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha *to++ = d2x((unsigned char)*from & 0xF); } else { *to++ = (*from == ' ' ? '+' : *from); - } + } ++from; - } + } - *to = 0; + *to = 0; return to; } @@ -220,7 +220,7 @@ char* CGIUnescape(char* to, const char* from) { char* CGIUnescape(char* to, const char* from, size_t len) { return Unescape(to, from, from + len, TFromHexLenLimited(from + len)); -} +} void CGIUnescape(TString& url) { if (url.empty()) { @@ -234,7 +234,7 @@ void CGIUnescape(TString& url) { url = CGIUnescapeRet(url); } } - + TString CGIUnescapeRet(const TStringBuf from) { TString to; to.ReserveAndResize(CgiUnescapeBufLen(from.size())); @@ -249,13 +249,13 @@ char* UrlUnescape(char* to, TStringBuf from) { if ('%' == ch && 2 <= from.length()) ch = TFromHexZeroTerm::x2c(from); *to++ = ch; - } + } - *to = 0; + *to = 0; return to; -} - +} + void UrlUnescape(TString& url) { if (url.empty()) { return; @@ -267,8 +267,8 @@ void UrlUnescape(TString& url) { } else { url = UrlUnescapeRet(url); } -} - +} + TString UrlUnescapeRet(const TStringBuf from) { TString to; to.ReserveAndResize(CgiUnescapeBufLen(from.size())); @@ -288,20 +288,20 @@ char* UrlEscape(char* to, const char* from, bool forceEscape) { *to++ = d2x((unsigned char)*from >> 4); *to++ = d2x((unsigned char)*from & 0xF); } else - *to++ = *from; + *to++ = *from; ++from; - } + } - *to = 0; + *to = 0; return to; -} - +} + void UrlEscape(TString& url, bool forceEscape) { TTempBuf tempBuf(CgiEscapeBufLen(url.size())); char* to = tempBuf.Data(); url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape)); -} +} TString UrlEscapeRet(const TStringBuf from, bool forceEscape) { TString to; diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 32179ead5b..85f4ac5d69 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -53,15 +53,15 @@ namespace { return 0; } - template <typename T> + template <typename T> inline T CutHttpPrefixImpl(const T& url, bool ignorehttps) { size_t prefixSize = GetHttpPrefixSizeImpl<typename T::char_type>(url.data(), TKnownSize(url.size()), ignorehttps); if (prefixSize) return url.substr(prefixSize); - return url; - } -} - + return url; + } +} + namespace NUrl { TSplitUrlToHostAndPathResult SplitUrlToHostAndPath(const TStringBuf url) { @@ -75,8 +75,8 @@ namespace NUrl { size_t GetHttpPrefixSize(const char* url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<char>(url, TUncheckedSize(), ignorehttps); -} - +} + size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<wchar16>(url, TUncheckedSize(), ignorehttps); } @@ -95,8 +95,8 @@ TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps) noexcept { TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps) noexcept { return CutHttpPrefixImpl(url, ignorehttps); -} - +} + size_t GetSchemePrefixSize(const TStringBuf url) noexcept { struct TDelim: public str_spn { inline TDelim() @@ -144,8 +144,8 @@ static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) { } return urlNoScheme; -} - +} + TStringBuf GetHost(const TStringBuf url) noexcept { return GetHostAndPortImpl<false>(url); } @@ -279,10 +279,10 @@ TStringBuf GetZone(const TStringBuf host) noexcept { TStringBuf CutWWWPrefix(const TStringBuf url) noexcept { if (url.size() >= 4 && url[3] == '.' && !strnicmp(url.data(), "www", 3)) - return url.substr(4); - return url; -} - + return url.substr(4); + return url; +} + TStringBuf CutWWWNumberedPrefix(const TStringBuf url) noexcept { auto it = url.begin(); @@ -334,44 +334,44 @@ TString AddSchemePrefix(const TString& url, TStringBuf scheme) { return TString::Join(scheme, TStringBuf("://"), url); } -#define X(c) (c >= 'A' ? ((c & 0xdf) - 'A') + 10 : (c - '0')) - -static inline int x2c(unsigned char* x) { +#define X(c) (c >= 'A' ? ((c & 0xdf) - 'A') + 10 : (c - '0')) + +static inline int x2c(unsigned char* x) { if (!IsAsciiHex(x[0]) || !IsAsciiHex(x[1])) - return -1; - return X(x[0]) * 16 + X(x[1]); -} - + return -1; + return X(x[0]) * 16 + X(x[1]); +} + #undef X static inline int Unescape(char* str) { char *to, *from; - int dlen = 0; + int dlen = 0; if ((str = strchr(str, '%')) == nullptr) - return dlen; - for (to = str, from = str; *from; from++, to++) { - if ((*to = *from) == '%') { + return dlen; + for (to = str, from = str; *from; from++, to++) { + if ((*to = *from) == '%') { int c = x2c((unsigned char*)from + 1); - *to = char((c > 0) ? c : '0'); - from += 2; - dlen += 2; - } - } + *to = char((c > 0) ? c : '0'); + from += 2; + dlen += 2; + } + } *to = 0; /* terminate it at the new length */ - return dlen; -} - + return dlen; +} + size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) { if (source.empty() || source[0] == '?') - return strlcpy(dest, "/", dest_size); + return strlcpy(dest, "/", dest_size); size_t len = Min(dest_size - 1, source.length()); memcpy(dest, source.data(), len); dest[len] = 0; - len -= Unescape(dest); - strlwr(dest); - return len; -} - + len -= Unescape(dest); + strlwr(dest); + return len; +} + size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport) { size_t len = Min(dest_size - 1, source.length()); memcpy(dest, source.data(), len); @@ -382,11 +382,11 @@ size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, char* ptr = strstr(dest, buf); if (ptr && ptr[buflen] == 0) { len -= buflen; - *ptr = 0; - } - strlwr(dest); - return len; -} + *ptr = 0; + } + strlwr(dest); + return len; +} TStringBuf RemoveFinalSlash(TStringBuf str) noexcept { if (str.EndsWith('/')) { diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index be90c4ff8a..84137ccc57 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -42,17 +42,17 @@ size_t GetSchemePrefixSize(const TStringBuf url) noexcept; Y_PURE_FUNCTION TStringBuf GetSchemePrefix(const TStringBuf url) noexcept; -//! removes protocol prefixes 'http://' and 'https://' from given URL -//! @note if URL has no prefix or some other prefix the function does nothing +//! removes protocol prefixes 'http://' and 'https://' from given URL +//! @note if URL has no prefix or some other prefix the function does nothing //! @param url URL from which the prefix should be removed //! @param ignorehttps if true, leaves https:// -//! @return a new URL without protocol prefix +//! @return a new URL without protocol prefix Y_PURE_FUNCTION TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps = false) noexcept; Y_PURE_FUNCTION TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps = false) noexcept; - + Y_PURE_FUNCTION TStringBuf CutSchemePrefix(const TStringBuf url) noexcept; @@ -132,7 +132,7 @@ TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment = true) noexc */ Y_PURE_FUNCTION TStringBuf GetOnlyHost(const TStringBuf url) noexcept; - + Y_PURE_FUNCTION TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept; // ("www.ya.ru", 2) -> "ya.ru" |