diff options
author | Ilnur Khuziev <ilnur.khuziev@yandex.ru> | 2022-02-10 16:46:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:14 +0300 |
commit | 60040c91ffe701a84689b2c6310ff845e65cff42 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp/string_utils/url | |
parent | 736dcd8ca259457a136f2f9f9168c44643914323 (diff) | |
download | ydb-60040c91ffe701a84689b2c6310ff845e65cff42.tar.gz |
Restoring authorship annotation for Ilnur Khuziev <ilnur.khuziev@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils/url')
-rw-r--r-- | library/cpp/string_utils/url/url.cpp | 38 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.h | 94 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url_ut.cpp | 2 | ||||
-rw-r--r-- | library/cpp/string_utils/url/ut/ya.make | 2 |
4 files changed, 68 insertions, 68 deletions
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 376a09a465..85f4ac5d69 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -73,31 +73,31 @@ namespace NUrl { } // namespace NUrl -size_t GetHttpPrefixSize(const char* url, bool ignorehttps) noexcept { +size_t GetHttpPrefixSize(const char* url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<char>(url, TUncheckedSize(), ignorehttps); } -size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps) noexcept { +size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<wchar16>(url, TUncheckedSize(), ignorehttps); } -size_t GetHttpPrefixSize(const TStringBuf url, bool ignorehttps) noexcept { +size_t GetHttpPrefixSize(const TStringBuf url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<char>(url.data(), TKnownSize(url.size()), ignorehttps); } -size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps) noexcept { +size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps) noexcept { return GetHttpPrefixSizeImpl<wchar16>(url.data(), TKnownSize(url.size()), ignorehttps); } -TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps) noexcept { +TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps) noexcept { return CutHttpPrefixImpl(url, ignorehttps); } -TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps) noexcept { +TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps) noexcept { return CutHttpPrefixImpl(url, ignorehttps); } -size_t GetSchemePrefixSize(const TStringBuf url) noexcept { +size_t GetSchemePrefixSize(const TStringBuf url) noexcept { struct TDelim: public str_spn { inline TDelim() : str_spn("!-/:-@[-`{|}", true) @@ -115,11 +115,11 @@ size_t GetSchemePrefixSize(const TStringBuf url) noexcept { return n + 3 - url.begin(); } -TStringBuf GetSchemePrefix(const TStringBuf url) noexcept { +TStringBuf GetSchemePrefix(const TStringBuf url) noexcept { return url.Head(GetSchemePrefixSize(url)); } -TStringBuf CutSchemePrefix(const TStringBuf url) noexcept { +TStringBuf CutSchemePrefix(const TStringBuf url) noexcept { return url.Tail(GetSchemePrefixSize(url)); } @@ -146,15 +146,15 @@ static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) { return urlNoScheme; } -TStringBuf GetHost(const TStringBuf url) noexcept { +TStringBuf GetHost(const TStringBuf url) noexcept { return GetHostAndPortImpl<false>(url); } -TStringBuf GetHostAndPort(const TStringBuf url) noexcept { +TStringBuf GetHostAndPort(const TStringBuf url) noexcept { return GetHostAndPortImpl<true>(url); } -TStringBuf GetSchemeHostAndPort(const TStringBuf url, bool trimHttp, bool trimDefaultPort) noexcept { +TStringBuf GetSchemeHostAndPort(const TStringBuf url, bool trimHttp, bool trimDefaultPort) noexcept { const size_t schemeSize = GetSchemePrefixSize(url); const TStringBuf scheme = url.Head(schemeSize); @@ -235,11 +235,11 @@ void GetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBuf& Y_ENSURE(isOk, "cannot parse port number from URL: " << url); } -TStringBuf GetOnlyHost(const TStringBuf url) noexcept { +TStringBuf GetOnlyHost(const TStringBuf url) noexcept { return GetHost(CutSchemePrefix(url)); } -TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) 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)) @@ -249,7 +249,7 @@ TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept { } // this strange creature returns 2nd level domain, possibly with port -TStringBuf GetDomain(const TStringBuf host) noexcept { +TStringBuf GetDomain(const TStringBuf host) noexcept { const char* c = !host ? host.data() : host.end() - 1; for (bool wasPoint = false; c != host.data(); --c) { if (*c == '.') { @@ -263,7 +263,7 @@ TStringBuf GetDomain(const TStringBuf host) noexcept { return TStringBuf(c, host.end()); } -TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept { +TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept { size_t pos = host.size(); for (size_t i = 0; i < level; ++i) { pos = host.rfind('.', pos); @@ -273,11 +273,11 @@ TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept { return host.SubStr(pos + 1); } -TStringBuf GetZone(const TStringBuf host) noexcept { +TStringBuf GetZone(const TStringBuf host) noexcept { return GetParentDomain(host, 1); } -TStringBuf CutWWWPrefix(const TStringBuf url) noexcept { +TStringBuf CutWWWPrefix(const TStringBuf url) noexcept { if (url.size() >= 4 && url[3] == '.' && !strnicmp(url.data(), "www", 3)) return url.substr(4); return url; @@ -388,7 +388,7 @@ size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, return len; } -TStringBuf RemoveFinalSlash(TStringBuf str) noexcept { +TStringBuf RemoveFinalSlash(TStringBuf str) noexcept { if (str.EndsWith('/')) { str.Chop(1); } diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index 64e82485a1..84137ccc57 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -23,39 +23,39 @@ namespace NUrl { } // namespace NUrl -Y_PURE_FUNCTION -size_t GetHttpPrefixSize(const char* url, bool ignorehttps = false) noexcept; -Y_PURE_FUNCTION -size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps = false) noexcept; +Y_PURE_FUNCTION +size_t GetHttpPrefixSize(const char* url, bool ignorehttps = false) noexcept; +Y_PURE_FUNCTION +size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps = false) noexcept; -Y_PURE_FUNCTION -size_t GetHttpPrefixSize(const TStringBuf url, bool ignorehttps = false) noexcept; +Y_PURE_FUNCTION +size_t GetHttpPrefixSize(const TStringBuf url, bool ignorehttps = false) noexcept; + +Y_PURE_FUNCTION +size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps = false) noexcept; -Y_PURE_FUNCTION -size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps = false) noexcept; - /** BEWARE of TStringBuf! You can not use operator ~ or c_str() like in TString !!!!!!!!!!!! */ -Y_PURE_FUNCTION -size_t GetSchemePrefixSize(const TStringBuf url) noexcept; +Y_PURE_FUNCTION +size_t GetSchemePrefixSize(const TStringBuf url) noexcept; -Y_PURE_FUNCTION -TStringBuf GetSchemePrefix(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 //! @param url URL from which the prefix should be removed //! @param ignorehttps if true, leaves https:// //! @return a new URL without protocol prefix -Y_PURE_FUNCTION -TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps = false) noexcept; +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 -TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps = false) noexcept; +Y_PURE_FUNCTION +TStringBuf CutSchemePrefix(const TStringBuf url) noexcept; -Y_PURE_FUNCTION -TStringBuf CutSchemePrefix(const TStringBuf url) noexcept; - //! adds specified scheme prefix if URL has no scheme //! @note if URL has scheme prefix already the function returns unchanged URL TString AddSchemePrefix(const TString& url, const TStringBuf scheme); @@ -63,15 +63,15 @@ TString AddSchemePrefix(const TString& url, const TStringBuf scheme); //! Same as `AddSchemePrefix(url, "http")`. TString AddSchemePrefix(const TString& url); -Y_PURE_FUNCTION -TStringBuf GetHost(const TStringBuf url) noexcept; +Y_PURE_FUNCTION +TStringBuf GetHost(const TStringBuf url) noexcept; + +Y_PURE_FUNCTION +TStringBuf GetHostAndPort(const TStringBuf url) noexcept; + +Y_PURE_FUNCTION +TStringBuf GetSchemeHostAndPort(const TStringBuf url, bool trimHttp = true, bool trimDefaultPort = true) noexcept; -Y_PURE_FUNCTION -TStringBuf GetHostAndPort(const TStringBuf url) noexcept; - -Y_PURE_FUNCTION -TStringBuf GetSchemeHostAndPort(const TStringBuf url, bool trimHttp = true, bool trimDefaultPort = true) noexcept; - /** * Splits URL to host and path * @@ -123,25 +123,25 @@ bool TryGetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBu */ void GetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBuf& host, ui16& port); -Y_PURE_FUNCTION -TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment = true) noexcept; +Y_PURE_FUNCTION +TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment = true) noexcept; /** * Extracts host from url and cuts http(https) protocol prefix and port if any. * @param[in] url any URL * @return host without port and http(https) prefix. */ -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" - -Y_PURE_FUNCTION -TStringBuf GetZone(const TStringBuf host) noexcept; - -Y_PURE_FUNCTION -TStringBuf CutWWWPrefix(const TStringBuf url) noexcept; - +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" + +Y_PURE_FUNCTION +TStringBuf GetZone(const TStringBuf host) noexcept; + +Y_PURE_FUNCTION +TStringBuf CutWWWPrefix(const TStringBuf url) noexcept; + Y_PURE_FUNCTION TStringBuf CutWWWNumberedPrefix(const TStringBuf url) noexcept; @@ -153,17 +153,17 @@ TStringBuf CutWWWNumberedPrefix(const TStringBuf url) noexcept; * @param[in] url any URL * @return url without 'm.' or 'M.' prefix. */ -Y_PURE_FUNCTION +Y_PURE_FUNCTION TStringBuf CutMPrefix(const TStringBuf url) noexcept; Y_PURE_FUNCTION -TStringBuf GetDomain(const TStringBuf host) noexcept; // should not be used - +TStringBuf GetDomain(const TStringBuf host) noexcept; // should not be used + size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size); size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport = 80); -Y_PURE_FUNCTION -TStringBuf RemoveFinalSlash(TStringBuf str) noexcept; +Y_PURE_FUNCTION +TStringBuf RemoveFinalSlash(TStringBuf str) noexcept; TStringBuf CutUrlPrefixes(TStringBuf url) noexcept; bool DoesUrlPathStartWithToken(TStringBuf url, const TStringBuf& token) noexcept; diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 4fbab25081..1588013893 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -2,7 +2,7 @@ #include <util/string/cast.h> -#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TUtilUrlTest) { Y_UNIT_TEST(TestGetHostAndGetHostAndPort) { diff --git a/library/cpp/string_utils/url/ut/ya.make b/library/cpp/string_utils/url/ut/ya.make index ca75e04baf..0efa30e4d2 100644 --- a/library/cpp/string_utils/url/ut/ya.make +++ b/library/cpp/string_utils/url/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/string_utils/url) +UNITTEST_FOR(library/cpp/string_utils/url) OWNER(g:util) |