diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /util/string | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/ascii.h | 58 | ||||
-rw-r--r-- | util/string/ascii_ut.cpp | 72 | ||||
-rw-r--r-- | util/string/cast.cpp | 20 | ||||
-rw-r--r-- | util/string/cast_ut.cpp | 4 | ||||
-rw-r--r-- | util/string/hex.cpp | 78 | ||||
-rw-r--r-- | util/string/hex.h | 8 | ||||
-rw-r--r-- | util/string/split.h | 6 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 8 |
8 files changed, 127 insertions, 127 deletions
diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..5b743029a8 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -4,13 +4,13 @@ #include <util/system/compat.h> #include <util/generic/string.h> -// ctype.h-like functions, locale-independent: -// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and -// AsciiTo{Upper,Lower} -// -// standard functions from <ctype.h> are locale dependent, -// and cause undefined behavior when called on chars outside [0..127] range - +// ctype.h-like functions, locale-independent: +// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and +// AsciiTo{Upper,Lower} +// +// standard functions from <ctype.h> are locale dependent, +// and cause undefined behavior when called on chars outside [0..127] range + namespace NPrivate { enum ECharClass { CC_SPACE = 1, @@ -61,9 +61,9 @@ namespace NPrivate { } constexpr bool IsAscii(const int c) noexcept { - return !(c & ~0x7f); -} - + return !(c & ~0x7f); +} + inline bool IsAsciiSpace(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_SPACE; } @@ -71,27 +71,27 @@ inline bool IsAsciiSpace(unsigned char c) { inline bool IsAsciiUpper(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_UPPER; } - + inline bool IsAsciiLower(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_LOWER; -} - +} + inline bool IsAsciiDigit(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_DIGIT; -} - +} + inline bool IsAsciiAlpha(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALPHA; -} - +} + inline bool IsAsciiAlnum(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALNUM; -} - +} + inline bool IsAsciiHex(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ISHEX; -} - +} + inline bool IsAsciiPunct(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_PUNCT; } @@ -101,9 +101,9 @@ inline bool IsAsciiPunct(unsigned char c) { template <class T> inline bool IsAsciiSpace(T c) { return ::NPrivate::RangeOk(c) && IsAsciiSpace(static_cast<unsigned char>(c)); -} - -template <class T> +} + +template <class T> inline bool IsAsciiUpper(T c) { return ::NPrivate::RangeOk(c) && IsAsciiUpper(static_cast<unsigned char>(c)); } @@ -150,12 +150,12 @@ inline char AsciiToLower(char c) noexcept { template <class T> inline ::NPrivate::TDereferenced<T> AsciiToLower(T c) noexcept { return (c >= 0 && c <= 127) ? (::NPrivate::TDereferenced<T>)AsciiToLower((ui8)c) : c; -} - -template <class T> +} + +template <class T> inline ::NPrivate::TDereferenced<T> AsciiToUpper(T c) noexcept { - return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; -} + return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; +} /** * ASCII case-insensitive string comparison (for proper UTF8 strings diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 89069fee50..4108302622 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -1,42 +1,42 @@ -#include "ascii.h" -#include <ctype.h> - +#include "ascii.h" +#include <ctype.h> + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TAsciiTest) { Y_UNIT_TEST(TestAscii) { - UNIT_ASSERT(IsAsciiDigit('3')); - UNIT_ASSERT(!IsAsciiDigit('x')); - - UNIT_ASSERT(IsAsciiAlpha('r')); - UNIT_ASSERT(IsAsciiAlpha('R')); - UNIT_ASSERT(!IsAsciiAlpha('3')); - - UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); - UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); - - UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); - UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); - - UNIT_ASSERT(IsAscii('a')); - UNIT_ASSERT(!IsAscii(-100)); - UNIT_ASSERT(!IsAscii(+200)); - UNIT_ASSERT(!IsAscii(int('a') + 256)); - - for (int i = 0; i < 128; ++i) { - UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); + UNIT_ASSERT(IsAsciiDigit('3')); + UNIT_ASSERT(!IsAsciiDigit('x')); + + UNIT_ASSERT(IsAsciiAlpha('r')); + UNIT_ASSERT(IsAsciiAlpha('R')); + UNIT_ASSERT(!IsAsciiAlpha('3')); + + UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); + UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); + + UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); + UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); + + UNIT_ASSERT(IsAscii('a')); + UNIT_ASSERT(!IsAscii(-100)); + UNIT_ASSERT(!IsAscii(+200)); + UNIT_ASSERT(!IsAscii(int('a') + 256)); + + for (int i = 0; i < 128; ++i) { + UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); UNIT_ASSERT_VALUES_EQUAL((bool)ispunct(i), IsAsciiPunct((char)i)); - } - } + } + } Y_UNIT_TEST(Test1) { for (int i = 128; i < 1000; ++i) { @@ -95,4 +95,4 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); } -} +} diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..7f5f8c6b01 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -522,11 +522,11 @@ TString FromStringImpl<TString>(const char* data, size_t len) { } template <> -TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { - return TStringBuf(data, len); -} - -template <> +TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { + return TStringBuf(data, len); +} + +template <> std::string FromStringImpl<std::string>(const char* data, size_t len) { return std::string(data, len); } @@ -536,11 +536,11 @@ TUtf16String FromStringImpl<TUtf16String>(const wchar16* data, size_t len) { return TUtf16String(data, len); } -template <> -TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { - return TWtringBuf(data, len); -} - +template <> +TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { + return TWtringBuf(data, len); +} + // Try-versions template <> bool TryFromStringImpl<TStringBuf>(const char* data, size_t len, TStringBuf& result) { diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..e0da29e1b9 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -19,7 +19,7 @@ #define EPS 10E-7 -#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) +#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) #define OK_HEX_CHECK(type, val, base) UNIT_ASSERT_EQUAL((IntFromStringForCheck<base>(IntToString<base>(val))), val); #define EXC_HEX_CHECK(type, val, base) UNIT_ASSERT_EXCEPTION((IntFromString<type, base>(IntToString<base>(val))), yexception); @@ -326,7 +326,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(a, b); UNIT_ASSERT_VALUES_EQUAL((void*)a.data(), (void*)b.data()); } - + #if 0 Y_UNIT_TEST(TestBufferOverflow) { CheckConvertToBuffer<float>(1.f, 5, "1"); diff --git a/util/string/hex.cpp b/util/string/hex.cpp index 667397987f..deea4e3ba7 100644 --- a/util/string/hex.cpp +++ b/util/string/hex.cpp @@ -1,5 +1,5 @@ -#include "hex.h" - +#include "hex.h" + const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" @@ -16,48 +16,48 @@ const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"); - -char* HexEncode(const void* in, size_t len, char* out) { - const unsigned char* b = (const unsigned char*)in; - const unsigned char* e = b + len; - - while (b != e) { - *out++ = DigitToChar(*b / 16); - *out++ = DigitToChar(*b++ % 16); - } - - return out; -} - -void* HexDecode(const void* in, size_t len, void* ptr) { - const char* b = (const char*)in; - const char* e = b + len; + +char* HexEncode(const void* in, size_t len, char* out) { + const unsigned char* b = (const unsigned char*)in; + const unsigned char* e = b + len; + + while (b != e) { + *out++ = DigitToChar(*b / 16); + *out++ = DigitToChar(*b++ % 16); + } + + return 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")); - - char* out = (char*)ptr; - - while (b != e) { + + char* out = (char*)ptr; + + while (b != e) { *out++ = (char)String2Byte(b); - b += 2; - } - - return out; -} - + b += 2; + } + + return out; +} + TString HexEncode(const void* in, size_t len) { TString ret; - - ret.ReserveAndResize(len << 1); - HexEncode(in, len, ret.begin()); - - return ret; -} - + + ret.ReserveAndResize(len << 1); + HexEncode(in, len, ret.begin()); + + return ret; +} + TString HexDecode(const void* in, size_t len) { TString ret; - + ret.ReserveAndResize(len >> 1); HexDecode(in, len, ret.begin()); - - return ret; -} + + return ret; +} diff --git a/util/string/hex.h b/util/string/hex.h index af3d2d528f..5e9fdcbbbb 100644 --- a/util/string/hex.h +++ b/util/string/hex.h @@ -13,11 +13,11 @@ inline static char DigitToChar(unsigned char digit) { } extern const char* const Char2DigitTable; - + inline static int Char2Digit(char ch) { - char result = Char2DigitTable[(unsigned char)ch]; + char result = Char2DigitTable[(unsigned char)ch]; Y_ENSURE(result != '\xff', "invalid hex character " << (int)ch); - return result; + return result; } //! Convert a hex string of exactly 2 chars to int @@ -26,7 +26,7 @@ inline static int String2Byte(const char* s) { return Char2Digit(*s) * 16 + Char2Digit(*(s + 1)); } -char* HexEncode(const void* in, size_t len, char* out); +char* HexEncode(const void* in, size_t len, char* out); TString HexEncode(const void* in, size_t len); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..6852f0600f 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -441,7 +441,7 @@ void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { } } -// example: +// example: // 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) { @@ -451,9 +451,9 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2) { } template <class D, class P1, class P2, class... Other> -void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { +void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { GetNext(s, delim, p1); - Split(s, delim, p2, other...); + Split(s, delim, p2, other...); } /** diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..cd8b8fccdc 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -254,10 +254,10 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { Y_UNIT_TEST(ConvenientSplitTest) { TString data("abc 22 33.5 xyz"); TString str; - int num1 = 0; - double num2 = 0; - TStringBuf strBuf; - Split(data, ' ', str, num1, num2, strBuf); + int num1 = 0; + double num2 = 0; + TStringBuf strBuf; + Split(data, ' ', str, num1, num2, strBuf); UNIT_ASSERT_VALUES_EQUAL(str, "abc"); UNIT_ASSERT_VALUES_EQUAL(num1, 22); UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); |