aboutsummaryrefslogtreecommitdiffstats
path: root/util/charset
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:48 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:48 +0300
commit9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/charset
parent8cbc307de0221f84c80c42dcbe07d40727537e2c (diff)
downloadydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/charset')
-rw-r--r--util/charset/benchmark/to_lower/main.cpp68
-rw-r--r--util/charset/benchmark/to_lower/metrics/main.py10
-rw-r--r--util/charset/benchmark/to_lower/metrics/ya.make26
-rw-r--r--util/charset/benchmark/to_lower/ya.make18
-rw-r--r--util/charset/benchmark/utf8_to_wide/main.cpp2
-rw-r--r--util/charset/benchmark/utf8_to_wide/metrics/main.py10
-rw-r--r--util/charset/benchmark/utf8_to_wide/metrics/ya.make26
-rw-r--r--util/charset/benchmark/ya.make20
-rw-r--r--util/charset/utf8.cpp4
-rw-r--r--util/charset/utf8.h14
-rw-r--r--util/charset/utf8_ut.cpp12
-rw-r--r--util/charset/wide.cpp680
-rw-r--r--util/charset/wide.h282
-rw-r--r--util/charset/wide_ut.cpp1500
14 files changed, 1336 insertions, 1336 deletions
diff --git a/util/charset/benchmark/to_lower/main.cpp b/util/charset/benchmark/to_lower/main.cpp
index 30260e532d..e95fdc2371 100644
--- a/util/charset/benchmark/to_lower/main.cpp
+++ b/util/charset/benchmark/to_lower/main.cpp
@@ -1,25 +1,25 @@
#include <library/cpp/testing/benchmark/bench.h>
-
-#include <util/charset/wide.h>
-#include <util/generic/singleton.h>
-#include <util/generic/vector.h>
-#include <util/generic/string.h>
-
-static const auto ShortAscii = UTF8ToWide("hELlo");
-static const auto LongAscii = UTF8ToWide(
- "The first plane, plane 0, the Basic Multilingual Plane (BMP) contains characters for almost "
- "all modern languages, and a large number of symbols. A primary objective for the BMP is to "
- "support the unification of prior character sets as well as characters for writing. Most of "
- "the assigned code points in the BMP are used to encode Chinese, Japanese, and Korean (CJK) "
- "characters.");
-
-static const auto ShortRussian = UTF8ToWide("пРИвет");
-static const auto LongRussian = UTF8ToWide(
- "Плоскость 0 (Основная многоязычная плоскость, англ. Basic Multilingual Plane, BMP) отведена "
- "для символов практически всех современных письменностей и большого числа специальных символов. "
- "Большая часть таблицы занята китайско-японскими иероглифами и своеобразными корейскими"
- "буквами. В Юникоде 10.0 в этой плоскости представлены следующие блоки");
-
+
+#include <util/charset/wide.h>
+#include <util/generic/singleton.h>
+#include <util/generic/vector.h>
+#include <util/generic/string.h>
+
+static const auto ShortAscii = UTF8ToWide("hELlo");
+static const auto LongAscii = UTF8ToWide(
+ "The first plane, plane 0, the Basic Multilingual Plane (BMP) contains characters for almost "
+ "all modern languages, and a large number of symbols. A primary objective for the BMP is to "
+ "support the unification of prior character sets as well as characters for writing. Most of "
+ "the assigned code points in the BMP are used to encode Chinese, Japanese, and Korean (CJK) "
+ "characters.");
+
+static const auto ShortRussian = UTF8ToWide("пРИвет");
+static const auto LongRussian = UTF8ToWide(
+ "Плоскость 0 (Основная многоязычная плоскость, англ. Basic Multilingual Plane, BMP) отведена "
+ "для символов практически всех современных письменностей и большого числа специальных символов. "
+ "Большая часть таблицы занята китайско-японскими иероглифами и своеобразными корейскими"
+ "буквами. В Юникоде 10.0 в этой плоскости представлены следующие блоки");
+
#define DEFINE_INPLACE_BENCH(s) \
Y_CPU_BENCHMARK(s##CopyDetach, iface) { \
for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { \
@@ -38,8 +38,8 @@ static const auto LongRussian = UTF8ToWide(
NBench::Escape(copy.data()); \
NBench::Clobber(); \
} \
- }
-
+ }
+
#define DEFINE_RET_BENCH(s) \
Y_CPU_BENCHMARK(s##Ret, iface) { \
for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { \
@@ -48,14 +48,14 @@ static const auto LongRussian = UTF8ToWide(
NBench::Escape(res.data()); \
NBench::Clobber(); \
} \
- }
-
-DEFINE_INPLACE_BENCH(ShortAscii)
-DEFINE_INPLACE_BENCH(LongAscii)
-DEFINE_INPLACE_BENCH(ShortRussian)
-DEFINE_INPLACE_BENCH(LongRussian)
-
-DEFINE_RET_BENCH(ShortAscii)
-DEFINE_RET_BENCH(LongAscii)
-DEFINE_RET_BENCH(ShortRussian)
-DEFINE_RET_BENCH(LongRussian)
+ }
+
+DEFINE_INPLACE_BENCH(ShortAscii)
+DEFINE_INPLACE_BENCH(LongAscii)
+DEFINE_INPLACE_BENCH(ShortRussian)
+DEFINE_INPLACE_BENCH(LongRussian)
+
+DEFINE_RET_BENCH(ShortAscii)
+DEFINE_RET_BENCH(LongAscii)
+DEFINE_RET_BENCH(ShortRussian)
+DEFINE_RET_BENCH(LongRussian)
diff --git a/util/charset/benchmark/to_lower/metrics/main.py b/util/charset/benchmark/to_lower/metrics/main.py
index d6a4625fa6..e7495d432b 100644
--- a/util/charset/benchmark/to_lower/metrics/main.py
+++ b/util/charset/benchmark/to_lower/metrics/main.py
@@ -1,5 +1,5 @@
-import yatest.common as yc
-
-
-def test_export_metrics(metrics):
- metrics.set_benchmark(yc.execute_benchmark('util/charset/benchmark/to_lower/to_lower'))
+import yatest.common as yc
+
+
+def test_export_metrics(metrics):
+ metrics.set_benchmark(yc.execute_benchmark('util/charset/benchmark/to_lower/to_lower'))
diff --git a/util/charset/benchmark/to_lower/metrics/ya.make b/util/charset/benchmark/to_lower/metrics/ya.make
index 675cdb7aab..5bb3461a8d 100644
--- a/util/charset/benchmark/to_lower/metrics/ya.make
+++ b/util/charset/benchmark/to_lower/metrics/ya.make
@@ -1,21 +1,21 @@
-OWNER(
- agorodilov
+OWNER(
+ agorodilov
g:util
-)
+)
SUBSCRIBER(g:util-subscribers)
-
+
PY2TEST()
-
+
SIZE(LARGE)
-
-TAG(
+
+TAG(
ya:force_sandbox
- sb:intel_e5_2660v1
+ sb:intel_e5_2660v1
ya:fat
-)
-
+)
+
TEST_SRCS(main.py)
-
+
DEPENDS(util/charset/benchmark/to_lower)
-
-END()
+
+END()
diff --git a/util/charset/benchmark/to_lower/ya.make b/util/charset/benchmark/to_lower/ya.make
index 2de20e626d..74c47e6de5 100644
--- a/util/charset/benchmark/to_lower/ya.make
+++ b/util/charset/benchmark/to_lower/ya.make
@@ -1,11 +1,11 @@
OWNER(yazevnul)
-
+
Y_BENCHMARK()
-
-ALLOCATOR(B)
-
-SRCS(
- main.cpp
-)
-
-END()
+
+ALLOCATOR(B)
+
+SRCS(
+ main.cpp
+)
+
+END()
diff --git a/util/charset/benchmark/utf8_to_wide/main.cpp b/util/charset/benchmark/utf8_to_wide/main.cpp
index bdd234bfc6..09fa567fe5 100644
--- a/util/charset/benchmark/utf8_to_wide/main.cpp
+++ b/util/charset/benchmark/utf8_to_wide/main.cpp
@@ -12,7 +12,7 @@ namespace {
template <size_t N>
struct TRandomAsciiString: public TVector<char> {
inline TRandomAsciiString() {
- reserve(N);
+ reserve(N);
for (size_t i = 0; i < N; ++i) {
push_back(RandomNumber<char>(127));
}
diff --git a/util/charset/benchmark/utf8_to_wide/metrics/main.py b/util/charset/benchmark/utf8_to_wide/metrics/main.py
index adadfac791..ffbd8f68fd 100644
--- a/util/charset/benchmark/utf8_to_wide/metrics/main.py
+++ b/util/charset/benchmark/utf8_to_wide/metrics/main.py
@@ -1,5 +1,5 @@
-import yatest.common as yc
-
-
-def test_export_metrics(metrics):
- metrics.set_benchmark(yc.execute_benchmark('util/charset/benchmark/utf8_to_wide/utf8_to_wide'))
+import yatest.common as yc
+
+
+def test_export_metrics(metrics):
+ metrics.set_benchmark(yc.execute_benchmark('util/charset/benchmark/utf8_to_wide/utf8_to_wide'))
diff --git a/util/charset/benchmark/utf8_to_wide/metrics/ya.make b/util/charset/benchmark/utf8_to_wide/metrics/ya.make
index 997c41fbca..c406e25bee 100644
--- a/util/charset/benchmark/utf8_to_wide/metrics/ya.make
+++ b/util/charset/benchmark/utf8_to_wide/metrics/ya.make
@@ -1,21 +1,21 @@
-OWNER(
- agorodilov
+OWNER(
+ agorodilov
g:util
-)
+)
SUBSCRIBER(g:util-subscribers)
-
+
PY2TEST()
-
+
SIZE(LARGE)
-
-TAG(
+
+TAG(
ya:force_sandbox
- sb:intel_e5_2660v1
+ sb:intel_e5_2660v1
ya:fat
-)
-
+)
+
TEST_SRCS(main.py)
-
+
DEPENDS(util/charset/benchmark/utf8_to_wide)
-
-END()
+
+END()
diff --git a/util/charset/benchmark/ya.make b/util/charset/benchmark/ya.make
index 9344fc3904..de3e04ef22 100644
--- a/util/charset/benchmark/ya.make
+++ b/util/charset/benchmark/ya.make
@@ -1,12 +1,12 @@
-OWNER(
- agorodilov
+OWNER(
+ agorodilov
g:util
-)
+)
SUBSCRIBER(g:util-subscribers)
-
-RECURSE(
- to_lower
- to_lower/metrics
- utf8_to_wide
- utf8_to_wide/metrics
-)
+
+RECURSE(
+ to_lower
+ to_lower/metrics
+ utf8_to_wide
+ utf8_to_wide/metrics
+)
diff --git a/util/charset/utf8.cpp b/util/charset/utf8.cpp
index a45229c33f..efe3a52f61 100644
--- a/util/charset/utf8.cpp
+++ b/util/charset/utf8.cpp
@@ -93,13 +93,13 @@ static const char* SkipUTF8Chars(const char* begin, const char* end, size_t numC
ythrow yexception() << "invalid UTF-8 char";
}
begin += runeLen;
- Y_ASSERT(begin <= end);
+ Y_ASSERT(begin <= end);
--numChars;
}
return begin;
}
-TStringBuf SubstrUTF8(const TStringBuf str, size_t pos, size_t len) {
+TStringBuf SubstrUTF8(const TStringBuf str, size_t pos, size_t len) {
const char* start = SkipUTF8Chars(str.begin(), str.end(), pos);
const char* end = SkipUTF8Chars(start, str.end(), len);
return TStringBuf(start, end - start);
diff --git a/util/charset/utf8.h b/util/charset/utf8.h
index d64bd3c61d..5039b46ae9 100644
--- a/util/charset/utf8.h
+++ b/util/charset/utf8.h
@@ -11,7 +11,7 @@
extern const wchar32 BROKEN_RUNE;
inline unsigned char UTF8LeadByteMask(size_t utf8_rune_len) {
- // Y_ASSERT (utf8_rune_len <= 4);
+ // Y_ASSERT (utf8_rune_len <= 4);
return "\0\0\037\017\007"[utf8_rune_len];
}
@@ -70,7 +70,7 @@ inline bool IsUTF8ContinuationByte(unsigned char c) {
//! @param p pointer to the current character
//! @param e end of the character sequence
inline RECODE_RESULT GetUTF8CharLen(size_t& n, const unsigned char* p, const unsigned char* e) {
- Y_ASSERT(p < e); // since p < e then we will check RECODE_EOINPUT only for n > 1 (see calls of this functions)
+ Y_ASSERT(p < e); // since p < e then we will check RECODE_EOINPUT only for n > 1 (see calls of this functions)
switch (UTF8RuneLen(*p)) {
case 0:
return RECODE_BROKENSYMBOL; //[BROKENSYMBOL] in first byte
@@ -125,7 +125,7 @@ inline bool GetNumberOfUTF8Chars(const char* text, size_t len, size_t& number) {
break;
}
cur += runeLen;
- Y_ASSERT(cur <= last);
+ Y_ASSERT(cur <= last);
++number;
}
return res;
@@ -195,7 +195,7 @@ inline RECODE_RESULT SafeReadUTF8Char(wchar32& rune, size_t& rune_len, const uns
//! @param p pointer to the current character, it will be changed in case of valid UTF8 byte sequence
//! @param e the end of the character sequence
Y_FORCE_INLINE RECODE_RESULT ReadUTF8CharAndAdvance(wchar32& rune, const unsigned char*& p, const unsigned char* e) noexcept {
- Y_ASSERT(p < e); // since p < e then we will check RECODE_EOINPUT only for n > 1 (see calls of this functions)
+ Y_ASSERT(p < e); // since p < e then we will check RECODE_EOINPUT only for n > 1 (see calls of this functions)
switch (UTF8RuneLen(*p)) {
case 0:
rune = BROKEN_RUNE;
@@ -345,7 +345,7 @@ inline void WriteUTF8Char(wchar32 rune, size_t& rune_len, unsigned char* s) {
}
}
-TStringBuf SubstrUTF8(const TStringBuf str, size_t pos, size_t len);
+TStringBuf SubstrUTF8(const TStringBuf str, size_t pos, size_t len);
enum EUTF8Detect {
NotUTF8,
@@ -355,7 +355,7 @@ enum EUTF8Detect {
EUTF8Detect UTF8Detect(const char* s, size_t len);
-inline EUTF8Detect UTF8Detect(const TStringBuf input) {
+inline EUTF8Detect UTF8Detect(const TStringBuf input) {
return UTF8Detect(input.data(), input.size());
}
@@ -363,7 +363,7 @@ inline bool IsUtf(const char* input, size_t len) {
return UTF8Detect(input, len) != NotUTF8;
}
-inline bool IsUtf(const TStringBuf input) {
+inline bool IsUtf(const TStringBuf input) {
return IsUtf(input.data(), input.size());
}
diff --git a/util/charset/utf8_ut.cpp b/util/charset/utf8_ut.cpp
index 70b7874740..9e68881cca 100644
--- a/util/charset/utf8_ut.cpp
+++ b/util/charset/utf8_ut.cpp
@@ -7,12 +7,12 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/testing/unittest/env.h>
-Y_UNIT_TEST_SUITE(TUtfUtilTest) {
- Y_UNIT_TEST(TestUTF8Len) {
+Y_UNIT_TEST_SUITE(TUtfUtilTest) {
+ Y_UNIT_TEST(TestUTF8Len) {
UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7);
}
- Y_UNIT_TEST(TestToLowerUtfString) {
+ Y_UNIT_TEST(TestToLowerUtfString) {
UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8("xyz XYZ ПРИВЕТ!"), "xyz xyz привет!");
UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8(TStringBuf("xyz")), "xyz");
@@ -92,14 +92,14 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) {
}
}
- Y_UNIT_TEST(TestUTF8ToWide) {
+ Y_UNIT_TEST(TestUTF8ToWide) {
TFileInput in(ArcadiaSourceRoot() + TStringBuf("/util/charset/ut/utf8/test1.txt"));
TString text = in.ReadAll();
UNIT_ASSERT(WideToUTF8(UTF8ToWide(text)) == text);
}
- Y_UNIT_TEST(TestInvalidUTF8) {
+ Y_UNIT_TEST(TestInvalidUTF8) {
TVector<TString> testData;
TFileInput input(ArcadiaSourceRoot() + TStringBuf("/util/charset/ut/utf8/invalid_UTF8.bin"));
Load(&input, testData);
@@ -109,7 +109,7 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) {
}
}
- Y_UNIT_TEST(TestUTF8ToWideScalar) {
+ Y_UNIT_TEST(TestUTF8ToWideScalar) {
TFileInput in(ArcadiaSourceRoot() + TStringBuf("/util/charset/ut/utf8/test1.txt"));
TString text = in.ReadAll();
diff --git a/util/charset/wide.cpp b/util/charset/wide.cpp
index 5c0dc0faed..a287438ddd 100644
--- a/util/charset/wide.cpp
+++ b/util/charset/wide.cpp
@@ -15,16 +15,16 @@ namespace {
inline size_t EscapedLen(wchar16 c) {
switch (c) {
case '<':
- return Y_ARRAY_SIZE(LT);
+ return Y_ARRAY_SIZE(LT);
case '>':
- return Y_ARRAY_SIZE(GT);
+ return Y_ARRAY_SIZE(GT);
case '&':
- return Y_ARRAY_SIZE(AMP);
+ return Y_ARRAY_SIZE(AMP);
case '\"':
- return Y_ARRAY_SIZE(QUOT);
+ return Y_ARRAY_SIZE(QUOT);
default:
if (insertBr && (c == '\r' || c == '\n'))
- return Y_ARRAY_SIZE(BR);
+ return Y_ARRAY_SIZE(BR);
else
return 1;
}
@@ -39,192 +39,192 @@ size_t Collapse(wchar16* s, size_t n) {
return CollapseImpl(s, n, IsWhitespace);
}
-TWtringBuf StripLeft(const TWtringBuf text) noexcept {
- const auto* p = text.data();
- const auto* const pe = text.data() + text.size();
-
- for (; p != pe && IsWhitespace(*p); ++p) {
- }
-
- return {p, pe};
-}
-
-void StripLeft(TUtf16String& text) {
- const auto stripped = StripLeft(TWtringBuf(text));
- if (stripped.size() == text.size()) {
- return;
- }
-
- text = stripped;
-}
-
-TWtringBuf StripRight(const TWtringBuf text) noexcept {
- if (!text) {
- return {};
- }
-
- const auto* const pe = text.data() - 1;
- const auto* p = text.data() + text.size() - 1;
-
- for (; p != pe && IsWhitespace(*p); --p) {
- }
-
- return {pe + 1, p + 1};
-}
-
-void StripRight(TUtf16String& text) {
- const auto stripped = StripRight(TWtringBuf(text));
- if (stripped.size() == text.size()) {
- return;
- }
-
- text.resize(stripped.size());
-}
-
-TWtringBuf Strip(const TWtringBuf text) noexcept {
- return StripRight(StripLeft(text));
-}
-
-void Strip(TUtf16String& text) {
- StripLeft(text);
- StripRight(text);
-}
-
-template <typename T>
-static bool IsReductionOnSymbolsTrue(const TWtringBuf text, T&& f) {
- const auto* p = text.data();
- const auto* const pe = text.data() + text.length();
- while (p != pe) {
- const auto symbol = ReadSymbolAndAdvance(p, pe);
- if (!f(symbol)) {
- return false;
- }
- }
-
- return true;
-}
-
-bool IsLowerWord(const TWtringBuf text) noexcept {
- return IsReductionOnSymbolsTrue(text, [](const wchar32 s) { return IsLower(s); });
-}
-
-bool IsUpperWord(const TWtringBuf text) noexcept {
- return IsReductionOnSymbolsTrue(text, [](const wchar32 s) { return IsUpper(s); });
-}
-
-bool IsLower(const TWtringBuf text) noexcept {
- return IsReductionOnSymbolsTrue(text, [](const wchar32 s) {
- if (IsAlpha(s)) {
- return IsLower(s);
- }
- return true;
- });
-}
-
-bool IsUpper(const TWtringBuf text) noexcept {
- return IsReductionOnSymbolsTrue(text, [](const wchar32 s) {
- if (IsAlpha(s)) {
- return IsUpper(s);
- }
- return true;
- });
-}
-
-bool IsTitleWord(const TWtringBuf text) noexcept {
- if (!text) {
- return false;
- }
-
- const auto* p = text.data();
- const auto* pe = text.data() + text.size();
-
- const auto firstSymbol = ReadSymbolAndAdvance(p, pe);
- if (firstSymbol != ToTitle(firstSymbol)) {
- return false;
- }
-
- return IsLowerWord({p, pe});
-}
-
+TWtringBuf StripLeft(const TWtringBuf text) noexcept {
+ const auto* p = text.data();
+ const auto* const pe = text.data() + text.size();
+
+ for (; p != pe && IsWhitespace(*p); ++p) {
+ }
+
+ return {p, pe};
+}
+
+void StripLeft(TUtf16String& text) {
+ const auto stripped = StripLeft(TWtringBuf(text));
+ if (stripped.size() == text.size()) {
+ return;
+ }
+
+ text = stripped;
+}
+
+TWtringBuf StripRight(const TWtringBuf text) noexcept {
+ if (!text) {
+ return {};
+ }
+
+ const auto* const pe = text.data() - 1;
+ const auto* p = text.data() + text.size() - 1;
+
+ for (; p != pe && IsWhitespace(*p); --p) {
+ }
+
+ return {pe + 1, p + 1};
+}
+
+void StripRight(TUtf16String& text) {
+ const auto stripped = StripRight(TWtringBuf(text));
+ if (stripped.size() == text.size()) {
+ return;
+ }
+
+ text.resize(stripped.size());
+}
+
+TWtringBuf Strip(const TWtringBuf text) noexcept {
+ return StripRight(StripLeft(text));
+}
+
+void Strip(TUtf16String& text) {
+ StripLeft(text);
+ StripRight(text);
+}
+
+template <typename T>
+static bool IsReductionOnSymbolsTrue(const TWtringBuf text, T&& f) {
+ const auto* p = text.data();
+ const auto* const pe = text.data() + text.length();
+ while (p != pe) {
+ const auto symbol = ReadSymbolAndAdvance(p, pe);
+ if (!f(symbol)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool IsLowerWord(const TWtringBuf text) noexcept {
+ return IsReductionOnSymbolsTrue(text, [](const wchar32 s) { return IsLower(s); });
+}
+
+bool IsUpperWord(const TWtringBuf text) noexcept {
+ return IsReductionOnSymbolsTrue(text, [](const wchar32 s) { return IsUpper(s); });
+}
+
+bool IsLower(const TWtringBuf text) noexcept {
+ return IsReductionOnSymbolsTrue(text, [](const wchar32 s) {
+ if (IsAlpha(s)) {
+ return IsLower(s);
+ }
+ return true;
+ });
+}
+
+bool IsUpper(const TWtringBuf text) noexcept {
+ return IsReductionOnSymbolsTrue(text, [](const wchar32 s) {
+ if (IsAlpha(s)) {
+ return IsUpper(s);
+ }
+ return true;
+ });
+}
+
+bool IsTitleWord(const TWtringBuf text) noexcept {
+ if (!text) {
+ return false;
+ }
+
+ const auto* p = text.data();
+ const auto* pe = text.data() + text.size();
+
+ const auto firstSymbol = ReadSymbolAndAdvance(p, pe);
+ if (firstSymbol != ToTitle(firstSymbol)) {
+ return false;
+ }
+
+ return IsLowerWord({p, pe});
+}
+
template <bool stopOnFirstModification, typename TCharType, typename F>
static bool ModifySequence(TCharType*& p, const TCharType* const pe, F&& f) {
- while (p != pe) {
- const auto symbol = ReadSymbol(p, pe);
- const auto modified = f(symbol);
- if (symbol != modified) {
- if (stopOnFirstModification) {
- return true;
- }
-
+ while (p != pe) {
+ const auto symbol = ReadSymbol(p, pe);
+ const auto modified = f(symbol);
+ if (symbol != modified) {
+ if (stopOnFirstModification) {
+ return true;
+ }
+
WriteSymbol(modified, p); // also moves `p` forward
- } else {
- p = SkipSymbol(p, pe);
- }
- }
-
- return false;
-}
-
+ } else {
+ p = SkipSymbol(p, pe);
+ }
+ }
+
+ return false;
+}
+
template <bool stopOnFirstModification, typename TCharType, typename F>
static bool ModifySequence(const TCharType*& p, const TCharType* const pe, TCharType*& out, F&& f) {
- while (p != pe) {
- const auto symbol = stopOnFirstModification ? ReadSymbol(p, pe) : ReadSymbolAndAdvance(p, pe);
- const auto modified = f(symbol);
-
- if (stopOnFirstModification) {
- if (symbol != modified) {
- return true;
- }
-
- p = SkipSymbol(p, pe);
- }
-
- WriteSymbol(modified, out);
- }
-
- return false;
-}
-
+ while (p != pe) {
+ const auto symbol = stopOnFirstModification ? ReadSymbol(p, pe) : ReadSymbolAndAdvance(p, pe);
+ const auto modified = f(symbol);
+
+ if (stopOnFirstModification) {
+ if (symbol != modified) {
+ return true;
+ }
+
+ p = SkipSymbol(p, pe);
+ }
+
+ WriteSymbol(modified, out);
+ }
+
+ return false;
+}
+
template <class TStringType>
static void DetachAndFixPointers(TStringType& text, typename TStringType::value_type*& p, const typename TStringType::value_type*& pe) {
- const auto pos = p - text.data();
- const auto count = pe - p;
- p = text.Detach() + pos;
- pe = p + count;
-}
-
+ const auto pos = p - text.data();
+ const auto count = pe - p;
+ p = text.Detach() + pos;
+ pe = p + count;
+}
+
template <class TStringType, typename F>
static bool ModifyStringSymbolwise(TStringType& text, size_t pos, size_t count, F&& f) {
- // TODO(yazevnul): this is done for consistency with `TUtf16String::to_lower` and friends
- // at r2914050, maybe worth replacing them with asserts. Also see the same code in `ToTitle`.
- pos = pos < text.size() ? pos : text.size();
- count = count < text.size() - pos ? count : text.size() - pos;
-
- // TUtf16String is refcounted and it's `data` method return pointer to the constant memory.
- // To simplify the code we do a `const_cast`, though first write to the memory will be done only
- // after we call `Detach()` and get pointer to a writable piece of memory.
+ // TODO(yazevnul): this is done for consistency with `TUtf16String::to_lower` and friends
+ // at r2914050, maybe worth replacing them with asserts. Also see the same code in `ToTitle`.
+ pos = pos < text.size() ? pos : text.size();
+ count = count < text.size() - pos ? count : text.size() - pos;
+
+ // TUtf16String is refcounted and it's `data` method return pointer to the constant memory.
+ // To simplify the code we do a `const_cast`, though first write to the memory will be done only
+ // after we call `Detach()` and get pointer to a writable piece of memory.
auto* p = const_cast<typename TStringType::value_type*>(text.data() + pos);
- const auto* pe = text.data() + pos + count;
-
- if (ModifySequence<true>(p, pe, f)) {
- DetachAndFixPointers(text, p, pe);
- ModifySequence<false>(p, pe, f);
- return true;
- }
-
- return false;
-}
-
-bool ToLower(TUtf16String& text, size_t pos, size_t count) {
- const auto f = [](const wchar32 s) { return ToLower(s); };
- return ModifyStringSymbolwise(text, pos, count, f);
-}
-
-bool ToUpper(TUtf16String& text, size_t pos, size_t count) {
- const auto f = [](const wchar32 s) { return ToUpper(s); };
- return ModifyStringSymbolwise(text, pos, count, f);
-}
-
+ const auto* pe = text.data() + pos + count;
+
+ if (ModifySequence<true>(p, pe, f)) {
+ DetachAndFixPointers(text, p, pe);
+ ModifySequence<false>(p, pe, f);
+ return true;
+ }
+
+ return false;
+}
+
+bool ToLower(TUtf16String& text, size_t pos, size_t count) {
+ const auto f = [](const wchar32 s) { return ToLower(s); };
+ return ModifyStringSymbolwise(text, pos, count, f);
+}
+
+bool ToUpper(TUtf16String& text, size_t pos, size_t count) {
+ const auto f = [](const wchar32 s) { return ToUpper(s); };
+ return ModifyStringSymbolwise(text, pos, count, f);
+}
+
bool ToLower(TUtf32String& text, size_t pos, size_t count) {
const auto f = [](const wchar32 s) { return ToLower(s); };
return ModifyStringSymbolwise(text, pos, count, f);
@@ -235,37 +235,37 @@ bool ToUpper(TUtf32String& text, size_t pos, size_t count) {
return ModifyStringSymbolwise(text, pos, count, f);
}
-bool ToTitle(TUtf16String& text, size_t pos, size_t count) {
- if (!text) {
- return false;
- }
-
- pos = pos < text.size() ? pos : text.size();
- count = count < text.size() - pos ? count : text.size() - pos;
-
- const auto toLower = [](const wchar32 s) { return ToLower(s); };
-
- auto* p = const_cast<wchar16*>(text.data() + pos);
- const auto* pe = text.data() + pos + count;
-
- const auto firstSymbol = ReadSymbol(p, pe);
- if (firstSymbol == ToTitle(firstSymbol)) {
- p = SkipSymbol(p, pe);
- if (ModifySequence<true>(p, pe, toLower)) {
- DetachAndFixPointers(text, p, pe);
- ModifySequence<false>(p, pe, toLower);
- return true;
- }
- } else {
- DetachAndFixPointers(text, p, pe);
+bool ToTitle(TUtf16String& text, size_t pos, size_t count) {
+ if (!text) {
+ return false;
+ }
+
+ pos = pos < text.size() ? pos : text.size();
+ count = count < text.size() - pos ? count : text.size() - pos;
+
+ const auto toLower = [](const wchar32 s) { return ToLower(s); };
+
+ auto* p = const_cast<wchar16*>(text.data() + pos);
+ const auto* pe = text.data() + pos + count;
+
+ const auto firstSymbol = ReadSymbol(p, pe);
+ if (firstSymbol == ToTitle(firstSymbol)) {
+ p = SkipSymbol(p, pe);
+ if (ModifySequence<true>(p, pe, toLower)) {
+ DetachAndFixPointers(text, p, pe);
+ ModifySequence<false>(p, pe, toLower);
+ return true;
+ }
+ } else {
+ DetachAndFixPointers(text, p, pe);
WriteSymbol(ToTitle(ReadSymbol(p, pe)), p); // also moves `p` forward
- ModifySequence<false>(p, pe, toLower);
- return true;
- }
-
- return false;
-}
-
+ ModifySequence<false>(p, pe, toLower);
+ return true;
+ }
+
+ return false;
+}
+
bool ToTitle(TUtf32String& text, size_t pos, size_t count) {
if (!text) {
return false;
@@ -297,21 +297,21 @@ bool ToTitle(TUtf32String& text, size_t pos, size_t count) {
return false;
}
-TUtf16String ToLowerRet(TUtf16String text, size_t pos, size_t count) {
- ToLower(text, pos, count);
- return text;
-}
-
-TUtf16String ToUpperRet(TUtf16String text, size_t pos, size_t count) {
- ToUpper(text, pos, count);
- return text;
-}
-
-TUtf16String ToTitleRet(TUtf16String text, size_t pos, size_t count) {
- ToTitle(text, pos, count);
- return text;
-}
-
+TUtf16String ToLowerRet(TUtf16String text, size_t pos, size_t count) {
+ ToLower(text, pos, count);
+ return text;
+}
+
+TUtf16String ToUpperRet(TUtf16String text, size_t pos, size_t count) {
+ ToUpper(text, pos, count);
+ return text;
+}
+
+TUtf16String ToTitleRet(TUtf16String text, size_t pos, size_t count) {
+ ToTitle(text, pos, count);
+ return text;
+}
+
TUtf32String ToLowerRet(TUtf32String text, size_t pos, size_t count) {
ToLower(text, pos, count);
return text;
@@ -327,87 +327,87 @@ TUtf32String ToTitleRet(TUtf32String text, size_t pos, size_t count) {
return text;
}
-bool ToLower(const wchar16* text, size_t length, wchar16* out) noexcept {
- // TODO(yazevnul): get rid of `text == out` case (it is probably used only in lemmer) and then
- // we can declare text and out as `__restrict__`
- Y_ASSERT(text == out || !(out >= text && out < text + length));
- const auto f = [](const wchar32 s) { return ToLower(s); };
- const auto* p = text;
- const auto* const pe = text + length;
- if (ModifySequence<true>(p, pe, out, f)) {
- ModifySequence<false>(p, pe, out, f);
- return true;
- }
- return false;
-}
-
-bool ToUpper(const wchar16* text, size_t length, wchar16* out) noexcept {
- Y_ASSERT(text == out || !(out >= text && out < text + length));
- const auto f = [](const wchar32 s) { return ToUpper(s); };
- const auto* p = text;
- const auto* const pe = text + length;
- if (ModifySequence<true>(p, pe, out, f)) {
- ModifySequence<false>(p, pe, out, f);
- return true;
- }
- return false;
-}
-
-bool ToTitle(const wchar16* text, size_t length, wchar16* out) noexcept {
- if (!length) {
- return false;
- }
-
- Y_ASSERT(text == out || !(out >= text && out < text + length));
-
- const auto* const textEnd = text + length;
- const auto firstSymbol = ReadSymbolAndAdvance(text, textEnd);
- const auto firstSymbolTitle = ToTitle(firstSymbol);
-
- WriteSymbol(firstSymbolTitle, out);
-
- return ToLower(text, textEnd - text, out) || firstSymbol != firstSymbolTitle;
-}
-
-bool ToLower(wchar16* text, size_t length) noexcept {
- const auto f = [](const wchar32 s) { return ToLower(s); };
- const auto* const textEnd = text + length;
- if (ModifySequence<true>(text, textEnd, f)) {
- ModifySequence<false>(text, textEnd, f);
- return true;
- }
- return false;
-}
-
-bool ToUpper(wchar16* text, size_t length) noexcept {
- const auto f = [](const wchar32 s) { return ToUpper(s); };
- const auto* const textEnd = text + length;
- if (ModifySequence<true>(text, textEnd, f)) {
- ModifySequence<false>(text, textEnd, f);
- return true;
- }
- return false;
-}
-
-bool ToTitle(wchar16* text, size_t length) noexcept {
- if (!length) {
- return false;
- }
-
- const auto* textEnd = text + length;
- const auto firstSymbol = ReadSymbol(text, textEnd);
- const auto firstSymbolTitle = ToTitle(firstSymbol);
-
- // avoid unnacessary writes to the memory
- if (firstSymbol != firstSymbolTitle) {
- WriteSymbol(firstSymbolTitle, text);
- } else {
- text = SkipSymbol(text, textEnd);
- }
-
- return ToLower(text, textEnd - text) || firstSymbol != firstSymbolTitle;
-}
-
+bool ToLower(const wchar16* text, size_t length, wchar16* out) noexcept {
+ // TODO(yazevnul): get rid of `text == out` case (it is probably used only in lemmer) and then
+ // we can declare text and out as `__restrict__`
+ Y_ASSERT(text == out || !(out >= text && out < text + length));
+ const auto f = [](const wchar32 s) { return ToLower(s); };
+ const auto* p = text;
+ const auto* const pe = text + length;
+ if (ModifySequence<true>(p, pe, out, f)) {
+ ModifySequence<false>(p, pe, out, f);
+ return true;
+ }
+ return false;
+}
+
+bool ToUpper(const wchar16* text, size_t length, wchar16* out) noexcept {
+ Y_ASSERT(text == out || !(out >= text && out < text + length));
+ const auto f = [](const wchar32 s) { return ToUpper(s); };
+ const auto* p = text;
+ const auto* const pe = text + length;
+ if (ModifySequence<true>(p, pe, out, f)) {
+ ModifySequence<false>(p, pe, out, f);
+ return true;
+ }
+ return false;
+}
+
+bool ToTitle(const wchar16* text, size_t length, wchar16* out) noexcept {
+ if (!length) {
+ return false;
+ }
+
+ Y_ASSERT(text == out || !(out >= text && out < text + length));
+
+ const auto* const textEnd = text + length;
+ const auto firstSymbol = ReadSymbolAndAdvance(text, textEnd);
+ const auto firstSymbolTitle = ToTitle(firstSymbol);
+
+ WriteSymbol(firstSymbolTitle, out);
+
+ return ToLower(text, textEnd - text, out) || firstSymbol != firstSymbolTitle;
+}
+
+bool ToLower(wchar16* text, size_t length) noexcept {
+ const auto f = [](const wchar32 s) { return ToLower(s); };
+ const auto* const textEnd = text + length;
+ if (ModifySequence<true>(text, textEnd, f)) {
+ ModifySequence<false>(text, textEnd, f);
+ return true;
+ }
+ return false;
+}
+
+bool ToUpper(wchar16* text, size_t length) noexcept {
+ const auto f = [](const wchar32 s) { return ToUpper(s); };
+ const auto* const textEnd = text + length;
+ if (ModifySequence<true>(text, textEnd, f)) {
+ ModifySequence<false>(text, textEnd, f);
+ return true;
+ }
+ return false;
+}
+
+bool ToTitle(wchar16* text, size_t length) noexcept {
+ if (!length) {
+ return false;
+ }
+
+ const auto* textEnd = text + length;
+ const auto firstSymbol = ReadSymbol(text, textEnd);
+ const auto firstSymbolTitle = ToTitle(firstSymbol);
+
+ // avoid unnacessary writes to the memory
+ if (firstSymbol != firstSymbolTitle) {
+ WriteSymbol(firstSymbolTitle, text);
+ } else {
+ text = SkipSymbol(text, textEnd);
+ }
+
+ return ToLower(text, textEnd - text) || firstSymbol != firstSymbolTitle;
+}
+
bool ToLower(const wchar32* text, size_t length, wchar32* out) noexcept {
// TODO(yazevnul): get rid of `text == out` case (it is probably used only in lemmer) and then
// we can declare text and out as `__restrict__`
@@ -489,27 +489,27 @@ bool ToTitle(wchar32* text, size_t length) noexcept {
return ToLower(text, textEnd - text) || firstSymbol != firstSymbolTitle;
}
-template <typename F>
-static TUtf16String ToSmthRet(const TWtringBuf text, size_t pos, size_t count, F&& f) {
- pos = pos < text.size() ? pos : text.size();
- count = count < text.size() - pos ? count : text.size() - pos;
-
- auto res = TUtf16String::Uninitialized(text.size());
- auto* const resBegin = res.Detach();
-
- if (pos) {
- MemCopy(resBegin, text.data(), pos);
- }
-
- f(text.data() + pos, count, resBegin + pos);
-
- if (count - pos != text.size()) {
- MemCopy(resBegin + pos + count, text.data() + pos + count, text.size() - pos - count);
- }
-
- return res;
-}
-
+template <typename F>
+static TUtf16String ToSmthRet(const TWtringBuf text, size_t pos, size_t count, F&& f) {
+ pos = pos < text.size() ? pos : text.size();
+ count = count < text.size() - pos ? count : text.size() - pos;
+
+ auto res = TUtf16String::Uninitialized(text.size());
+ auto* const resBegin = res.Detach();
+
+ if (pos) {
+ MemCopy(resBegin, text.data(), pos);
+ }
+
+ f(text.data() + pos, count, resBegin + pos);
+
+ if (count - pos != text.size()) {
+ MemCopy(resBegin + pos + count, text.data() + pos + count, text.size() - pos - count);
+ }
+
+ return res;
+}
+
template <typename F>
static TUtf32String ToSmthRet(const TUtf32StringBuf text, size_t pos, size_t count, F&& f) {
pos = pos < text.size() ? pos : text.size();
@@ -531,24 +531,24 @@ static TUtf32String ToSmthRet(const TUtf32StringBuf text, size_t pos, size_t cou
return res;
}
-TUtf16String ToLowerRet(const TWtringBuf text, size_t pos, size_t count) {
+TUtf16String ToLowerRet(const TWtringBuf text, size_t pos, size_t count) {
return ToSmthRet(text, pos, count, [](const wchar16* theText, size_t length, wchar16* out) {
ToLower(theText, length, out);
- });
-}
-
-TUtf16String ToUpperRet(const TWtringBuf text, size_t pos, size_t count) {
+ });
+}
+
+TUtf16String ToUpperRet(const TWtringBuf text, size_t pos, size_t count) {
return ToSmthRet(text, pos, count, [](const wchar16* theText, size_t length, wchar16* out) {
ToUpper(theText, length, out);
- });
-}
-
-TUtf16String ToTitleRet(const TWtringBuf text, size_t pos, size_t count) {
+ });
+}
+
+TUtf16String ToTitleRet(const TWtringBuf text, size_t pos, size_t count) {
return ToSmthRet(text, pos, count, [](const wchar16* theText, size_t length, wchar16* out) {
ToTitle(theText, length, out);
- });
-}
-
+ });
+}
+
TUtf32String ToLowerRet(const TUtf32StringBuf text, size_t pos, size_t count) {
return ToSmthRet(text, pos, count, [](const wchar32* theText, size_t length, wchar32* out) {
ToLower(theText, length, out);
diff --git a/util/charset/wide.h b/util/charset/wide.h
index 81e7282f90..04e6928aab 100644
--- a/util/charset/wide.h
+++ b/util/charset/wide.h
@@ -5,12 +5,12 @@
#include "utf8.h"
#include "wide_specific.h"
-#include <util/generic/algorithm.h>
+#include <util/generic/algorithm.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>
#include <util/memory/tempbuf.h>
-#include <util/system/compiler.h>
-#include <util/system/cpu_id.h>
+#include <util/system/compiler.h>
+#include <util/system/cpu_id.h>
#include <util/system/yassert.h>
#include <cstring>
@@ -79,7 +79,7 @@ inline const wchar32* SkipSymbol(const wchar32* begin, const wchar32* end) noexc
}
inline wchar32 ReadSymbol(const wchar16* begin, const wchar16* end) noexcept {
- Y_ASSERT(begin < end);
+ Y_ASSERT(begin < end);
if (IsW16SurrogateLead(*begin)) {
if (begin + 1 < end && IsW16SurrogateTail(*(begin + 1)))
return ::NDetail::ReadSurrogatePair(begin);
@@ -99,10 +99,10 @@ inline wchar32 ReadSymbol(const wchar32* begin, const wchar32* end) noexcept {
//! presuming input data is either big enought of null terminated
inline wchar32 ReadSymbolAndAdvance(const wchar16*& begin) noexcept {
- Y_ASSERT(*begin);
+ Y_ASSERT(*begin);
if (IsW16SurrogateLead(begin[0])) {
if (IsW16SurrogateTail(begin[1])) {
- Y_ASSERT(begin[1] != 0);
+ Y_ASSERT(begin[1] != 0);
const wchar32 c = ::NDetail::ReadSurrogatePair(begin);
begin += 2;
return c;
@@ -123,7 +123,7 @@ inline wchar32 ReadSymbolAndAdvance(const wchar32*& begin) noexcept {
}
inline wchar32 ReadSymbolAndAdvance(const wchar16*& begin, const wchar16* end) noexcept {
- Y_ASSERT(begin < end);
+ Y_ASSERT(begin < end);
if (IsW16SurrogateLead(begin[0])) {
if (begin + 1 != end && IsW16SurrogateTail(begin[1])) {
const wchar32 c = ::NDetail::ReadSurrogatePair(begin);
@@ -140,7 +140,7 @@ inline wchar32 ReadSymbolAndAdvance(const wchar16*& begin, const wchar16* end) n
}
inline wchar32 ReadSymbolAndAdvance(const wchar32*& begin, const wchar32* end) noexcept {
- Y_ASSERT(begin < end);
+ Y_ASSERT(begin < end);
return *(begin++);
}
@@ -165,7 +165,7 @@ inline size_t WriteSymbol(wchar32 s, T& dest) noexcept {
}
inline bool WriteSymbol(wchar32 s, wchar16*& dest, const wchar16* destEnd) noexcept {
- Y_ASSERT(dest < destEnd);
+ Y_ASSERT(dest < destEnd);
if (s > 0xFFFF) {
if (s >= NUnicode::UnicodeInstancesLimit()) {
@@ -190,7 +190,7 @@ inline size_t WriteSymbol(wchar32 s, wchar32*& dest) noexcept {
}
inline bool WriteSymbol(wchar32 s, wchar32*& dest, const wchar32* destEnd) noexcept {
- Y_ASSERT(dest < destEnd);
+ Y_ASSERT(dest < destEnd);
*(dest++) = s;
@@ -200,7 +200,7 @@ inline bool WriteSymbol(wchar32 s, wchar32*& dest, const wchar32* destEnd) noexc
template <class T>
inline void ::NDetail::WriteSurrogatePair(wchar32 s, T& dest) noexcept {
const wchar32 LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
- Y_ASSERT(s > 0xFFFF && s < ::NUnicode::UnicodeInstancesLimit());
+ Y_ASSERT(s > 0xFFFF && s < ::NUnicode::UnicodeInstancesLimit());
wchar16 lead = LEAD_OFFSET + (static_cast<wchar16>(s >> 10));
wchar16 tail = 0xDC00 + static_cast<wchar16>(s & 0x3FF);
@@ -327,7 +327,7 @@ inline TUtf16String UTF8ToWide(const char* text, size_t len) {
size_t pos = UTF8ToWideImpl<robust>(text, len, w.begin(), written);
if (pos != len)
ythrow yexception() << "failed to decode UTF-8 string at pos " << pos << ::NDetail::InStringMsg(text, len);
- Y_ASSERT(w.size() >= written);
+ Y_ASSERT(w.size() >= written);
w.remove(written);
return w;
}
@@ -400,7 +400,7 @@ inline void WideToUTF8(const TCharType* text, size_t len, char* dest, size_t& wr
size_t runeLen;
for (const TCharType* cur = text; cur != last;) {
WriteUTF8Char(ReadSymbolAndAdvance(cur, last), runeLen, p);
- Y_ASSERT(runeLen <= 4);
+ Y_ASSERT(runeLen <= 4);
p += runeLen;
}
written = p - reinterpret_cast<unsigned char*>(dest);
@@ -414,7 +414,7 @@ inline TStringBuf WideToUTF8(const TWtringBuf src, TString& dst) {
dst.ReserveAndResize(WideToUTF8BufferSize(src.size()));
size_t written = 0;
WideToUTF8(src.data(), src.size(), dst.begin(), written);
- Y_ASSERT(dst.size() >= written);
+ Y_ASSERT(dst.size() >= written);
dst.remove(written);
return dst;
}
@@ -423,7 +423,7 @@ inline TString WideToUTF8(const wchar16* text, size_t len) {
TString s = TString::Uninitialized(WideToUTF8BufferSize(len));
size_t written = 0;
WideToUTF8(text, len, s.begin(), written);
- Y_ASSERT(s.size() >= written);
+ Y_ASSERT(s.size() >= written);
s.remove(written);
return s;
}
@@ -469,49 +469,49 @@ namespace NDetail {
return !(reinterpret_cast<TMachineWord>(pointer) & kMachineWordAlignmentMask);
}
- template <typename T>
+ template <typename T>
inline T* AlignToMachineWord(T* pointer) {
return reinterpret_cast<T*>(reinterpret_cast<TMachineWord>(pointer) & ~kMachineWordAlignmentMask);
}
- template <size_t size, typename CharacterType>
+ template <size_t size, typename CharacterType>
struct NonASCIIMask;
- template <>
- struct
- NonASCIIMask<4, wchar16> {
- static constexpr ui32 Value() {
- return 0xFF80FF80U;
- }
+ template <>
+ struct
+ NonASCIIMask<4, wchar16> {
+ static constexpr ui32 Value() {
+ return 0xFF80FF80U;
+ }
};
- template <>
- struct
- NonASCIIMask<4, char> {
- static constexpr ui32 Value() {
- return 0x80808080U;
- }
+ template <>
+ struct
+ NonASCIIMask<4, char> {
+ static constexpr ui32 Value() {
+ return 0x80808080U;
+ }
};
- template <>
- struct
- NonASCIIMask<8, wchar16> {
- static constexpr ui64 Value() {
- return 0xFF80FF80FF80FF80ULL;
- }
+ template <>
+ struct
+ NonASCIIMask<8, wchar16> {
+ static constexpr ui64 Value() {
+ return 0xFF80FF80FF80FF80ULL;
+ }
};
- template <>
- struct
- NonASCIIMask<8, char> {
- static constexpr ui64 Value() {
- return 0x8080808080808080ULL;
- }
+ template <>
+ struct
+ NonASCIIMask<8, char> {
+ static constexpr ui64 Value() {
+ return 0x8080808080808080ULL;
+ }
};
template <typename TChar>
inline bool DoIsStringASCIISlow(const TChar* first, const TChar* last) {
- using TUnsignedChar = std::make_unsigned_t<TChar>;
+ using TUnsignedChar = std::make_unsigned_t<TChar>;
Y_ASSERT(first <= last);
for (; first != last; ++first) {
if (static_cast<TUnsignedChar>(*first) > 0x7F) {
@@ -573,7 +573,7 @@ namespace NDetail {
int asciiMask = _mm_movemask_epi8(chunk);
if (asciiMask) {
return false;
- }
+ }
first += 16;
}
@@ -630,7 +630,7 @@ inline void Copy(const TChar1* first, size_t len, TChar2* result) {
//! and the family of template member functions: append, assign, insert, replace.
template <typename TStringType, typename TChar>
inline TStringType CopyTo(const TChar* first, const TChar* last) {
- Y_ASSERT(first <= last);
+ Y_ASSERT(first <= last);
TStringType str = TStringType::Uninitialized(last - first);
Copy(first, last, str.begin());
return str;
@@ -644,12 +644,12 @@ inline TStringType CopyTo(const TChar* s, size_t n) {
}
inline TString WideToASCII(const TWtringBuf w) {
- Y_ASSERT(IsStringASCII(w.begin(), w.end()));
+ Y_ASSERT(IsStringASCII(w.begin(), w.end()));
return CopyTo<TString>(w.begin(), w.end());
}
inline TUtf16String ASCIIToWide(const TStringBuf s) {
- Y_ASSERT(IsStringASCII(s.begin(), s.end()));
+ Y_ASSERT(IsStringASCII(s.begin(), s.end()));
return CopyTo<TUtf16String>(s.begin(), s.end());
}
@@ -663,7 +663,7 @@ inline bool IsSpace(const wchar16* s, size_t n) {
if (n == 0)
return false;
- Y_ASSERT(s);
+ Y_ASSERT(s);
const wchar16* const e = s + n;
for (const wchar16* p = s; p != e; ++p) {
@@ -674,7 +674,7 @@ inline bool IsSpace(const wchar16* s, size_t n) {
}
//! returns @c true if string contains whitespace characters only
-inline bool IsSpace(const TWtringBuf s) {
+inline bool IsSpace(const TWtringBuf s) {
return IsSpace(s.data(), s.length());
}
@@ -684,61 +684,61 @@ void Collapse(TUtf16String& w);
//! @return new length
size_t Collapse(wchar16* s, size_t n);
-//! Removes leading whitespace characters
-TWtringBuf StripLeft(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
-void StripLeft(TUtf16String& text);
-
-//! Removes trailing whitespace characters
-TWtringBuf StripRight(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
-void StripRight(TUtf16String& text);
-
-//! Removes leading and trailing whitespace characters
-TWtringBuf Strip(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
-void Strip(TUtf16String& text);
-
-/* Check if given word is lowercase/uppercase. Will return false if string contains any
- * non-alphabetical symbols. It is expected that `text` is a correct UTF-16 string.
- *
- * For example `IsLowerWord("hello")` will return `true`, when `IsLowerWord("hello there")` will
- * return false because of the space in the middle of the string. Empty string is also considered
- * lowercase.
- */
-bool IsLowerWord(const TWtringBuf text) noexcept;
-bool IsUpperWord(const TWtringBuf text) noexcept;
-
-/* Will check if given word starts with capital letter and the rest of the word is lowercase. Will
- * return `false` for empty string. See also `IsLowerWord`.
- */
-bool IsTitleWord(const TWtringBuf text) noexcept;
-
-/* Check if given string is lowercase/uppercase. Will return `true` if all alphabetic symbols are
- * in proper case, all other symbols are ignored. It is expected that `text` is a correct UTF-16
- * string.
- *
- * For example `IsLowerWord("hello")` will return `true` and `IsLowerWord("hello there")` will
- * also return true because. Empty string is also considered lowercase.
- *
- * NOTE: for any case where `IsLowerWord` returns `true` `IsLower` will also return `true`.
- */
-bool IsLower(const TWtringBuf text) noexcept;
-bool IsUpper(const TWtringBuf text) noexcept;
-
-/* Lowercase/uppercase given string inplace. Any alphabetic symbol will be converted to a proper
- * case, the rest of the symbols will be kept the same. It is expected that `text` is a correct
- * UTF-16 string.
- *
- * For example `ToLower("heLLo")` will return `"hello"`.
- *
- * @param text String to modify
- * @param pos Position of the first character to modify
- * @param count Length of the substring
- * @returns `true` if `text` was changed
- *
- * NOTE: `pos` and `count` are measured in `wchar16`, not in codepoints.
- */
-bool ToLower(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
-bool ToUpper(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
-
+//! Removes leading whitespace characters
+TWtringBuf StripLeft(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
+void StripLeft(TUtf16String& text);
+
+//! Removes trailing whitespace characters
+TWtringBuf StripRight(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
+void StripRight(TUtf16String& text);
+
+//! Removes leading and trailing whitespace characters
+TWtringBuf Strip(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
+void Strip(TUtf16String& text);
+
+/* Check if given word is lowercase/uppercase. Will return false if string contains any
+ * non-alphabetical symbols. It is expected that `text` is a correct UTF-16 string.
+ *
+ * For example `IsLowerWord("hello")` will return `true`, when `IsLowerWord("hello there")` will
+ * return false because of the space in the middle of the string. Empty string is also considered
+ * lowercase.
+ */
+bool IsLowerWord(const TWtringBuf text) noexcept;
+bool IsUpperWord(const TWtringBuf text) noexcept;
+
+/* Will check if given word starts with capital letter and the rest of the word is lowercase. Will
+ * return `false` for empty string. See also `IsLowerWord`.
+ */
+bool IsTitleWord(const TWtringBuf text) noexcept;
+
+/* Check if given string is lowercase/uppercase. Will return `true` if all alphabetic symbols are
+ * in proper case, all other symbols are ignored. It is expected that `text` is a correct UTF-16
+ * string.
+ *
+ * For example `IsLowerWord("hello")` will return `true` and `IsLowerWord("hello there")` will
+ * also return true because. Empty string is also considered lowercase.
+ *
+ * NOTE: for any case where `IsLowerWord` returns `true` `IsLower` will also return `true`.
+ */
+bool IsLower(const TWtringBuf text) noexcept;
+bool IsUpper(const TWtringBuf text) noexcept;
+
+/* Lowercase/uppercase given string inplace. Any alphabetic symbol will be converted to a proper
+ * case, the rest of the symbols will be kept the same. It is expected that `text` is a correct
+ * UTF-16 string.
+ *
+ * For example `ToLower("heLLo")` will return `"hello"`.
+ *
+ * @param text String to modify
+ * @param pos Position of the first character to modify
+ * @param count Length of the substring
+ * @returns `true` if `text` was changed
+ *
+ * NOTE: `pos` and `count` are measured in `wchar16`, not in codepoints.
+ */
+bool ToLower(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
+bool ToUpper(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
+
/* Lowercase/uppercase given string inplace. Any alphabetic symbol will be converted to a proper
* case, the rest of the symbols will be kept the same. It is expected that `text` is a correct
* UTF-32 string.
@@ -755,54 +755,54 @@ bool ToUpper(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::np
bool ToLower(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
bool ToUpper(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
-/* Titlecase first symbol and lowercase the rest, see `ToLower` for more details.
- */
-bool ToTitle(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
-
+/* Titlecase first symbol and lowercase the rest, see `ToLower` for more details.
+ */
+bool ToTitle(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
+
/* Titlecase first symbol and lowercase the rest, see `ToLower` for more details.
*/
bool ToTitle(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
-/* @param text Pointer to the string to modify
- * @param length Length of the string to modify
- * @param out Pointer to the character array to write to
- *
- * NOTE: [text, text+length) and [out, out+length) should not interleave.
- *
- * TODO(yazevnul): replace these functions with `bool(const TWtringBuf, const TArrayRef<wchar16>)`
- * overload.
- */
-bool ToLower(const wchar16* text, size_t length, wchar16* out) noexcept;
-bool ToUpper(const wchar16* text, size_t length, wchar16* out) noexcept;
-bool ToTitle(const wchar16* text, size_t length, wchar16* out) noexcept;
-
+/* @param text Pointer to the string to modify
+ * @param length Length of the string to modify
+ * @param out Pointer to the character array to write to
+ *
+ * NOTE: [text, text+length) and [out, out+length) should not interleave.
+ *
+ * TODO(yazevnul): replace these functions with `bool(const TWtringBuf, const TArrayRef<wchar16>)`
+ * overload.
+ */
+bool ToLower(const wchar16* text, size_t length, wchar16* out) noexcept;
+bool ToUpper(const wchar16* text, size_t length, wchar16* out) noexcept;
+bool ToTitle(const wchar16* text, size_t length, wchar16* out) noexcept;
+
bool ToLower(const wchar32* text, size_t length, wchar32* out) noexcept;
bool ToUpper(const wchar32* text, size_t length, wchar32* out) noexcept;
bool ToTitle(const wchar32* text, size_t length, wchar32* out) noexcept;
-/* @param text Pointer to the string to modify
- * @param length Length of the string to modify
- *
- * TODO(yazevnul): replace these functions with `bool(const TArrayRef<wchar16>)` overload.
- */
-bool ToLower(wchar16* text, size_t length) noexcept;
-bool ToUpper(wchar16* text, size_t length) noexcept;
-bool ToTitle(wchar16* text, size_t length) noexcept;
-
+/* @param text Pointer to the string to modify
+ * @param length Length of the string to modify
+ *
+ * TODO(yazevnul): replace these functions with `bool(const TArrayRef<wchar16>)` overload.
+ */
+bool ToLower(wchar16* text, size_t length) noexcept;
+bool ToUpper(wchar16* text, size_t length) noexcept;
+bool ToTitle(wchar16* text, size_t length) noexcept;
+
bool ToLower(wchar32* text, size_t length) noexcept;
bool ToUpper(wchar32* text, size_t length) noexcept;
bool ToTitle(wchar32* text, size_t length) noexcept;
-/* Convenience wrappers for `ToLower`, `ToUpper` and `ToTitle`.
- */
-TUtf16String ToLowerRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
-TUtf16String ToUpperRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
-TUtf16String ToTitleRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
-
-TUtf16String ToLowerRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
-TUtf16String ToUpperRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
-TUtf16String ToTitleRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
-
+/* Convenience wrappers for `ToLower`, `ToUpper` and `ToTitle`.
+ */
+TUtf16String ToLowerRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
+TUtf16String ToUpperRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
+TUtf16String ToTitleRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
+
+TUtf16String ToLowerRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
+TUtf16String ToUpperRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
+TUtf16String ToTitleRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
+
TUtf32String ToLowerRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
TUtf32String ToUpperRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
TUtf32String ToTitleRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
@@ -823,7 +823,7 @@ inline size_t CountWideChars(const wchar16* b, const wchar16* e) {
return count;
}
-inline size_t CountWideChars(const TWtringBuf str) {
+inline size_t CountWideChars(const TWtringBuf str) {
return CountWideChars(str.begin(), str.end());
}
@@ -838,6 +838,6 @@ inline bool IsValidUTF16(const wchar16* b, const wchar16* e) {
return true;
}
-inline bool IsValidUTF16(const TWtringBuf str) {
+inline bool IsValidUTF16(const TWtringBuf str) {
return IsValidUTF16(str.begin(), str.end());
}
diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp
index 3d176b61c1..d8f3233e73 100644
--- a/util/charset/wide_ut.cpp
+++ b/util/charset/wide_ut.cpp
@@ -592,20 +592,20 @@ class TWideUtilTest: public TTestBase {
UNIT_TEST(TestCountWideChars);
UNIT_TEST(TestIsValidUTF16);
UNIT_TEST(TestIsStringASCII);
- UNIT_TEST(TestIsLowerWordStr);
- UNIT_TEST(TestIsUpperWordStr);
- UNIT_TEST(TestIsTitleStr);
- UNIT_TEST(TestIsLowerStr);
- UNIT_TEST(TestIsUpperStr);
- UNIT_TEST(TestToLowerStr);
- UNIT_TEST(TestToUpperStr);
- UNIT_TEST(TestToTitleStr);
+ UNIT_TEST(TestIsLowerWordStr);
+ UNIT_TEST(TestIsUpperWordStr);
+ UNIT_TEST(TestIsTitleStr);
+ UNIT_TEST(TestIsLowerStr);
+ UNIT_TEST(TestIsUpperStr);
+ UNIT_TEST(TestToLowerStr);
+ UNIT_TEST(TestToUpperStr);
+ UNIT_TEST(TestToTitleStr);
UNIT_TEST_SUITE_END();
public:
void TestCollapse() {
TUtf16String s;
- s.append(ws, Y_ARRAY_SIZE(ws)).append(3, 'a').append(ws, Y_ARRAY_SIZE(ws)).append(3, 'b').append(ws, Y_ARRAY_SIZE(ws));
+ s.append(ws, Y_ARRAY_SIZE(ws)).append(3, 'a').append(ws, Y_ARRAY_SIZE(ws)).append(3, 'b').append(ws, Y_ARRAY_SIZE(ws));
Collapse(s);
UNIT_ASSERT(s == ASCIIToWide(" aaa bbb "));
{
@@ -664,7 +664,7 @@ public:
void TestCollapseBuffer() {
TUtf16String s;
- s.append(ws, Y_ARRAY_SIZE(ws)).append(3, 'a').append(ws, Y_ARRAY_SIZE(ws)).append(3, 'b').append(ws, Y_ARRAY_SIZE(ws));
+ s.append(ws, Y_ARRAY_SIZE(ws)).append(3, 'a').append(ws, Y_ARRAY_SIZE(ws)).append(3, 'b').append(ws, Y_ARRAY_SIZE(ws));
size_t n = Collapse(s.begin(), s.size());
s.resize(n);
UNIT_ASSERT(s == ASCIIToWide(" aaa bbb "));
@@ -735,40 +735,40 @@ public:
Strip(s);
UNIT_ASSERT(s == TUtf16String());
- StripLeft(s);
- UNIT_ASSERT(s == TUtf16String());
- StripRight(s);
- UNIT_ASSERT(s == TUtf16String());
+ StripLeft(s);
+ UNIT_ASSERT(s == TUtf16String());
+ StripRight(s);
+ UNIT_ASSERT(s == TUtf16String());
s = ASCIIToWide(" \t\r\n");
Strip(s);
UNIT_ASSERT(s == TUtf16String());
- s = ASCIIToWide(" \t\r\n");
- StripLeft(s);
- UNIT_ASSERT(s == TUtf16String());
- s = ASCIIToWide(" \t\r\n");
- StripRight(s);
- UNIT_ASSERT(s == TUtf16String());
+ s = ASCIIToWide(" \t\r\n");
+ StripLeft(s);
+ UNIT_ASSERT(s == TUtf16String());
+ s = ASCIIToWide(" \t\r\n");
+ StripRight(s);
+ UNIT_ASSERT(s == TUtf16String());
s = ASCIIToWide("\t\f\va \r\n");
Strip(s);
UNIT_ASSERT(s == ASCIIToWide("a"));
- s = ASCIIToWide("\t\f\va \r\n");
- StripLeft(s);
- UNIT_ASSERT(s == ASCIIToWide("a \r\n"));
- s = ASCIIToWide("\t\f\va \r\n");
- StripRight(s);
- UNIT_ASSERT(s == ASCIIToWide("\t\f\va"));
+ s = ASCIIToWide("\t\f\va \r\n");
+ StripLeft(s);
+ UNIT_ASSERT(s == ASCIIToWide("a \r\n"));
+ s = ASCIIToWide("\t\f\va \r\n");
+ StripRight(s);
+ UNIT_ASSERT(s == ASCIIToWide("\t\f\va"));
s = ASCIIToWide("\r\na\r\nb\t\tc\r\n");
Strip(s);
UNIT_ASSERT(s == ASCIIToWide("a\r\nb\t\tc"));
- s = ASCIIToWide("\r\na\r\nb\t\tc\r\n");
- StripLeft(s);
- UNIT_ASSERT(s == ASCIIToWide("a\r\nb\t\tc\r\n"));
- s = ASCIIToWide("\r\na\r\nb\t\tc\r\n");
- StripRight(s);
- UNIT_ASSERT(s == ASCIIToWide("\r\na\r\nb\t\tc"));
+ s = ASCIIToWide("\r\na\r\nb\t\tc\r\n");
+ StripLeft(s);
+ UNIT_ASSERT(s == ASCIIToWide("a\r\nb\t\tc\r\n"));
+ s = ASCIIToWide("\r\na\r\nb\t\tc\r\n");
+ StripRight(s);
+ UNIT_ASSERT(s == ASCIIToWide("\r\na\r\nb\t\tc"));
const TUtf16String w(ASCIIToWide("a b"));
s = w;
@@ -777,24 +777,24 @@ public:
#ifndef TSTRING_IS_STD_STRING
UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all
#endif
- s = w;
- StripLeft(s);
- UNIT_ASSERT(s == w);
+ s = w;
+ StripLeft(s);
+ UNIT_ASSERT(s == w);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all
+ UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all
#endif
- s = w;
- StripRight(s);
- UNIT_ASSERT(s == w);
+ s = w;
+ StripRight(s);
+ UNIT_ASSERT(s == w);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all
+ UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all
#endif
}
void TestIsSpace() {
UNIT_ASSERT(!IsSpace(TUtf16String()));
- UNIT_ASSERT(IsSpace(ws, Y_ARRAY_SIZE(ws)));
+ UNIT_ASSERT(IsSpace(ws, Y_ARRAY_SIZE(ws)));
TUtf16String w;
w.assign(ws, Y_ARRAY_SIZE(ws)).append(TUtf16String(1, '!'));
@@ -983,760 +983,760 @@ public:
}
}
}
-
- void TestIsLowerWordStr() {
- UNIT_ASSERT(IsLowerWord(TWtringBuf()));
- UNIT_ASSERT(IsLowerWord(UTF8ToWide("")));
- UNIT_ASSERT(IsLowerWord(UTF8ToWide("test")));
+
+ void TestIsLowerWordStr() {
+ UNIT_ASSERT(IsLowerWord(TWtringBuf()));
+ UNIT_ASSERT(IsLowerWord(UTF8ToWide("")));
+ UNIT_ASSERT(IsLowerWord(UTF8ToWide("test")));
UNIT_ASSERT(IsLowerWord(UTF8ToWide("тест"))); // "тест" is "test" in russian (cyrrilic)
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тест тест")));
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тест100500")));
-
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("Test")));
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("tesT")));
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("tEst")));
-
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("Тест")));
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("теСт")));
- UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тесТ")));
- }
-
- void TestIsUpperWordStr() {
- UNIT_ASSERT(IsUpperWord(TWtringBuf()));
- UNIT_ASSERT(IsUpperWord(UTF8ToWide("")));
- UNIT_ASSERT(IsUpperWord(UTF8ToWide("TEST")));
- UNIT_ASSERT(IsUpperWord(UTF8ToWide("ТЕСТ")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тест тест")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тест100500")));
-
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("Test")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("tesT")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("tEst")));
-
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("Тест")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("теСт")));
- UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тесТ")));
- }
-
- void TestIsTitleStr() {
- UNIT_ASSERT(!IsTitleWord(TWtringBuf()));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("t")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("й")));
- UNIT_ASSERT(IsTitleWord(UTF8ToWide("T")));
- UNIT_ASSERT(IsTitleWord(UTF8ToWide("Й")));
- UNIT_ASSERT(IsTitleWord(UTF8ToWide("Test")));
- UNIT_ASSERT(IsTitleWord(UTF8ToWide("Тест")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тест тест")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тест100500")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("Тест тест")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("Тест100500")));
-
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("tesT")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("tEst")));
-
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("теСт")));
- UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тесТ")));
- }
-
- void TestIsLowerStr() {
- UNIT_ASSERT(IsLower(TWtringBuf()));
- UNIT_ASSERT(IsLower(UTF8ToWide("")));
- UNIT_ASSERT(IsLower(UTF8ToWide("test")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тест тест")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тест100500")));
+
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("Test")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("tesT")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("tEst")));
+
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("Тест")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("теСт")));
+ UNIT_ASSERT(!IsLowerWord(UTF8ToWide("тесТ")));
+ }
+
+ void TestIsUpperWordStr() {
+ UNIT_ASSERT(IsUpperWord(TWtringBuf()));
+ UNIT_ASSERT(IsUpperWord(UTF8ToWide("")));
+ UNIT_ASSERT(IsUpperWord(UTF8ToWide("TEST")));
+ UNIT_ASSERT(IsUpperWord(UTF8ToWide("ТЕСТ")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тест тест")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тест100500")));
+
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("Test")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("tesT")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("tEst")));
+
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("Тест")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("теСт")));
+ UNIT_ASSERT(!IsUpperWord(UTF8ToWide("тесТ")));
+ }
+
+ void TestIsTitleStr() {
+ UNIT_ASSERT(!IsTitleWord(TWtringBuf()));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("t")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("й")));
+ UNIT_ASSERT(IsTitleWord(UTF8ToWide("T")));
+ UNIT_ASSERT(IsTitleWord(UTF8ToWide("Й")));
+ UNIT_ASSERT(IsTitleWord(UTF8ToWide("Test")));
+ UNIT_ASSERT(IsTitleWord(UTF8ToWide("Тест")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тест тест")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тест100500")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("Тест тест")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("Тест100500")));
+
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("tesT")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("tEst")));
+
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("теСт")));
+ UNIT_ASSERT(!IsTitleWord(UTF8ToWide("тесТ")));
+ }
+
+ void TestIsLowerStr() {
+ UNIT_ASSERT(IsLower(TWtringBuf()));
+ UNIT_ASSERT(IsLower(UTF8ToWide("")));
+ UNIT_ASSERT(IsLower(UTF8ToWide("test")));
UNIT_ASSERT(IsLower(UTF8ToWide("тест"))); // "тест" is "test" in russian (cyrrilic)
- UNIT_ASSERT(IsLower(UTF8ToWide("тест тест")));
- UNIT_ASSERT(IsLower(UTF8ToWide("тест100500")));
-
- UNIT_ASSERT(!IsLower(UTF8ToWide("Test")));
- UNIT_ASSERT(!IsLower(UTF8ToWide("tesT")));
- UNIT_ASSERT(!IsLower(UTF8ToWide("tEst")));
-
- UNIT_ASSERT(!IsLower(UTF8ToWide("Тест")));
- UNIT_ASSERT(!IsLower(UTF8ToWide("теСт")));
- UNIT_ASSERT(!IsLower(UTF8ToWide("тесТ")));
- }
-
- void TestIsUpperStr() {
- UNIT_ASSERT(IsUpper(TWtringBuf()));
- UNIT_ASSERT(IsUpper(UTF8ToWide("")));
- UNIT_ASSERT(IsUpper(UTF8ToWide("TEST")));
- UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ")));
- UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ ТЕСТ")));
- UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ100500")));
-
- UNIT_ASSERT(!IsUpper(UTF8ToWide("Test")));
- UNIT_ASSERT(!IsUpper(UTF8ToWide("tesT")));
- UNIT_ASSERT(!IsUpper(UTF8ToWide("tEst")));
-
- UNIT_ASSERT(!IsUpper(UTF8ToWide("Тест")));
- UNIT_ASSERT(!IsUpper(UTF8ToWide("теСт")));
- UNIT_ASSERT(!IsUpper(UTF8ToWide("тесТ")));
- }
-
- void TestToLowerStr() {
- // In these test and test for `ToUpper` and `ToTitle` we are checking that string keep
- // pointing to the same piece of memory we are doing it the following way:
- //
- // TUtf16String s = ...
- // const auto copy = s;
- // ...
- // UNIT_ASSERT(s.data() == copy.data())
- //
- // It saves us a couple lines (we are reusing `copy` later) and if one day `TString` will
- // become non-refcounted we'll need to rewrite it to something like:
- //
- // TUtf16String s = ...
- // const auto* const data = s.data();
- // const auto length = s.length();
- // ...
- // UNIT_ASSERT(s.data() == data);
- // UNIT_ASSERT(s.length() == length);
- {
- TUtf16String s;
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String lower;
-
- UNIT_ASSERT(!ToLower(s));
- UNIT_ASSERT(s == lower);
+ UNIT_ASSERT(IsLower(UTF8ToWide("тест тест")));
+ UNIT_ASSERT(IsLower(UTF8ToWide("тест100500")));
+
+ UNIT_ASSERT(!IsLower(UTF8ToWide("Test")));
+ UNIT_ASSERT(!IsLower(UTF8ToWide("tesT")));
+ UNIT_ASSERT(!IsLower(UTF8ToWide("tEst")));
+
+ UNIT_ASSERT(!IsLower(UTF8ToWide("Тест")));
+ UNIT_ASSERT(!IsLower(UTF8ToWide("теСт")));
+ UNIT_ASSERT(!IsLower(UTF8ToWide("тесТ")));
+ }
+
+ void TestIsUpperStr() {
+ UNIT_ASSERT(IsUpper(TWtringBuf()));
+ UNIT_ASSERT(IsUpper(UTF8ToWide("")));
+ UNIT_ASSERT(IsUpper(UTF8ToWide("TEST")));
+ UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ")));
+ UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ ТЕСТ")));
+ UNIT_ASSERT(IsUpper(UTF8ToWide("ТЕСТ100500")));
+
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("Test")));
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("tesT")));
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("tEst")));
+
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("Тест")));
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("теСт")));
+ UNIT_ASSERT(!IsUpper(UTF8ToWide("тесТ")));
+ }
+
+ void TestToLowerStr() {
+ // In these test and test for `ToUpper` and `ToTitle` we are checking that string keep
+ // pointing to the same piece of memory we are doing it the following way:
+ //
+ // TUtf16String s = ...
+ // const auto copy = s;
+ // ...
+ // UNIT_ASSERT(s.data() == copy.data())
+ //
+ // It saves us a couple lines (we are reusing `copy` later) and if one day `TString` will
+ // become non-refcounted we'll need to rewrite it to something like:
+ //
+ // TUtf16String s = ...
+ // const auto* const data = s.data();
+ // const auto length = s.length();
+ // ...
+ // UNIT_ASSERT(s.data() == data);
+ // UNIT_ASSERT(s.length() == length);
+ {
+ TUtf16String s;
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String lower;
+
+ UNIT_ASSERT(!ToLower(s));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- TUtf16String s = UTF8ToWide("");
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String lower;
-
- UNIT_ASSERT(!ToLower(s));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ TUtf16String s = UTF8ToWide("");
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String lower;
+
+ UNIT_ASSERT(!ToLower(s));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- TUtf16String s;
- const auto copy = s;
- const TUtf16String lower;
-
- UNIT_ASSERT(!ToLower(s, 100500));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ TUtf16String s;
+ const auto copy = s;
+ const TUtf16String lower;
+
+ UNIT_ASSERT(!ToLower(s, 100500));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToLowerRet(copy, 100500) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500) == lower);
- }
- {
- TUtf16String s;
- const auto copy = s;
- const TUtf16String lower;
-
- UNIT_ASSERT(!ToLower(s, 100500, 1111));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy, 100500) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500) == lower);
+ }
+ {
+ TUtf16String s;
+ const auto copy = s;
+ const TUtf16String lower;
+
+ UNIT_ASSERT(!ToLower(s, 100500, 1111));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToLowerRet(copy, 100500, 1111) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500, 1111) == lower);
- }
- {
- auto s = UTF8ToWide("Й");
- auto writableCopy = s;
- const auto copy = s;
- const auto lower = UTF8ToWide("й");
-
- UNIT_ASSERT(ToLower(s));
- UNIT_ASSERT(s == lower);
-
- UNIT_ASSERT(ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- auto s = UTF8ToWide("й");
- auto writableCopy = s;
- const auto copy = s;
- const auto lower = UTF8ToWide("й");
-
- UNIT_ASSERT(!ToLower(s));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy, 100500, 1111) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500, 1111) == lower);
+ }
+ {
+ auto s = UTF8ToWide("Й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto lower = UTF8ToWide("й");
+
+ UNIT_ASSERT(ToLower(s));
+ UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ auto s = UTF8ToWide("й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto lower = UTF8ToWide("й");
+
+ UNIT_ASSERT(!ToLower(s));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- auto s = UTF8ToWide("тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto lower = UTF8ToWide("тест");
-
- UNIT_ASSERT(!ToLower(s));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ auto s = UTF8ToWide("тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto lower = UTF8ToWide("тест");
+
+ UNIT_ASSERT(!ToLower(s));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- auto s = UTF8ToWide("Тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto lower = UTF8ToWide("тест");
-
- UNIT_ASSERT(ToLower(s));
- UNIT_ASSERT(s == lower);
-
- UNIT_ASSERT(ToLower(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLower(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == lower);
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- TUtf16String s = UTF8ToWide("тЕст");
- const auto copy = s;
- const auto lower = UTF8ToWide("тест");
-
- UNIT_ASSERT(ToLower(s));
- UNIT_ASSERT(s == UTF8ToWide("тест"));
-
- UNIT_ASSERT(ToLowerRet(copy) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
- }
- {
- auto s = UTF8ToWide("тЕст");
- const auto copy = s;
- const auto lower = UTF8ToWide("тЕст");
-
- UNIT_ASSERT(!ToLower(s, 2));
- UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(!ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ auto s = UTF8ToWide("Тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto lower = UTF8ToWide("тест");
+
+ UNIT_ASSERT(ToLower(s));
+ UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(ToLower(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLower(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ TUtf16String s = UTF8ToWide("тЕст");
+ const auto copy = s;
+ const auto lower = UTF8ToWide("тест");
+
+ UNIT_ASSERT(ToLower(s));
+ UNIT_ASSERT(s == UTF8ToWide("тест"));
+
+ UNIT_ASSERT(ToLowerRet(copy) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy)) == lower);
+ }
+ {
+ auto s = UTF8ToWide("тЕст");
+ const auto copy = s;
+ const auto lower = UTF8ToWide("тЕст");
+
+ UNIT_ASSERT(!ToLower(s, 2));
+ UNIT_ASSERT(s == lower);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToLowerRet(copy, 2) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 2) == lower);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto lower = UTF8ToWide("тест");
-
- UNIT_ASSERT(ToLower(s, 2));
- UNIT_ASSERT(s == lower);
-
- UNIT_ASSERT(ToLowerRet(copy, 2) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 2) == lower);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto lower = UTF8ToWide("теСт");
-
- UNIT_ASSERT(!ToLower(s, 3, 1));
- UNIT_ASSERT(s == copy);
+
+ UNIT_ASSERT(ToLowerRet(copy, 2) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 2) == lower);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto lower = UTF8ToWide("тест");
+
+ UNIT_ASSERT(ToLower(s, 2));
+ UNIT_ASSERT(s == lower);
+
+ UNIT_ASSERT(ToLowerRet(copy, 2) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 2) == lower);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto lower = UTF8ToWide("теСт");
+
+ UNIT_ASSERT(!ToLower(s, 3, 1));
+ UNIT_ASSERT(s == copy);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToLowerRet(copy, 3, 1) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 1) == lower);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto lower = UTF8ToWide("теСт");
-
- UNIT_ASSERT(!ToLower(s, 3, 100500));
- UNIT_ASSERT(s == copy);
+
+ UNIT_ASSERT(ToLowerRet(copy, 3, 1) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 1) == lower);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto lower = UTF8ToWide("теСт");
+
+ UNIT_ASSERT(!ToLower(s, 3, 100500));
+ UNIT_ASSERT(s == copy);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToLowerRet(copy, 3, 100500) == lower);
- UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 100500) == lower);
- }
- }
-
- void TestToUpperStr() {
- {
- TUtf16String s;
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String upper;
-
- UNIT_ASSERT(!ToUpper(s));
- UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToLowerRet(copy, 3, 100500) == lower);
+ UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 100500) == lower);
+ }
+ }
+
+ void TestToUpperStr() {
+ {
+ TUtf16String s;
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String upper;
+
+ UNIT_ASSERT(!ToUpper(s));
+ UNIT_ASSERT(s == upper);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("");
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String upper;
-
- UNIT_ASSERT(!ToUpper(s));
- UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("");
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String upper;
+
+ UNIT_ASSERT(!ToUpper(s));
+ UNIT_ASSERT(s == upper);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- TUtf16String s;
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String upper;
-
- UNIT_ASSERT(!ToUpper(s, 100500));
- UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ TUtf16String s;
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String upper;
+
+ UNIT_ASSERT(!ToUpper(s, 100500));
+ UNIT_ASSERT(s == upper);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy, 100500) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 100500) == upper);
- }
- {
- TUtf16String s;
- const auto copy = s;
- const TUtf16String upper;
-
- UNIT_ASSERT(!ToUpper(s, 100500, 1111));
- UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy, 100500) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 100500) == upper);
+ }
+ {
+ TUtf16String s;
+ const auto copy = s;
+ const TUtf16String upper;
+
+ UNIT_ASSERT(!ToUpper(s, 100500, 1111));
+ UNIT_ASSERT(s == upper);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToUpperRet(copy, 100500, 1111) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 100500, 1111) == upper);
- }
- {
- auto s = UTF8ToWide("й");
- auto writableCopy = s;
- const auto copy = s;
- const auto upper = UTF8ToWide("Й");
-
- UNIT_ASSERT(ToUpper(s));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("Й");
- auto writableCopy = s;
- const auto copy = s;
- const auto upper = UTF8ToWide("Й");
-
- UNIT_ASSERT(!ToUpper(s));
- UNIT_ASSERT(s == copy);
+
+ UNIT_ASSERT(ToUpperRet(copy, 100500, 1111) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 100500, 1111) == upper);
+ }
+ {
+ auto s = UTF8ToWide("й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto upper = UTF8ToWide("Й");
+
+ UNIT_ASSERT(ToUpper(s));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("Й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto upper = UTF8ToWide("Й");
+
+ UNIT_ASSERT(!ToUpper(s));
+ UNIT_ASSERT(s == copy);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto upper = UTF8ToWide("ТЕСТ");
-
- UNIT_ASSERT(ToUpper(s));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("Тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto upper = UTF8ToWide("ТЕСТ");
-
- UNIT_ASSERT(ToUpper(s));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("тЕст");
- auto writableCopy = s;
- const auto copy = s;
- const auto upper = UTF8ToWide("ТЕСТ");
-
- UNIT_ASSERT(ToUpper(s));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == upper);
-
- UNIT_ASSERT(ToUpperRet(copy) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
- }
- {
- auto s = UTF8ToWide("тЕст");
- const auto copy = s;
- const auto upper = UTF8ToWide("тЕСТ");
-
- UNIT_ASSERT(ToUpper(s, 2));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpperRet(copy, 2) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 2) == upper);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto upper = UTF8ToWide("теСТ");
-
- UNIT_ASSERT(ToUpper(s, 2));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpperRet(copy, 2) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 2) == upper);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto upper = UTF8ToWide("теСТ");
-
- UNIT_ASSERT(ToUpper(s, 3, 1));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpperRet(copy, 3, 1) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 3, 1) == upper);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto upper = UTF8ToWide("теСТ");
-
- UNIT_ASSERT(ToUpper(s, 3, 100500));
- UNIT_ASSERT(s == upper);
-
- UNIT_ASSERT(ToUpperRet(copy, 3, 100500) == upper);
- UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 3, 100500) == upper);
- }
- }
-
- void TestToTitleStr() {
- {
- TUtf16String s;
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String title;
-
- UNIT_ASSERT(!ToTitle(s));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(!ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto upper = UTF8ToWide("ТЕСТ");
+
+ UNIT_ASSERT(ToUpper(s));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("Тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto upper = UTF8ToWide("ТЕСТ");
+
+ UNIT_ASSERT(ToUpper(s));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("тЕст");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto upper = UTF8ToWide("ТЕСТ");
+
+ UNIT_ASSERT(ToUpper(s));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpper(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpper(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy)) == upper);
+ }
+ {
+ auto s = UTF8ToWide("тЕст");
+ const auto copy = s;
+ const auto upper = UTF8ToWide("тЕСТ");
+
+ UNIT_ASSERT(ToUpper(s, 2));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy, 2) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 2) == upper);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto upper = UTF8ToWide("теСТ");
+
+ UNIT_ASSERT(ToUpper(s, 2));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy, 2) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 2) == upper);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto upper = UTF8ToWide("теСТ");
+
+ UNIT_ASSERT(ToUpper(s, 3, 1));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy, 3, 1) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 3, 1) == upper);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto upper = UTF8ToWide("теСТ");
+
+ UNIT_ASSERT(ToUpper(s, 3, 100500));
+ UNIT_ASSERT(s == upper);
+
+ UNIT_ASSERT(ToUpperRet(copy, 3, 100500) == upper);
+ UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 3, 100500) == upper);
+ }
+ }
+
+ void TestToTitleStr() {
+ {
+ TUtf16String s;
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String title;
+
+ UNIT_ASSERT(!ToTitle(s));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("");
- auto writableCopy = s;
- const auto copy = s;
- const TUtf16String title;
-
- UNIT_ASSERT(!ToTitle(s));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("");
+ auto writableCopy = s;
+ const auto copy = s;
+ const TUtf16String title;
+
+ UNIT_ASSERT(!ToTitle(s));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- TUtf16String s;
- const auto copy = s;
- const TUtf16String title;
-
- UNIT_ASSERT(!ToTitle(s, 100500));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ TUtf16String s;
+ const auto copy = s;
+ const TUtf16String title;
+
+ UNIT_ASSERT(!ToTitle(s, 100500));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- TUtf16String s;
- const auto copy = s;
- const TUtf16String title;
-
- UNIT_ASSERT(!ToTitle(s, 100500, 1111));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ TUtf16String s;
+ const auto copy = s;
+ const TUtf16String title;
+
+ UNIT_ASSERT(!ToTitle(s, 100500, 1111));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("й");
- auto writableCopy = s;
- const auto copy = s;
- const auto title = UTF8ToWide("Й");
-
- UNIT_ASSERT(ToTitle(s));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("Й");
- auto writableCopy = s;
- const auto copy = s;
- const auto title = UTF8ToWide("Й");
-
- UNIT_ASSERT(!ToTitle(s));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto title = UTF8ToWide("Й");
+
+ UNIT_ASSERT(ToTitle(s));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("Й");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto title = UTF8ToWide("Й");
+
+ UNIT_ASSERT(!ToTitle(s));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto title = UTF8ToWide("Тест");
-
- UNIT_ASSERT(ToTitle(s));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("Тест");
- auto writableCopy = s;
- const auto copy = s;
- const auto title = UTF8ToWide("Тест");
-
- UNIT_ASSERT(!ToTitle(s));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto title = UTF8ToWide("Тест");
+
+ UNIT_ASSERT(ToTitle(s));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("Тест");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto title = UTF8ToWide("Тест");
+
+ UNIT_ASSERT(!ToTitle(s));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("тЕст");
- auto writableCopy = s;
- const auto copy = s;
- const auto title = UTF8ToWide("Тест");
-
- UNIT_ASSERT(ToTitle(s));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
- UNIT_ASSERT(writableCopy == title);
-
- UNIT_ASSERT(ToTitleRet(copy) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
- }
- {
- auto s = UTF8ToWide("тЕст");
- const auto copy = s;
- const auto title = UTF8ToWide("тЕСт");
-
- UNIT_ASSERT(ToTitle(s, 2));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitleRet(copy, 2) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 2) == title);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto title = UTF8ToWide("теСт");
-
- UNIT_ASSERT(!ToTitle(s, 2));
- UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(!ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("тЕст");
+ auto writableCopy = s;
+ const auto copy = s;
+ const auto title = UTF8ToWide("Тест");
+
+ UNIT_ASSERT(ToTitle(s));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitle(writableCopy.Detach(), writableCopy.size()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitle(copy.data(), copy.size(), writableCopy.Detach()));
+ UNIT_ASSERT(writableCopy == title);
+
+ UNIT_ASSERT(ToTitleRet(copy) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title);
+ }
+ {
+ auto s = UTF8ToWide("тЕст");
+ const auto copy = s;
+ const auto title = UTF8ToWide("тЕСт");
+
+ UNIT_ASSERT(ToTitle(s, 2));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitleRet(copy, 2) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 2) == title);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto title = UTF8ToWide("теСт");
+
+ UNIT_ASSERT(!ToTitle(s, 2));
+ UNIT_ASSERT(s == title);
#ifndef TSTRING_IS_STD_STRING
- UNIT_ASSERT(s.data() == copy.data());
+ UNIT_ASSERT(s.data() == copy.data());
#endif
-
- UNIT_ASSERT(ToTitleRet(copy, 2) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 2) == title);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
- const auto title = UTF8ToWide("теСТ");
-
- UNIT_ASSERT(ToTitle(s, 3, 1));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitleRet(copy, 3, 1) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 3, 1) == title);
- }
- {
- auto s = UTF8ToWide("теСт");
- const auto copy = s;
+
+ UNIT_ASSERT(ToTitleRet(copy, 2) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 2) == title);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
+ const auto title = UTF8ToWide("теСТ");
+
+ UNIT_ASSERT(ToTitle(s, 3, 1));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitleRet(copy, 3, 1) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 3, 1) == title);
+ }
+ {
+ auto s = UTF8ToWide("теСт");
+ const auto copy = s;
const auto title = UTF8ToWide("теСТ");
-
- UNIT_ASSERT(ToTitle(s, 3, 100500));
- UNIT_ASSERT(s == title);
-
- UNIT_ASSERT(ToTitleRet(copy, 3, 100500) == title);
- UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 3, 100500) == title);
- }
- }
+
+ UNIT_ASSERT(ToTitle(s, 3, 100500));
+ UNIT_ASSERT(s == title);
+
+ UNIT_ASSERT(ToTitleRet(copy, 3, 100500) == title);
+ UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 3, 100500) == title);
+ }
+ }
};
UNIT_TEST_SUITE_REGISTRATION(TWideUtilTest);