aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authordobrokot <dobrokot@yandex-team.ru>2022-02-10 16:49:07 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:07 +0300
commit25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch)
treebd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /util/generic
parent1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff)
downloadydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/algorithm.h76
-rw-r--r--util/generic/algorithm_ut.cpp172
-rw-r--r--util/generic/cast.h2
-rw-r--r--util/generic/hash.h2
-rw-r--r--util/generic/map.h2
-rw-r--r--util/generic/mapfindptr.h40
-rw-r--r--util/generic/mapfindptr_ut.cpp10
-rw-r--r--util/generic/ptr.h14
-rw-r--r--util/generic/refcount.h4
-rw-r--r--util/generic/strbase.h12
-rw-r--r--util/generic/strbuf.h20
-rw-r--r--util/generic/strbuf_ut.cpp60
-rw-r--r--util/generic/string_ut.h24
13 files changed, 219 insertions, 219 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h
index badfb88993..cbfb41ff04 100644
--- a/util/generic/algorithm.h
+++ b/util/generic/algorithm.h
@@ -3,9 +3,9 @@
#include "is_in.h"
#include "utility.h"
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <util/generic/fwd.h>
-
+
#include <numeric>
#include <algorithm>
#include <iterator>
@@ -154,51 +154,51 @@ static inline auto FindIf(C&& c, P p) {
}
template <class I, class P>
-static inline bool AllOf(I f, I l, P pred) {
+static inline bool AllOf(I f, I l, P pred) {
return std::all_of(f, l, pred);
-}
-
+}
+
template <class C, class P>
-static inline bool AllOf(const C& c, P pred) {
+static inline bool AllOf(const C& c, P pred) {
using std::begin;
using std::end;
return AllOf(begin(c), end(c), pred);
-}
-
+}
+
template <class I, class P>
-static inline bool AnyOf(I f, I l, P pred) {
+static inline bool AnyOf(I f, I l, P pred) {
return std::any_of(f, l, pred);
-}
-
+}
+
template <class C, class P>
-static inline bool AnyOf(const C& c, P pred) {
+static inline bool AnyOf(const C& c, P pred) {
using std::begin;
using std::end;
return AnyOf(begin(c), end(c), pred);
-}
-
-// FindIfPtr - return NULL if not found. Works for arrays, containers, iterators
+}
+
+// FindIfPtr - return NULL if not found. Works for arrays, containers, iterators
template <class I, class P>
static inline auto FindIfPtr(I f, I l, P pred) -> decltype(&*f) {
- I found = FindIf(f, l, pred);
+ I found = FindIf(f, l, pred);
return (found != l) ? &*found : nullptr;
-}
-
+}
+
template <class C, class P>
static inline auto FindIfPtr(C&& c, P pred) {
using std::begin;
using std::end;
return FindIfPtr(begin(c), end(c), pred);
-}
-
-template <class C, class T>
+}
+
+template <class C, class T>
static inline size_t FindIndex(C&& c, const T& x) {
using std::begin;
using std::end;
auto it = Find(begin(c), end(c), x);
return it == end(c) ? NPOS : (it - begin(c));
-}
-
+}
+
template <class C, class P>
static inline size_t FindIndexIf(C&& c, P p) {
using std::begin;
@@ -207,17 +207,17 @@ static inline size_t FindIndexIf(C&& c, P p) {
return it == end(c) ? NPOS : (it - begin(c));
}
-//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange")
+//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange")
template <typename T>
inline bool EqualToOneOf(const T&) {
- return false;
-}
+ return false;
+}
template <typename T, typename U, typename... Other>
inline bool EqualToOneOf(const T& x, const U& y, const Other&... other) {
- return x == y || EqualToOneOf(x, other...);
-}
-
+ return x == y || EqualToOneOf(x, other...);
+}
+
template <typename T>
static inline size_t CountOf(const T&) {
return 0;
@@ -342,11 +342,11 @@ void Erase(C& c, const TValue& value) {
c.erase(std::remove(c.begin(), c.end(), value), c.end());
}
-template <class C, class P>
-void EraseIf(C& c, P p) {
+template <class C, class P>
+void EraseIf(C& c, P p) {
c.erase(std::remove_if(c.begin(), c.end(), p), c.end());
-}
-
+}
+
template <class C, class P>
void EraseNodesIf(C& c, P p) {
for (auto iter = c.begin(), last = c.end(); iter != last;) {
@@ -643,18 +643,18 @@ static inline auto Count(const TContainer& container, const TValue& value) {
return Count(std::cbegin(container), std::cend(container), value);
}
-template <class It, class P>
+template <class It, class P>
static inline auto CountIf(It first, It last, P p) {
return std::count_if(first, last, p);
-}
-
+}
+
template <class C, class P>
static inline auto CountIf(const C& c, P pred) {
using std::begin;
using std::end;
return CountIf(begin(c), end(c), pred);
-}
-
+}
+
template <class I1, class I2>
static inline std::pair<I1, I2> Mismatch(I1 b1, I1 e1, I2 b2) {
return std::mismatch(b1, e1, b2);
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp
index 8d732fcc0c..8db678f3cb 100644
--- a/util/generic/algorithm_ut.cpp
+++ b/util/generic/algorithm_ut.cpp
@@ -1,11 +1,11 @@
#include <library/cpp/testing/unittest/registar.h>
-
+
#include "algorithm.h"
#include "strbuf.h"
#include "string.h"
-
-static auto isOne = [](char c) { return c == '1'; };
-
+
+static auto isOne = [](char c) { return c == '1'; };
+
Y_UNIT_TEST_SUITE(TAlgorithm) {
Y_UNIT_TEST(AnyTest) {
UNIT_ASSERT(0 == AnyOf(TStringBuf("00"), isOne));
@@ -18,8 +18,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
UNIT_ASSERT(0 == AnyOf(array00, isOne));
const char array01[]{'0', '1'};
UNIT_ASSERT(1 == AnyOf(array01, isOne));
- }
-
+ }
+
Y_UNIT_TEST(AllOfTest) {
UNIT_ASSERT(0 == AllOf(TStringBuf("00"), isOne));
UNIT_ASSERT(0 == AllOf(TStringBuf("01"), isOne));
@@ -31,8 +31,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
UNIT_ASSERT(0 == AllOf(array01, isOne));
const char array11[]{'1', '1'};
UNIT_ASSERT(1 == AllOf(array11, isOne));
- }
-
+ }
+
Y_UNIT_TEST(CountIfTest) {
UNIT_ASSERT(3 == CountIf(TStringBuf("____1________1____1_______"), isOne));
UNIT_ASSERT(5 == CountIf(TStringBuf("1____1________1____1_______1"), isOne));
@@ -42,8 +42,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
const char array[] = "____1________1____1_______";
UNIT_ASSERT(3 == CountIf(array, isOne));
- }
-
+ }
+
Y_UNIT_TEST(CountTest) {
UNIT_ASSERT(3 == Count("____1________1____1_______", '1'));
UNIT_ASSERT(3 == Count(TStringBuf("____1________1____1_______"), '1'));
@@ -66,15 +66,15 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
private:
TStrokaNoCopy(const TStrokaNoCopy&);
void operator=(const TStrokaNoCopy&);
- };
-
+ };
+
Y_UNIT_TEST(CountOfTest) {
UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 2), 0);
UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 1), 1);
UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 5), 0);
UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 2), 1);
UNIT_ASSERT_VALUES_EQUAL(CountOf(3, 3, 3), 2);
-
+
// Checking comparison of different types.
UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'x', 'y', 'z'), 0);
UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2);
@@ -102,32 +102,32 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
}
Y_UNIT_TEST(EqualToOneOfTest) {
- UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2));
- UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2));
- UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2));
- UNIT_ASSERT(1 == EqualToOneOf(1, 1));
- UNIT_ASSERT(0 == EqualToOneOf(1, 2));
- UNIT_ASSERT(0 == EqualToOneOf(3));
-
- //test, that EqualToOneOf can compare different types, and don't copy objects:
- TStrokaNoCopy x("x");
- TStrokaNoCopy y("y");
- TStrokaNoCopy z("z");
+ UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2));
+ UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2));
+ UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2));
+ UNIT_ASSERT(1 == EqualToOneOf(1, 1));
+ UNIT_ASSERT(0 == EqualToOneOf(1, 2));
+ UNIT_ASSERT(0 == EqualToOneOf(3));
+
+ //test, that EqualToOneOf can compare different types, and don't copy objects:
+ TStrokaNoCopy x("x");
+ TStrokaNoCopy y("y");
+ TStrokaNoCopy z("z");
const char* px = "x";
const char* py = "y";
const char* pz = "z";
-
- UNIT_ASSERT(1 == EqualToOneOf(x, px, py));
- UNIT_ASSERT(1 == EqualToOneOf(y, px, py));
- UNIT_ASSERT(1 == EqualToOneOf(y, px, y));
- UNIT_ASSERT(1 == EqualToOneOf(y, x, py));
- UNIT_ASSERT(0 == EqualToOneOf(z, px, py));
- UNIT_ASSERT(1 == EqualToOneOf(px, x, y));
- UNIT_ASSERT(1 == EqualToOneOf(py, x, y));
- UNIT_ASSERT(0 == EqualToOneOf(pz, x, y));
- }
-
- template <class TTestConstPtr>
+
+ UNIT_ASSERT(1 == EqualToOneOf(x, px, py));
+ UNIT_ASSERT(1 == EqualToOneOf(y, px, py));
+ UNIT_ASSERT(1 == EqualToOneOf(y, px, y));
+ UNIT_ASSERT(1 == EqualToOneOf(y, x, py));
+ UNIT_ASSERT(0 == EqualToOneOf(z, px, py));
+ UNIT_ASSERT(1 == EqualToOneOf(px, x, y));
+ UNIT_ASSERT(1 == EqualToOneOf(py, x, y));
+ UNIT_ASSERT(0 == EqualToOneOf(pz, x, y));
+ }
+
+ template <class TTestConstPtr>
void TestFindPtrFoundValue(int j, TTestConstPtr root) {
if (j == 3) {
UNIT_ASSERT(root && *root == 3);
@@ -139,35 +139,35 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
}
template <class TTestConstPtr>
- void TestFindIfPtrFoundValue(int j, TTestConstPtr root) {
- if (j == 3) {
+ void TestFindIfPtrFoundValue(int j, TTestConstPtr root) {
+ if (j == 3) {
UNIT_ASSERT(root == nullptr);
- } else if (j == 4) {
- UNIT_ASSERT(root && *root == 2);
- } else {
- ythrow yexception() << "invalid param " << j;
- }
- }
-
+ } else if (j == 4) {
+ UNIT_ASSERT(root && *root == 2);
+ } else {
+ ythrow yexception() << "invalid param " << j;
+ }
+ }
+
struct TVectorNoCopy: std::vector<int> {
- public:
+ public:
TVectorNoCopy() = default;
- private:
- TVectorNoCopy(const TVectorNoCopy&);
- void operator=(const TVectorNoCopy&);
- };
-
+ private:
+ TVectorNoCopy(const TVectorNoCopy&);
+ void operator=(const TVectorNoCopy&);
+ };
+
Y_UNIT_TEST(FindPtrTest) {
- TVectorNoCopy v;
- v.push_back(1);
- v.push_back(2);
- v.push_back(3);
-
+ TVectorNoCopy v;
+ v.push_back(1);
+ v.push_back(2);
+ v.push_back(3);
+
int array[3] = {1, 2, 3};
const int array_const[3] = {1, 2, 3};
-
- //test (const, non-const) * (iterator, vector, array) * (found, not found) variants.
+
+ //test (const, non-const) * (iterator, vector, array) * (found, not found) variants.
// value '3' is in container, value '4' is not
for (int j = 3; j <= 4; ++j) {
TestFindPtrFoundValue<int*>(j, FindPtr(v, j));
@@ -190,40 +190,40 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
const int array_const[3] = {1, 2, 3};
//test (const, non-const) * (iterator, vector, array) * (found, not found) variants.
- // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3)
- for (int j = 3; j <= 4; ++j) {
+ // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3)
+ for (int j = 3; j <= 4; ++j) {
TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v, [j](int i) { return i * i == j; }));
TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v.begin(), v.end(), [j](int i) { return i * i == j; }));
const TVectorNoCopy& q = v;
TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q, [j](int i) { return i * i == j; }));
-
+
TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q.begin(), q.end(), [j](int i) { return i * i == j; }));
TestFindIfPtrFoundValue<int*>(j, FindIfPtr(array, [j](int i) { return i * i == j; }));
TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(array_const, [j](int i) { return i * i == j; }));
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(FindIndexTest) {
- TVectorNoCopy v;
- v.push_back(1);
- v.push_back(2);
- v.push_back(3);
-
- UNIT_ASSERT_EQUAL(0, FindIndex(v, 1));
- UNIT_ASSERT_EQUAL(1, FindIndex(v, 2));
- UNIT_ASSERT_EQUAL(2, FindIndex(v, 3));
- UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42));
-
+ TVectorNoCopy v;
+ v.push_back(1);
+ v.push_back(2);
+ v.push_back(3);
+
+ UNIT_ASSERT_EQUAL(0, FindIndex(v, 1));
+ UNIT_ASSERT_EQUAL(1, FindIndex(v, 2));
+ UNIT_ASSERT_EQUAL(2, FindIndex(v, 3));
+ UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42));
+
int array[3] = {1, 2, 3};
-
- UNIT_ASSERT_EQUAL(0, FindIndex(array, 1));
- UNIT_ASSERT_EQUAL(1, FindIndex(array, 2));
- UNIT_ASSERT_EQUAL(2, FindIndex(array, 3));
- UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42));
-
+
+ UNIT_ASSERT_EQUAL(0, FindIndex(array, 1));
+ UNIT_ASSERT_EQUAL(1, FindIndex(array, 2));
+ UNIT_ASSERT_EQUAL(2, FindIndex(array, 3));
+ UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42));
+
TVector<int> empty;
- UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0));
- }
+ UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0));
+ }
Y_UNIT_TEST(FindIndexIfTest) {
TVectorNoCopy v;
@@ -276,10 +276,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
Y_UNIT_TEST(EraseIfTest) {
TVector<int> data = {5, 4, 3, 2, 1, 0};
TVector<int> expected = {2, 1, 0};
- EraseIf(data, [](int i) { return i >= 3; });
- UNIT_ASSERT_EQUAL(data, expected);
- }
-
+ EraseIf(data, [](int i) { return i >= 3; });
+ UNIT_ASSERT_EQUAL(data, expected);
+ }
+
Y_UNIT_TEST(EraseNodesIfTest) {
TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}};
TMap<int, int> expectedMap{{1, 1}};
diff --git a/util/generic/cast.h b/util/generic/cast.h
index 0d4a41f385..268b79baf4 100644
--- a/util/generic/cast.h
+++ b/util/generic/cast.h
@@ -53,7 +53,7 @@ static inline T CheckedCast(F f) {
}
return static_cast<T>(f);
-#endif // USE_DEBUG_CHECKED_CAST
+#endif // USE_DEBUG_CHECKED_CAST
}
/*
diff --git a/util/generic/hash.h b/util/generic/hash.h
index e46db21fa9..1f2ae2ca38 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -1,7 +1,7 @@
#pragma once
#include "fwd.h"
-#include "mapfindptr.h"
+#include "mapfindptr.h"
#include <util/memory/alloc.h>
#include <util/system/type_name.h>
diff --git a/util/generic/map.h b/util/generic/map.h
index b5001b56c0..92e79ad9af 100644
--- a/util/generic/map.h
+++ b/util/generic/map.h
@@ -1,7 +1,7 @@
#pragma once
#include "fwd.h"
-#include "mapfindptr.h"
+#include "mapfindptr.h"
#include <util/str_stl.h>
#include <util/memory/alloc.h>
diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h
index bc10cac60f..fdacd9e997 100644
--- a/util/generic/mapfindptr.h
+++ b/util/generic/mapfindptr.h
@@ -1,41 +1,41 @@
-#pragma once
-
+#pragma once
+
#include <type_traits>
-/** MapFindPtr usage:
-
-if (T* value = MapFindPtr(myMap, someKey) {
- Cout << *value;
-}
-
-*/
-
+/** MapFindPtr usage:
+
+if (T* value = MapFindPtr(myMap, someKey) {
+ Cout << *value;
+}
+
+*/
+
template <class Map, class K>
inline auto MapFindPtr(Map& map, const K& key) {
auto i = map.find(key);
return (i == map.end() ? nullptr : &i->second);
-}
-
+}
+
template <class Map, class K>
inline auto MapFindPtr(const Map& map, const K& key) {
auto i = map.find(key);
return (i == map.end() ? nullptr : &i->second);
-}
-
+}
+
/** helper for THashMap/TMap */
template <class Derived>
-struct TMapOps {
+struct TMapOps {
template <class K>
inline auto FindPtr(const K& key) {
- return MapFindPtr(static_cast<Derived&>(*this), key);
- }
+ return MapFindPtr(static_cast<Derived&>(*this), key);
+ }
template <class K>
inline auto FindPtr(const K& key) const {
- return MapFindPtr(static_cast<const Derived&>(*this), key);
- }
+ return MapFindPtr(static_cast<const Derived&>(*this), key);
+ }
template <class K, class DefaultValue>
inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> {
@@ -57,4 +57,4 @@ struct TMapOps {
template <class K, class V>
inline const V& ValueRef(const K& key, V&& defaultValue) const = delete;
-};
+};
diff --git a/util/generic/mapfindptr_ut.cpp b/util/generic/mapfindptr_ut.cpp
index 613da7a96b..e78817425b 100644
--- a/util/generic/mapfindptr_ut.cpp
+++ b/util/generic/mapfindptr_ut.cpp
@@ -2,26 +2,26 @@
#include "hash.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <map>
#include "mapfindptr.h"
Y_UNIT_TEST_SUITE(TMapFindPtrTest) {
struct TTestMap: std::map<int, TString>, TMapOps<TTestMap> {};
-
+
Y_UNIT_TEST(TestDerivedClass) {
TTestMap a;
-
+
a[42] = "cat";
UNIT_ASSERT(a.FindPtr(42));
UNIT_ASSERT_EQUAL(*a.FindPtr(42), "cat");
UNIT_ASSERT_EQUAL(a.FindPtr(0), nullptr);
-
+
//test mutation
if (TString* p = a.FindPtr(42)) {
*p = "dog";
- }
+ }
UNIT_ASSERT(a.FindPtr(42));
UNIT_ASSERT_EQUAL(*a.FindPtr(42), "dog");
diff --git a/util/generic/ptr.h b/util/generic/ptr.h
index 19db0e3ec5..2af6603934 100644
--- a/util/generic/ptr.h
+++ b/util/generic/ptr.h
@@ -17,13 +17,13 @@ using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::
template <class T>
inline void AssertTypeComplete() {
- // If compiler triggers this error from destructor of your class with
- // smart pointer, then may be you should move the destructor definition
- // to the .cpp file, where type T have full definition.
- //
- // 'delete' called on pointer to incomplete type is
- // undefined behavior (missing destructor call/corrupted memory manager).
- // 'sizeof' is used to trigger compile-time error.
+ // If compiler triggers this error from destructor of your class with
+ // smart pointer, then may be you should move the destructor definition
+ // to the .cpp file, where type T have full definition.
+ //
+ // 'delete' called on pointer to incomplete type is
+ // undefined behavior (missing destructor call/corrupted memory manager).
+ // 'sizeof' is used to trigger compile-time error.
static_assert(sizeof(T) != 0, "Type must be complete");
}
diff --git a/util/generic/refcount.h b/util/generic/refcount.h
index 966e853b77..3f37e76cd7 100644
--- a/util/generic/refcount.h
+++ b/util/generic/refcount.h
@@ -63,9 +63,9 @@ protected:
};
#if defined(SIMPLE_COUNTER_THREAD_CHECK)
-
+
#include <util/system/thread.i>
-
+
class TCheckPolicy {
public:
inline TCheckPolicy() {
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index ab39fc7537..eed24a1615 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -475,18 +475,18 @@ public:
return AsStringView().rfind(str.data(), pos, str.size());
}
- //~~~~Contains~~~~
+ //~~~~Contains~~~~
/**
* @returns Whether this string contains the provided substring.
*/
inline bool Contains(const TStringView s, size_t pos = 0) const noexcept {
return !s.length() || find(s, pos) != npos;
- }
-
+ }
+
inline bool Contains(TChar c, size_t pos = 0) const noexcept {
- return find(c, pos) != npos;
- }
-
+ return find(c, pos) != npos;
+ }
+
inline void Contains(std::enable_if<std::is_unsigned<TCharType>::value, char> c, size_t pos = 0) const noexcept {
return find(ui8(c), pos) != npos;
}
diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h
index 70b9360d58..ab463595a9 100644
--- a/util/generic/strbuf.h
+++ b/util/generic/strbuf.h
@@ -321,19 +321,19 @@ public:
inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept {
if (this->StartsWith(prefix)) {
result = Tail(prefix.size());
- return true;
- }
- return false;
- }
-
+ return true;
+ }
+ return false;
+ }
+
inline bool BeforeSuffix(const TdSelf& suffix, TdSelf& result) const noexcept {
if (this->EndsWith(suffix)) {
result = Head(size() - suffix.size());
- return true;
- }
- return false;
- }
-
+ return true;
+ }
+ return false;
+ }
+
// returns true if string started with `prefix`, false otherwise
inline bool SkipPrefix(const TdSelf& prefix) noexcept {
return AfterPrefix(prefix, *this);
diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp
index 69cde785af..195b7b1b5d 100644
--- a/util/generic/strbuf_ut.cpp
+++ b/util/generic/strbuf_ut.cpp
@@ -82,19 +82,19 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
}
Y_UNIT_TEST(TestAfterPrefix) {
- TStringBuf str("cat_dog");
-
- TStringBuf r = "the_same";
- UNIT_ASSERT(!str.AfterPrefix("dog", r));
- UNIT_ASSERT_EQUAL(r, "the_same");
- UNIT_ASSERT(str.AfterPrefix("cat_", r));
- UNIT_ASSERT_EQUAL(r, "dog");
-
- //example:
- str = "http://ya.ru";
- if (str.AfterPrefix("http://", r)) {
- UNIT_ASSERT_EQUAL(r, "ya.ru");
- }
+ TStringBuf str("cat_dog");
+
+ TStringBuf r = "the_same";
+ UNIT_ASSERT(!str.AfterPrefix("dog", r));
+ UNIT_ASSERT_EQUAL(r, "the_same");
+ UNIT_ASSERT(str.AfterPrefix("cat_", r));
+ UNIT_ASSERT_EQUAL(r, "dog");
+
+ //example:
+ str = "http://ya.ru";
+ if (str.AfterPrefix("http://", r)) {
+ UNIT_ASSERT_EQUAL(r, "ya.ru");
+ }
// SkipPrefix()
TStringBuf a = "abcdef";
@@ -106,22 +106,22 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
UNIT_ASSERT(a.SkipPrefix("def") && a == "");
UNIT_ASSERT(a.SkipPrefix("") && a == "");
UNIT_ASSERT(!a.SkipPrefix("def") && a == "");
- }
-
+ }
+
Y_UNIT_TEST(TestBeforeSuffix) {
- TStringBuf str("cat_dog");
-
- TStringBuf r = "the_same";
- UNIT_ASSERT(!str.BeforeSuffix("cat", r));
- UNIT_ASSERT_EQUAL(r, "the_same");
- UNIT_ASSERT(str.BeforeSuffix("_dog", r));
- UNIT_ASSERT_EQUAL(r, "cat");
-
- //example:
- str = "maps.yandex.com.ua";
- if (str.BeforeSuffix(".ru", r)) {
- UNIT_ASSERT_EQUAL(r, "maps.yandex");
- }
+ TStringBuf str("cat_dog");
+
+ TStringBuf r = "the_same";
+ UNIT_ASSERT(!str.BeforeSuffix("cat", r));
+ UNIT_ASSERT_EQUAL(r, "the_same");
+ UNIT_ASSERT(str.BeforeSuffix("_dog", r));
+ UNIT_ASSERT_EQUAL(r, "cat");
+
+ //example:
+ str = "maps.yandex.com.ua";
+ if (str.BeforeSuffix(".ru", r)) {
+ UNIT_ASSERT_EQUAL(r, "maps.yandex");
+ }
// ChopSuffix()
TStringBuf a = "abcdef";
@@ -133,8 +133,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
UNIT_ASSERT(a.ChopSuffix("abc") && a == "");
UNIT_ASSERT(a.ChopSuffix("") && a == "");
UNIT_ASSERT(!a.ChopSuffix("abc") && a == "");
- }
-
+ }
+
Y_UNIT_TEST(TestEmpty) {
UNIT_ASSERT(TStringBuf().empty());
UNIT_ASSERT(!TStringBuf("q").empty());
diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h
index 44bb10bdeb..5ac2cef731 100644
--- a/util/generic/string_ut.h
+++ b/util/generic/string_ut.h
@@ -725,20 +725,20 @@ public:
void TestContains() {
const TStringType s(Data._0123456_12345());
const TStringType s2(Data._0123());
-
- UNIT_ASSERT(s.Contains(Data._345()));
- UNIT_ASSERT(!s2.Contains(Data._345()));
-
- UNIT_ASSERT(s.Contains('1'));
- UNIT_ASSERT(!s.Contains('*'));
-
+
+ UNIT_ASSERT(s.Contains(Data._345()));
+ UNIT_ASSERT(!s2.Contains(Data._345()));
+
+ UNIT_ASSERT(s.Contains('1'));
+ UNIT_ASSERT(!s.Contains('*'));
+
TStringType empty;
- UNIT_ASSERT(s.Contains(empty));
- UNIT_ASSERT(!empty.Contains(s));
- UNIT_ASSERT(empty.Contains(empty));
+ UNIT_ASSERT(s.Contains(empty));
+ UNIT_ASSERT(!empty.Contains(s));
+ UNIT_ASSERT(empty.Contains(empty));
UNIT_ASSERT(s.Contains(empty, s.length()));
- }
-
+ }
+
// Operators
void TestOperators() {