diff options
author | tobo <tobo@yandex-team.ru> | 2022-02-10 16:47:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:27 +0300 |
commit | 7fe839092527589b38f014d854c51565b3c1adfa (patch) | |
tree | 309e97022d3530044b712b8f71318c78faf7856e /util/string | |
parent | d0d68c395c10da4cb56a1c845504570a04d7893e (diff) | |
download | ydb-7fe839092527589b38f014d854c51565b3c1adfa.tar.gz |
Restoring authorship annotation for <tobo@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/ascii_ut.cpp | 2 | ||||
-rw-r--r-- | util/string/cast.cpp | 86 | ||||
-rw-r--r-- | util/string/cast_ut.cpp | 14 | ||||
-rw-r--r-- | util/string/escape_ut.cpp | 24 | ||||
-rw-r--r-- | util/string/hex.cpp | 2 | ||||
-rw-r--r-- | util/string/join_ut.cpp | 2 | ||||
-rw-r--r-- | util/string/split.h | 6 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 2 | ||||
-rw-r--r-- | util/string/strip_ut.cpp | 8 | ||||
-rw-r--r-- | util/string/type.cpp | 68 | ||||
-rw-r--r-- | util/string/type.h | 2 | ||||
-rw-r--r-- | util/string/type_ut.cpp | 40 | ||||
-rw-r--r-- | util/string/util.h | 10 |
13 files changed, 133 insertions, 133 deletions
diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 89069fee50..d4a31f61b6 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -64,7 +64,7 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { Y_UNIT_TEST(CompareTest) { UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", "qQq")); - UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", TStringBuf("qQq"))); + UNIT_ASSERT(AsciiEqualsIgnoreCase("qqq", TStringBuf("qQq"))); TString qq = "qq"; TString qQ = "qQ"; UNIT_ASSERT(AsciiEqualsIgnoreCase(qq, qQ)); diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..2a4f697042 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -6,7 +6,7 @@ #include <cstdio> #include <string> -#include <cmath> +#include <cmath> #include <util/string/type.h> #include <util/string/cast.h> @@ -31,12 +31,12 @@ using double_conversion::StringToDoubleConverter; */ namespace { - constexpr char IntToChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + constexpr char IntToChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; static_assert(Y_ARRAY_SIZE(IntToChar) == 16, "expect Y_ARRAY_SIZE(IntToChar) == 16"); // clang-format off - constexpr int LetterToIntMap[] = { + constexpr int LetterToIntMap[] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, @@ -52,17 +52,17 @@ namespace { // clang-format on template <class T> - std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T value) noexcept { + std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T value) noexcept { return std::make_unsigned_t<T>(-(value + 1)) + std::make_unsigned_t<T>(1); } template <class T> - std::enable_if_t<std::is_unsigned<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T) noexcept { + std::enable_if_t<std::is_unsigned<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T) noexcept { Y_UNREACHABLE(); } template <class T> - std::make_signed_t<T> NegatePositiveSigned(T value) noexcept { + std::make_signed_t<T> NegatePositiveSigned(T value) noexcept { return value > 0 ? (-std::make_signed_t<T>(value - 1) - 1) : 0; } @@ -72,18 +72,18 @@ namespace { static_assert(std::is_unsigned<T>::value, "TBasicIntFormatter can only handle unsigned integers."); static inline size_t Format(T value, TChar* buf, size_t len) { - Y_ENSURE(len, TStringBuf("zero length")); + Y_ENSURE(len, TStringBuf("zero length")); TChar* tmp = buf; do { - // divide only once, do not use mod - const T nextVal = static_cast<T>(value / base); - *tmp++ = IntToChar[base == 2 || base == 4 || base == 8 || base == 16 ? value & (base - 1) : value - base * nextVal]; - value = nextVal; + // divide only once, do not use mod + const T nextVal = static_cast<T>(value / base); + *tmp++ = IntToChar[base == 2 || base == 4 || base == 8 || base == 16 ? value & (base - 1) : value - base * nextVal]; + value = nextVal; } while (value && --len); - Y_ENSURE(!value, TStringBuf("not enough room in buffer")); + Y_ENSURE(!value, TStringBuf("not enough room in buffer")); const size_t result = tmp - buf; @@ -111,7 +111,7 @@ namespace { using TUFmt = TBasicIntFormatter<std::make_unsigned_t<T>, base, TChar>; if (std::is_signed<T>::value && value < 0) { - Y_ENSURE(len >= 2, TStringBuf("not enough room in buffer")); + Y_ENSURE(len >= 2, TStringBuf("not enough room in buffer")); *buf = '-'; @@ -126,15 +126,15 @@ namespace { struct TFltModifiers; template <class T, int base, class TChar> - Y_NO_INLINE size_t FormatInt(T value, TChar* buf, size_t len) { + Y_NO_INLINE size_t FormatInt(T value, TChar* buf, size_t len) { return TIntFormatter<T, base, TChar>::Format(value, buf, len); } template <class T> - inline size_t FormatFlt(T t, char* buf, size_t len) { + inline size_t FormatFlt(T t, char* buf, size_t len) { const int ret = snprintf(buf, len, TFltModifiers<T>::ModifierWrite, t); - Y_ENSURE(ret >= 0 && (size_t)ret <= len, TStringBuf("cannot format float")); + Y_ENSURE(ret >= 0 && (size_t)ret <= len, TStringBuf("cannot format float")); return (size_t)ret; } @@ -148,7 +148,7 @@ namespace { PS_OVERFLOW, }; - constexpr ui8 SAFE_LENS[4][17] = { + constexpr ui8 SAFE_LENS[4][17] = { {0, 0, 7, 5, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1}, {0, 0, 15, 10, 7, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3}, {0, 0, 31, 20, 15, 13, 12, 11, 10, 10, 9, 9, 8, 8, 8, 8, 7}, @@ -160,7 +160,7 @@ namespace { } template <unsigned BASE, class TChar, class T> - inline std::enable_if_t<(BASE > 10), bool> CharToDigit(TChar c, T* digit) noexcept { + inline std::enable_if_t<(BASE > 10), bool> CharToDigit(TChar c, T* digit) noexcept { unsigned uc = c; if (uc >= Y_ARRAY_SIZE(LetterToIntMap)) { @@ -173,7 +173,7 @@ namespace { } template <unsigned BASE, class TChar, class T> - inline std::enable_if_t<(BASE <= 10), bool> CharToDigit(TChar c, T* digit) noexcept { + inline std::enable_if_t<(BASE <= 10), bool> CharToDigit(TChar c, T* digit) noexcept { return (c >= '0') && ((*digit = (c - '0')) < BASE); } @@ -284,7 +284,7 @@ namespace { return PS_EMPTY_STRING; } - bool negative = false; + bool negative = false; TUnsigned max; if (*pos == '+') { pos++; @@ -329,22 +329,22 @@ namespace { switch (status) { case PS_EMPTY_STRING: - ythrow TFromStringException() << TStringBuf("Cannot parse empty string as number. "); + ythrow TFromStringException() << TStringBuf("Cannot parse empty string as number. "); case PS_PLUS_STRING: - ythrow TFromStringException() << TStringBuf("Cannot parse string \"+\" as number. "); + ythrow TFromStringException() << TStringBuf("Cannot parse string \"+\" as number. "); case PS_MINUS_STRING: - ythrow TFromStringException() << TStringBuf("Cannot parse string \"-\" as number. "); + ythrow TFromStringException() << TStringBuf("Cannot parse string \"-\" as number. "); case PS_BAD_SYMBOL: - ythrow TFromStringException() << TStringBuf("Unexpected symbol \"") << EscapeC(*pos) << TStringBuf("\" at pos ") << (pos - data) << TStringBuf(" in string ") << TStringType(data, len).Quote() << TStringBuf(". "); + ythrow TFromStringException() << TStringBuf("Unexpected symbol \"") << EscapeC(*pos) << TStringBuf("\" at pos ") << (pos - data) << TStringBuf(" in string ") << TStringType(data, len).Quote() << TStringBuf(". "); case PS_OVERFLOW: - ythrow TFromStringException() << TStringBuf("Integer overflow in string ") << TStringType(data, len).Quote() << TStringBuf(". "); + ythrow TFromStringException() << TStringBuf("Integer overflow in string ") << TStringType(data, len).Quote() << TStringBuf(". "); default: - ythrow yexception() << TStringBuf("Unknown error code in string converter. "); + ythrow yexception() << TStringBuf("Unknown error code in string converter. "); } } template <typename T, typename TUnsigned, int base, typename TChar> - Y_NO_INLINE T ParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds) { + Y_NO_INLINE T ParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds) { T result; const TChar* pos = data; EParseStatus status = TIntParser<T, base, TChar>::Parse(&pos, pos + len, bounds, &result); @@ -357,12 +357,12 @@ namespace { } template <typename T, typename TUnsigned, int base, typename TChar> - Y_NO_INLINE bool TryParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds, T* result) { + Y_NO_INLINE bool TryParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds, T* result) { return TIntParser<T, base, TChar>::Parse(&data, data + len, bounds, result) == PS_OK; } template <class T> - inline T ParseFlt(const char* data, size_t len) { + inline T ParseFlt(const char* data, size_t len) { /* * TODO */ @@ -384,7 +384,7 @@ namespace { return ret; } - ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")"); + ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")"); } #define DEF_FLT_MOD(type, modifierWrite, modifierRead) \ @@ -405,16 +405,16 @@ namespace { * sure they go into binary as actual values and there is no associated * initialization code. * */ - constexpr TBounds<ui64> bSBounds = {static_cast<ui64>(SCHAR_MAX), static_cast<ui64>(UCHAR_MAX - SCHAR_MAX)}; - constexpr TBounds<ui64> bUBounds = {static_cast<ui64>(UCHAR_MAX), 0}; - constexpr TBounds<ui64> sSBounds = {static_cast<ui64>(SHRT_MAX), static_cast<ui64>(USHRT_MAX - SHRT_MAX)}; - constexpr TBounds<ui64> sUBounds = {static_cast<ui64>(USHRT_MAX), 0}; - constexpr TBounds<ui64> iSBounds = {static_cast<ui64>(INT_MAX), static_cast<ui64>(UINT_MAX - INT_MAX)}; - constexpr TBounds<ui64> iUBounds = {static_cast<ui64>(UINT_MAX), 0}; - constexpr TBounds<ui64> lSBounds = {static_cast<ui64>(LONG_MAX), static_cast<ui64>(ULONG_MAX - LONG_MAX)}; - constexpr TBounds<ui64> lUBounds = {static_cast<ui64>(ULONG_MAX), 0}; - constexpr TBounds<ui64> llSBounds = {static_cast<ui64>(LLONG_MAX), static_cast<ui64>(ULLONG_MAX - LLONG_MAX)}; - constexpr TBounds<ui64> llUBounds = {static_cast<ui64>(ULLONG_MAX), 0}; + constexpr TBounds<ui64> bSBounds = {static_cast<ui64>(SCHAR_MAX), static_cast<ui64>(UCHAR_MAX - SCHAR_MAX)}; + constexpr TBounds<ui64> bUBounds = {static_cast<ui64>(UCHAR_MAX), 0}; + constexpr TBounds<ui64> sSBounds = {static_cast<ui64>(SHRT_MAX), static_cast<ui64>(USHRT_MAX - SHRT_MAX)}; + constexpr TBounds<ui64> sUBounds = {static_cast<ui64>(USHRT_MAX), 0}; + constexpr TBounds<ui64> iSBounds = {static_cast<ui64>(INT_MAX), static_cast<ui64>(UINT_MAX - INT_MAX)}; + constexpr TBounds<ui64> iUBounds = {static_cast<ui64>(UINT_MAX), 0}; + constexpr TBounds<ui64> lSBounds = {static_cast<ui64>(LONG_MAX), static_cast<ui64>(ULONG_MAX - LONG_MAX)}; + constexpr TBounds<ui64> lUBounds = {static_cast<ui64>(ULONG_MAX), 0}; + constexpr TBounds<ui64> llSBounds = {static_cast<ui64>(LLONG_MAX), static_cast<ui64>(ULLONG_MAX - LLONG_MAX)}; + constexpr TBounds<ui64> llUBounds = {static_cast<ui64>(ULLONG_MAX), 0}; } #define DEF_INT_SPEC_II(TYPE, ITYPE, BASE) \ @@ -474,7 +474,7 @@ DEF_FLT_SPEC(long double) template <> size_t ToStringImpl<bool>(bool t, char* buf, size_t len) { - Y_ENSURE(len, TStringBuf("zero length")); + Y_ENSURE(len, TStringBuf("zero length")); *buf = t ? '1' : '0'; return 1; } @@ -510,7 +510,7 @@ bool FromStringImpl<bool>(const char* data, size_t len) { bool result; if (!TryFromStringImpl<bool>(data, len, result)) { - ythrow TFromStringException() << TStringBuf("Cannot parse bool(") << TStringBuf(data, len) << TStringBuf("). "); + ythrow TFromStringException() << TStringBuf("Cannot parse bool(") << TStringBuf(data, len) << TStringBuf("). "); } return result; @@ -683,7 +683,7 @@ template <> double FromStringImpl<double>(const char* data, size_t len) { double d = 0.0; if (!TryFromStringImpl(data, len, d)) { - ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")"); + ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")"); } return d; } diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..1a1d6c5d91 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -282,10 +282,10 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::quiet_NaN()), "nan"); UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::infinity()), "inf"); - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<double>::infinity()), "-inf"); - - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::quiet_NaN()), "nan"); - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::infinity()), "inf"); + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<double>::infinity()), "-inf"); + + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::quiet_NaN()), "nan"); + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::infinity()), "inf"); UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<float>::infinity()), "-inf"); } @@ -452,7 +452,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { Y_UNIT_TEST(TestAutoDetectType) { UNIT_ASSERT_DOUBLES_EQUAL((float)FromString("0.0001"), 0.0001, EPS); UNIT_ASSERT_DOUBLES_EQUAL((double)FromString("0.0015", sizeof("0.0015") - 2), 0.001, EPS); - UNIT_ASSERT_DOUBLES_EQUAL((long double)FromString(TStringBuf("0.0001")), 0.0001, EPS); + UNIT_ASSERT_DOUBLES_EQUAL((long double)FromString(TStringBuf("0.0001")), 0.0001, EPS); UNIT_ASSERT_DOUBLES_EQUAL((float)FromString(TString("10E-5")), 10E-5, EPS); UNIT_ASSERT_VALUES_EQUAL((bool)FromString("da"), true); UNIT_ASSERT_VALUES_EQUAL((bool)FromString("no"), false); @@ -512,13 +512,13 @@ Y_UNIT_TEST_SUITE(TCastTest) { Y_UNIT_TEST(TryStringBuf) { { - constexpr TStringBuf hello = "hello"; + constexpr TStringBuf hello = "hello"; TStringBuf out; UNIT_ASSERT(TryFromString(hello, out)); UNIT_ASSERT_VALUES_EQUAL(hello, out); } { - constexpr TStringBuf empty = ""; + constexpr TStringBuf empty = ""; TStringBuf out; UNIT_ASSERT(TryFromString(empty, out)); UNIT_ASSERT_VALUES_EQUAL(empty, out); diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp index cd38ecffd3..68513df10c 100644 --- a/util/string/escape_ut.cpp +++ b/util/string/escape_ut.cpp @@ -5,8 +5,8 @@ #include <util/generic/string.h> #include <util/charset/wide.h> -using namespace std::string_view_literals; - +using namespace std::string_view_literals; + namespace { struct TExample { TString Expected; @@ -22,11 +22,11 @@ namespace { static const TExample CommonTestData[] = { // Should be valid UTF-8. - {"http://ya.ru/", "http://ya.ru/"}, - {"http://ya.ru/\\x17\\n", "http://ya.ru/\x17\n"}, + {"http://ya.ru/", "http://ya.ru/"}, + {"http://ya.ru/\\x17\\n", "http://ya.ru/\x17\n"}, - {"http://ya.ru/\\0", "http://ya.ru/\0"sv}, - {"http://ya.ru/\\0\\0", "http://ya.ru/\0\0"sv}, + {"http://ya.ru/\\0", "http://ya.ru/\0"sv}, + {"http://ya.ru/\\0\\0", "http://ya.ru/\0\0"sv}, {"http://ya.ru/\\0\\0000", "http://ya.ru/\0\0" "0"sv}, {"http://ya.ru/\\0\\0001", "http://ya.ru/\0\x00" @@ -37,13 +37,13 @@ static const TExample CommonTestData[] = { {R"(\2\4\689)", "\2\4\6" "89"sv}, // \6 -> \6 because next char '8' is not "octal" - {R"(\"Hello\", Alice said.)", "\"Hello\", Alice said."}, - {"Slash\\\\dash!", "Slash\\dash!"}, - {R"(There\nare\r\nnewlines.)", "There\nare\r\nnewlines."}, - {"There\\tare\\ttabs.", "There\tare\ttabs."}, + {R"(\"Hello\", Alice said.)", "\"Hello\", Alice said."}, + {"Slash\\\\dash!", "Slash\\dash!"}, + {R"(There\nare\r\nnewlines.)", "There\nare\r\nnewlines."}, + {"There\\tare\\ttabs.", "There\tare\ttabs."}, - {"There are questions \\x3F\\x3F?", "There are questions ???"}, - {"There are questions \\x3F?", "There are questions ??"}, + {"There are questions \\x3F\\x3F?", "There are questions ???"}, + {"There are questions \\x3F?", "There are questions ??"}, }; Y_UNIT_TEST_SUITE(TEscapeCTest) { diff --git a/util/string/hex.cpp b/util/string/hex.cpp index 667397987f..4d5ea72e7d 100644 --- a/util/string/hex.cpp +++ b/util/string/hex.cpp @@ -32,7 +32,7 @@ char* HexEncode(const void* in, size_t len, char* out) { void* HexDecode(const void* in, size_t len, void* ptr) { const char* b = (const char*)in; const char* e = b + len; - Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); + Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); char* out = (char*)ptr; diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp index 3ed2b2459c..f23d2c0440 100644 --- a/util/string/join_ut.cpp +++ b/util/string/join_ut.cpp @@ -19,7 +19,7 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(Join(", ", 10, 11.1, "foobar"), "10, 11.1, foobar"); UNIT_ASSERT_EQUAL(Join(", ", 10, 11.1, TString("foobar")), "10, 11.1, foobar"); - UNIT_ASSERT_EQUAL(Join('#', 0, "a", "foobar", -1.4, TStringBuf("aaa")), "0#a#foobar#-1.4#aaa"); + UNIT_ASSERT_EQUAL(Join('#', 0, "a", "foobar", -1.4, TStringBuf("aaa")), "0#a#foobar#-1.4#aaa"); UNIT_ASSERT_EQUAL(Join("", "", ""), ""); UNIT_ASSERT_EQUAL(Join("", "a", "b", "c"), "abc"); UNIT_ASSERT_EQUAL(Join("", "a", "b", "", "c"), "abc"); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..401d75bdd9 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -427,7 +427,7 @@ inline size_t Split(const TStringBuf s, const TSetDelimiter<const char>& delim, template <class P, class D> void GetNext(TStringBuf& s, D delim, P& param) { TStringBuf next = s.NextTok(delim); - Y_ENSURE(next.IsInited(), TStringBuf("Split: number of fields less than number of Split output arguments")); + Y_ENSURE(next.IsInited(), TStringBuf("Split: number of fields less than number of Split output arguments")); param = FromString<P>(next); } @@ -442,12 +442,12 @@ void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { } // example: -// Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); +// Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); template <class D, class P1, class P2> void Split(TStringBuf s, D delim, P1& p1, P2& p2) { GetNext(s, delim, p1); GetNext(s, delim, p2); - Y_ENSURE(!s.IsInited(), TStringBuf("Split: number of fields more than number of Split output arguments")); + Y_ENSURE(!s.IsInited(), TStringBuf("Split: number of fields more than number of Split output arguments")); } template <class D, class P1, class P2, class... Other> diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..7f4c0d6d23 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -648,7 +648,7 @@ Y_UNIT_TEST_SUITE(StringSplitter) { TVector<TString> actual1 = {"another", "one,", "and", "another", "one"}; num = 0; - for (TStringBuf elem : StringSplitter(TStringBuf("another one, and \n\n another one")).SplitBySet(" \n").SkipEmpty()) { + for (TStringBuf elem : StringSplitter(TStringBuf("another one, and \n\n another one")).SplitBySet(" \n").SkipEmpty()) { UNIT_ASSERT_VALUES_EQUAL(elem, actual1[num++]); } diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index d1029d1498..84451b467c 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -94,15 +94,15 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { } Y_UNIT_TEST(TestWtrokaStrip) { - UNIT_ASSERT_EQUAL(StripString(TWtringBuf(u" abc ")), u"abc"); - UNIT_ASSERT_EQUAL(StripStringLeft(TWtringBuf(u" abc ")), u"abc "); - UNIT_ASSERT_EQUAL(StripStringRight(TWtringBuf(u" abc ")), u" abc"); + UNIT_ASSERT_EQUAL(StripString(TWtringBuf(u" abc ")), u"abc"); + UNIT_ASSERT_EQUAL(StripStringLeft(TWtringBuf(u" abc ")), u"abc "); + UNIT_ASSERT_EQUAL(StripStringRight(TWtringBuf(u" abc ")), u" abc"); } Y_UNIT_TEST(TestWtrokaCustomStrip) { UNIT_ASSERT_EQUAL( StripString( - TWtringBuf(u"/abc/"), + TWtringBuf(u"/abc/"), EqualsStripAdapter(u'/')), u"abc"); } diff --git a/util/string/type.cpp b/util/string/type.cpp index 49671c02c2..3fbc547fc6 100644 --- a/util/string/type.cpp +++ b/util/string/type.cpp @@ -17,38 +17,38 @@ bool IsSpace(const char* s, size_t len) noexcept { template <typename TStringType> static bool IsNumberT(const TStringType& s) noexcept { - if (s.empty()) { - return false; - } - + if (s.empty()) { + return false; + } + return std::all_of(s.begin(), s.end(), IsAsciiDigit<typename TStringType::value_type>); -} - +} + bool IsNumber(const TStringBuf s) noexcept { - return IsNumberT(s); -} - + return IsNumberT(s); +} + bool IsNumber(const TWtringBuf s) noexcept { - return IsNumberT(s); -} - + return IsNumberT(s); +} + template <typename TStringType> static bool IsHexNumberT(const TStringType& s) noexcept { - if (s.empty()) { + if (s.empty()) { return false; - } + } return std::all_of(s.begin(), s.end(), IsAsciiHex<typename TStringType::value_type>); } bool IsHexNumber(const TStringBuf s) noexcept { - return IsHexNumberT(s); -} - + return IsHexNumberT(s); +} + bool IsHexNumber(const TWtringBuf s) noexcept { - return IsHexNumberT(s); -} - + return IsHexNumberT(s); +} + namespace { template <size_t N> bool IsCaseInsensitiveAnyOf(TStringBuf str, const std::array<TStringBuf, N>& options) { @@ -63,24 +63,24 @@ namespace { bool IsTrue(const TStringBuf v) noexcept { static constexpr std::array<TStringBuf, 7> trueOptions{ - "true", - "t", - "yes", - "y", - "on", - "1", - "da"}; + "true", + "t", + "yes", + "y", + "on", + "1", + "da"}; return IsCaseInsensitiveAnyOf(v, trueOptions); } bool IsFalse(const TStringBuf v) noexcept { static constexpr std::array<TStringBuf, 7> falseOptions{ - "false", - "f", - "no", - "n", - "off", - "0", - "net"}; + "false", + "f", + "no", + "n", + "off", + "0", + "net"}; return IsCaseInsensitiveAnyOf(v, falseOptions); } diff --git a/util/string/type.h b/util/string/type.h index d6cb29ea58..a868cc265a 100644 --- a/util/string/type.h +++ b/util/string/type.h @@ -18,7 +18,7 @@ Y_PURE_FUNCTION bool IsNumber(const TWtringBuf s) noexcept; Y_PURE_FUNCTION bool IsHexNumber(const TStringBuf s) noexcept; Y_PURE_FUNCTION bool IsHexNumber(const TWtringBuf s) noexcept; - + /* Tests if the given string is case insensitive equal to one of: * - "true", * - "t", diff --git a/util/string/type_ut.cpp b/util/string/type_ut.cpp index 03e7af62bd..d41b7edb37 100644 --- a/util/string/type_ut.cpp +++ b/util/string/type_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/charset/wide.h> - +#include <util/charset/wide.h> + Y_UNIT_TEST_SUITE(TStringClassify) { Y_UNIT_TEST(TestIsSpace) { UNIT_ASSERT_EQUAL(IsSpace(" "), true); @@ -38,32 +38,32 @@ Y_UNIT_TEST_SUITE(TStringClassify) { UNIT_ASSERT(!IsFalse("fa")); UNIT_ASSERT(!IsFalse("foobar")); } - + Y_UNIT_TEST(TestIsNumber) { - UNIT_ASSERT(IsNumber("0")); - UNIT_ASSERT(IsNumber("12345678901234567890")); - UNIT_ASSERT(!IsNumber("1234567890a")); - UNIT_ASSERT(!IsNumber("12345xx67890a")); - UNIT_ASSERT(!IsNumber("foobar")); + UNIT_ASSERT(IsNumber("0")); + UNIT_ASSERT(IsNumber("12345678901234567890")); + UNIT_ASSERT(!IsNumber("1234567890a")); + UNIT_ASSERT(!IsNumber("12345xx67890a")); + UNIT_ASSERT(!IsNumber("foobar")); UNIT_ASSERT(!IsNumber("")); - + UNIT_ASSERT(IsNumber(u"0")); UNIT_ASSERT(IsNumber(u"12345678901234567890")); UNIT_ASSERT(!IsNumber(u"1234567890a")); UNIT_ASSERT(!IsNumber(u"12345xx67890a")); UNIT_ASSERT(!IsNumber(u"foobar")); - } - + } + Y_UNIT_TEST(TestIsHexNumber) { - UNIT_ASSERT(IsHexNumber("0")); - UNIT_ASSERT(IsHexNumber("aaaadddAAAAA")); - UNIT_ASSERT(IsHexNumber("0123456789ABCDEFabcdef")); - UNIT_ASSERT(IsHexNumber("12345678901234567890")); - UNIT_ASSERT(IsHexNumber("1234567890a")); - UNIT_ASSERT(!IsHexNumber("12345xx67890a")); - UNIT_ASSERT(!IsHexNumber("foobar")); + UNIT_ASSERT(IsHexNumber("0")); + UNIT_ASSERT(IsHexNumber("aaaadddAAAAA")); + UNIT_ASSERT(IsHexNumber("0123456789ABCDEFabcdef")); + UNIT_ASSERT(IsHexNumber("12345678901234567890")); + UNIT_ASSERT(IsHexNumber("1234567890a")); + UNIT_ASSERT(!IsHexNumber("12345xx67890a")); + UNIT_ASSERT(!IsHexNumber("foobar")); UNIT_ASSERT(!IsHexNumber(TString())); - + UNIT_ASSERT(IsHexNumber(u"0")); UNIT_ASSERT(IsHexNumber(u"aaaadddAAAAA")); UNIT_ASSERT(IsHexNumber(u"0123456789ABCDEFabcdef")); @@ -72,5 +72,5 @@ Y_UNIT_TEST_SUITE(TStringClassify) { UNIT_ASSERT(!IsHexNumber(u"12345xx67890a")); UNIT_ASSERT(!IsHexNumber(u"foobar")); UNIT_ASSERT(!IsHexNumber(TUtf16String())); - } + } } diff --git a/util/string/util.h b/util/string/util.h index 0d77a5042b..24fcaa5bb8 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -73,13 +73,13 @@ public: /// [DIFFERENCE FOR NOT_FOUND CASE: Returns end of string, not NULL] const char* brk(const char* s) const { while (c_chars_table[(ui8)*s]) - ++s; + ++s; return s; } const char* brk(const char* s, const char* e) const { while (s < e && c_chars_table[(ui8)*s]) - ++s; + ++s; return s; } @@ -87,13 +87,13 @@ public: /// That is, skip all characters in table const char* cbrk(const char* s) const { while (chars_table[(ui8)*s]) - ++s; + ++s; return s; } const char* cbrk(const char* s, const char* e) const { while (s < e && chars_table[(ui8)*s]) - ++s; + ++s; return s; } @@ -148,7 +148,7 @@ public: protected: void init(const char* charset, bool extended); - str_spn() = default; + str_spn() = default; }; // an analogue of tr/$from/$to/ |