From 1ff544358cca129bee1b9f60d1cc396751c2e1f6 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 29 Sep 2021 15:43:08 +0200 Subject: Fixed signed/unsigned mismatched warnings from GCC --- zencore/string.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zencore/string.cpp') diff --git a/zencore/string.cpp b/zencore/string.cpp index 6dcdc9542..df387dc3c 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -76,7 +76,7 @@ FilepathFindExtension(const std::string_view& Path, const char* ExtensionToMatch // Look for extension introducer ('.') - for (size_t i = PathLen - 1; i >= 0; --i) + for (ssize_t i = PathLen - 1; i >= 0; --i) { if (Path[i] == '.') return Path.data() + i; -- cgit v1.2.3 From 2cebe6fca3655a4e33baf96745438e8c3c552b13 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 29 Sep 2021 16:54:24 +0200 Subject: There is no ssize_t on Windows --- zencore/string.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zencore/string.cpp') diff --git a/zencore/string.cpp b/zencore/string.cpp index df387dc3c..4bf0378b2 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -76,7 +76,7 @@ FilepathFindExtension(const std::string_view& Path, const char* ExtensionToMatch // Look for extension introducer ('.') - for (ssize_t i = PathLen - 1; i >= 0; --i) + for (int64_t i = PathLen - 1; i >= 0; --i) { if (Path[i] == '.') return Path.data() + i; -- cgit v1.2.3 From 859e08f3f0e261148e5de88701243b1044010058 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Mon, 11 Oct 2021 11:25:43 +0200 Subject: Replaced use of std::u16string* with std::wstring* --- zencore/string.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'zencore/string.cpp') diff --git a/zencore/string.cpp b/zencore/string.cpp index efa84ea73..7acdc16f0 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -30,6 +30,17 @@ utf16to8_impl(u16bit_iterator StartIt, u16bit_iterator EndIt, ::zen::StringBuild } } +template +void +utf32to8_impl(u32bit_iterator StartIt, u32bit_iterator EndIt, ::zen::StringBuilderBase& OutString) +{ + for (; StartIt != EndIt; ++StartIt) + { + wchar_t cp = *StartIt; + OutString.AppendCodepoint(cp); + } +} + ////////////////////////////////////////////////////////////////////////// namespace zen { @@ -164,26 +175,24 @@ Utf8ToWide(const std::u8string_view& Str8, WideStringBuilderBase& OutString) void WideToUtf8(const wchar_t* Wstr, StringBuilderBase& OutString) { - WideToUtf8(std::u16string_view{(char16_t*)Wstr}, OutString); + WideToUtf8(std::wstring_view{Wstr}, OutString); } void WideToUtf8(const std::wstring_view& Wstr, StringBuilderBase& OutString) { - WideToUtf8(std::u16string_view{(char16_t*)Wstr.data(), Wstr.size()}, OutString); -} - -void -WideToUtf8(const std::u16string_view& Wstr, StringBuilderBase& OutString) -{ +#if ZEN_SIZEOF_WCHAR_T == 2 utf16to8_impl(begin(Wstr), end(Wstr), OutString); +#else + utf32to8_impl(begin(Wstr), end(Wstr), OutString); +#endif } std::string WideToUtf8(const wchar_t* Wstr) { ExtendableStringBuilder<128> String; - WideToUtf8(std::u16string_view{(char16_t*)Wstr}, String); + WideToUtf8(std::wstring_view{Wstr}, String); return String.c_str(); } @@ -192,7 +201,7 @@ std::string WideToUtf8(const std::wstring_view Wstr) { ExtendableStringBuilder<128> String; - WideToUtf8(std::u16string_view{(char16_t*)Wstr.data(), Wstr.size()}, String); + WideToUtf8(std::wstring_view{Wstr.data(), Wstr.size()}, String); return String.c_str(); } -- cgit v1.2.3 From c80bc1e4b2ea10c2e871091f996d19a18218f231 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Mon, 25 Oct 2021 09:39:31 +0200 Subject: Cross-platform string comparison helper plus tests --- zencore/string.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'zencore/string.cpp') diff --git a/zencore/string.cpp b/zencore/string.cpp index 34ea0a87d..35dfcfcf3 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -951,6 +951,18 @@ TEST_CASE("string") CHECK_EQ(ToLower("TE%St"sv), "te%st"sv); } + SUBCASE("StrCaseCompare") + { + CHECK(StrCaseCompare("foo", "FoO") == 0); + CHECK(StrCaseCompare("Bar", "bAs") < 0); + CHECK(StrCaseCompare("bAr", "Bas") < 0); + CHECK(StrCaseCompare("BBr", "Bar") > 0); + CHECK(StrCaseCompare("Bbr", "BAr") > 0); + CHECK(StrCaseCompare("foo", "FoO", 3) == 0); + CHECK(StrCaseCompare("Bar", "bAs", 3) < 0); + CHECK(StrCaseCompare("BBr", "Bar", 2) > 0); + } + SUBCASE("ForEachStrTok") { const auto Tokens = "here,is,my,different,tokens"sv; -- cgit v1.2.3