diff options
author | somov <somov@yandex-team.ru> | 2022-02-10 16:45:47 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:47 +0300 |
commit | a5950576e397b1909261050b8c7da16db58f10b1 (patch) | |
tree | 7ba7677f6a4c3e19e2cefab34d16df2c8963b4d4 /library/cpp/string_utils/url | |
parent | 81eddc8c0b55990194e112b02d127b87d54164a9 (diff) | |
download | ydb-a5950576e397b1909261050b8c7da16db58f10b1.tar.gz |
Restoring authorship annotation for <somov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/url')
-rw-r--r-- | library/cpp/string_utils/url/url.cpp | 24 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.h | 6 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url_ut.cpp | 14 |
3 files changed, 22 insertions, 22 deletions
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d69..988122e5d1 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -312,28 +312,28 @@ TStringBuf CutMPrefix(const TStringBuf url) noexcept { static inline bool IsSchemeChar(char c) noexcept { return IsAsciiAlnum(c); //what about '+' ?.. -} - +} + static bool HasPrefix(const TStringBuf url) noexcept { TStringBuf scheme, unused; if (!url.TrySplit(TStringBuf("://"), scheme, unused)) - return false; - + return false; + return AllOf(scheme, IsSchemeChar); -} - +} + TString AddSchemePrefix(const TString& url) { return AddSchemePrefix(url, TStringBuf("http")); } TString AddSchemePrefix(const TString& url, TStringBuf scheme) { - if (HasPrefix(url)) { - return url; - } - + if (HasPrefix(url)) { + return url; + } + return TString::Join(scheme, TStringBuf("://"), url); -} - +} + #define X(c) (c >= 'A' ? ((c & 0xdf) - 'A') + 10 : (c - '0')) static inline int x2c(unsigned char* x) { diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index 84137ccc57..c5c550ea6b 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -56,10 +56,10 @@ TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps = false) noexcep 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 +//! 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); - + //! Same as `AddSchemePrefix(url, "http")`. TString AddSchemePrefix(const TString& url); diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 1588013893..02a0de9e5f 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -69,14 +69,14 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("FHFBN", GetZone("ya.FHFBN")); UNIT_ASSERT_VALUES_EQUAL("", GetZone("")); } - + Y_UNIT_TEST(TestAddSchemePrefix) { - UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("yandex.ru")); - UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("http://yandex.ru")); - UNIT_ASSERT_VALUES_EQUAL("https://yandex.ru", AddSchemePrefix("https://yandex.ru")); - UNIT_ASSERT_VALUES_EQUAL("file://yandex.ru", AddSchemePrefix("file://yandex.ru")); - UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", AddSchemePrefix("ya.ru", "ftp")); - } + UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("yandex.ru")); + UNIT_ASSERT_VALUES_EQUAL("http://yandex.ru", AddSchemePrefix("http://yandex.ru")); + UNIT_ASSERT_VALUES_EQUAL("https://yandex.ru", AddSchemePrefix("https://yandex.ru")); + UNIT_ASSERT_VALUES_EQUAL("file://yandex.ru", AddSchemePrefix("file://yandex.ru")); + UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", AddSchemePrefix("ya.ru", "ftp")); + } Y_UNIT_TEST(TestSchemeGet) { UNIT_ASSERT_VALUES_EQUAL("http://", GetSchemePrefix("http://ya.ru/bebe")); |