aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils
diff options
context:
space:
mode:
authormowgli <mowgli@yandex-team.ru>2022-02-10 16:49:25 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:25 +0300
commit56c39b3cf908e7202b1f7551a1653681e8015607 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/string_utils
parent89afbbe4ca0e02e386dd4df08f7945f190dc1b84 (diff)
downloadydb-56c39b3cf908e7202b1f7551a1653681e8015607.tar.gz
Restoring authorship annotation for <mowgli@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/string_utils')
-rw-r--r--library/cpp/string_utils/base64/base64.h30
-rw-r--r--library/cpp/string_utils/base64/base64_ut.cpp58
-rw-r--r--library/cpp/string_utils/url/url.cpp18
-rw-r--r--library/cpp/string_utils/url/url_ut.cpp26
4 files changed, 66 insertions, 66 deletions
diff --git a/library/cpp/string_utils/base64/base64.h b/library/cpp/string_utils/base64/base64.h
index cb2d201681..f778a6425a 100644
--- a/library/cpp/string_utils/base64/base64.h
+++ b/library/cpp/string_utils/base64/base64.h
@@ -28,14 +28,14 @@ inline TStringBuf Base64Decode(const TStringBuf src, void* dst) {
}
inline void Base64Decode(const TStringBuf src, TString& dst) {
- dst.ReserveAndResize(Base64DecodeBufSize(src.size()));
- dst.resize(Base64Decode(src, dst.begin()).size());
-}
-
+ dst.ReserveAndResize(Base64DecodeBufSize(src.size()));
+ dst.resize(Base64Decode(src, dst.begin()).size());
+}
+
//WARNING: can process not whole input silently, use Base64StrictDecode instead of this function
inline TString Base64Decode(const TStringBuf s) {
TString ret;
- Base64Decode(s, ret);
+ Base64Decode(s, ret);
return ret;
}
@@ -108,23 +108,23 @@ inline TStringBuf Base64EncodeUrl(const TStringBuf src, void* tmp) {
}
inline void Base64Encode(const TStringBuf src, TString& dst) {
- dst.ReserveAndResize(Base64EncodeBufSize(src.size()));
- dst.resize(Base64Encode(src, dst.begin()).size());
-}
-
+ dst.ReserveAndResize(Base64EncodeBufSize(src.size()));
+ dst.resize(Base64Encode(src, dst.begin()).size());
+}
+
inline void Base64EncodeUrl(const TStringBuf src, TString& dst) {
- dst.ReserveAndResize(Base64EncodeBufSize(src.size()));
- dst.resize(Base64EncodeUrl(src, dst.begin()).size());
-}
-
+ dst.ReserveAndResize(Base64EncodeBufSize(src.size()));
+ dst.resize(Base64EncodeUrl(src, dst.begin()).size());
+}
+
inline TString Base64Encode(const TStringBuf s) {
TString ret;
- Base64Encode(s, ret);
+ Base64Encode(s, ret);
return ret;
}
inline TString Base64EncodeUrl(const TStringBuf s) {
TString ret;
- Base64EncodeUrl(s, ret);
+ Base64EncodeUrl(s, ret);
return ret;
}
diff --git a/library/cpp/string_utils/base64/base64_ut.cpp b/library/cpp/string_utils/base64/base64_ut.cpp
index 6a54e010a6..bcc1e65879 100644
--- a/library/cpp/string_utils/base64/base64_ut.cpp
+++ b/library/cpp/string_utils/base64/base64_ut.cpp
@@ -165,20 +165,20 @@ void Out<NB64Etalon::TImpls::EImpl>(IOutputStream& o, typename TTypeTraits<NB64E
static void TestEncodeDecodeIntoString(const TString& plain, const TString& encoded, const TString& encodedUrl) {
TString a, b;
-
- Base64Encode(plain, a);
- UNIT_ASSERT_VALUES_EQUAL(a, encoded);
-
- Base64Decode(a, b);
- UNIT_ASSERT_VALUES_EQUAL(b, plain);
-
- Base64EncodeUrl(plain, a);
- UNIT_ASSERT_VALUES_EQUAL(a, encodedUrl);
-
- Base64Decode(a, b);
- UNIT_ASSERT_VALUES_EQUAL(b, plain);
-}
-
+
+ Base64Encode(plain, a);
+ UNIT_ASSERT_VALUES_EQUAL(a, encoded);
+
+ Base64Decode(a, b);
+ UNIT_ASSERT_VALUES_EQUAL(b, plain);
+
+ Base64EncodeUrl(plain, a);
+ UNIT_ASSERT_VALUES_EQUAL(a, encodedUrl);
+
+ Base64Decode(a, b);
+ UNIT_ASSERT_VALUES_EQUAL(b, plain);
+}
+
static void TestEncodeStrictDecodeIntoString(const TString& plain, const TString& encoded, const TString& encodedUrl) {
TString a, b;
@@ -204,11 +204,11 @@ Y_UNIT_TEST_SUITE(TBase64) {
}
Y_UNIT_TEST(TestIntoString) {
- {
+ {
TString str;
- for (size_t i = 0; i < 256; ++i)
- str += char(i);
-
+ for (size_t i = 0; i < 256; ++i)
+ str += char(i);
+
const TString base64 =
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJy"
"gpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q"
@@ -225,22 +225,22 @@ Y_UNIT_TEST_SUITE(TBase64) {
"oqOkpaanqKmqq6ytrq-wsbKztLW2t7i5uru8vb6_wMHCw8TFxsfIyc"
"rLzM3Oz9DR0tPU1dbX2Nna29zd3t_g4eLj5OXm5-jp6uvs7e7v8PHy"
"8_T19vf4-fr7_P3-_w,,";
-
- TestEncodeDecodeIntoString(str, base64, base64Url);
+
+ TestEncodeDecodeIntoString(str, base64, base64Url);
TestEncodeStrictDecodeIntoString(str, base64, base64Url);
- }
-
- {
+ }
+
+ {
const TString str = "http://yandex.ru:1234/request?param=value&lll=fff#fragment";
-
+
const TString base64 = "aHR0cDovL3lhbmRleC5ydToxMjM0L3JlcXVlc3Q/cGFyYW09dmFsdWUmbGxsPWZmZiNmcmFnbWVudA==";
const TString base64Url = "aHR0cDovL3lhbmRleC5ydToxMjM0L3JlcXVlc3Q_cGFyYW09dmFsdWUmbGxsPWZmZiNmcmFnbWVudA,,";
-
- TestEncodeDecodeIntoString(str, base64, base64Url);
+
+ TestEncodeDecodeIntoString(str, base64, base64Url);
TestEncodeStrictDecodeIntoString(str, base64, base64Url);
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(TestDecode) {
UNIT_ASSERT_EXCEPTION(Base64Decode("a"), yexception);
UNIT_ASSERT_EXCEPTION(Base64StrictDecode("a"), yexception);
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp
index 0744ae5640..85f4ac5d69 100644
--- a/library/cpp/string_utils/url/url.cpp
+++ b/library/cpp/string_utils/url/url.cpp
@@ -264,17 +264,17 @@ TStringBuf GetDomain(const TStringBuf host) 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);
+ size_t pos = host.size();
+ for (size_t i = 0; i < level; ++i) {
+ pos = host.rfind('.', pos);
if (pos == TString::npos)
- return host;
- }
- return host.SubStr(pos + 1);
-}
-
+ return host;
+ }
+ return host.SubStr(pos + 1);
+}
+
TStringBuf GetZone(const TStringBuf host) noexcept {
- return GetParentDomain(host, 1);
+ return GetParentDomain(host, 1);
}
TStringBuf CutWWWPrefix(const TStringBuf url) noexcept {
diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp
index 829fbe217f..1588013893 100644
--- a/library/cpp/string_utils/url/url_ut.cpp
+++ b/library/cpp/string_utils/url/url_ut.cpp
@@ -49,19 +49,19 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {
}
Y_UNIT_TEST(TestGetParentDomain) {
- UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("www.ya.ru", 0));
- UNIT_ASSERT_VALUES_EQUAL("ru", GetParentDomain("www.ya.ru", 1));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetParentDomain("www.ya.ru", 2));
- UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetParentDomain("www.ya.ru", 3));
- UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetParentDomain("www.ya.ru", 4));
- UNIT_ASSERT_VALUES_EQUAL("com", GetParentDomain("ya.com", 1));
- UNIT_ASSERT_VALUES_EQUAL("ya.com", GetParentDomain("ya.com", 2));
- UNIT_ASSERT_VALUES_EQUAL("RU", GetParentDomain("RU", 1));
- UNIT_ASSERT_VALUES_EQUAL("RU", GetParentDomain("RU", 2));
- UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("", 0));
- UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("", 1));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("www.ya.ru", 0));
+ UNIT_ASSERT_VALUES_EQUAL("ru", GetParentDomain("www.ya.ru", 1));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetParentDomain("www.ya.ru", 2));
+ UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetParentDomain("www.ya.ru", 3));
+ UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetParentDomain("www.ya.ru", 4));
+ UNIT_ASSERT_VALUES_EQUAL("com", GetParentDomain("ya.com", 1));
+ UNIT_ASSERT_VALUES_EQUAL("ya.com", GetParentDomain("ya.com", 2));
+ UNIT_ASSERT_VALUES_EQUAL("RU", GetParentDomain("RU", 1));
+ UNIT_ASSERT_VALUES_EQUAL("RU", GetParentDomain("RU", 2));
+ UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("", 0));
+ UNIT_ASSERT_VALUES_EQUAL("", GetParentDomain("", 1));
+ }
+
Y_UNIT_TEST(TestGetZone) {
UNIT_ASSERT_VALUES_EQUAL("ru", GetZone("www.ya.ru"));
UNIT_ASSERT_VALUES_EQUAL("com", GetZone("ya.com"));