From 66d6fa62b7931673f97f4b00d8d201481e0d25e2 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Thu, 2 May 2024 11:33:13 +0530 Subject: [PATCH] SimpCfg: C++ and strings is a mess even after decades Seperate out the checks wrt different string types. Add a wstring_basic, which verifies that wstring iterator handles non english chars propery or atleast better. --- common/simpcfg.hpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/common/simpcfg.hpp b/common/simpcfg.hpp index 429fb02a6..e82d58b5b 100644 --- a/common/simpcfg.hpp +++ b/common/simpcfg.hpp @@ -306,8 +306,7 @@ public: #include -void check_strings() { - +void check_string() { std::vector vStandard = { "123", "1अ3" }; std::cout << "**** string **** " << vStandard.size() << std::endl; for(auto sCur: vStandard) { @@ -318,7 +317,9 @@ void check_strings() { i += 1; } } +} +void check_u8string() { std::vector vU8s = { u8"123", u8"1अ3" }; std::cout << "**** u8string **** " << vU8s.size() << std::endl; for(auto sCur: vU8s) { @@ -331,7 +332,9 @@ void check_strings() { i += 1; } } +} +void check_wstring() { std::wcout.imbue(std::locale("en_US.UTF-8")); std::vector vWide = { L"123", L"1अ3" }; std::cout << "**** wstring **** " << vWide.size() << std::endl; @@ -344,7 +347,27 @@ void check_strings() { i += 1; } } +} +void check_wstring_basic() { + std::vector vWide = { L"123", L"1अ3" }; + std::cout << "**** wstring basic **** " << vWide.size() << std::endl; + for(auto sCur: vWide) { + std::string sCurx (sCur.begin(), sCur.end()); + std::cout << std::format("wstring: [{}] len[{}] size[{}]", sCurx, sCur.length(), sCur.size()) << std::endl; + int i = 0; + for(auto c: sCur) { + std::cout << std::format("wstring:{}:pos:{}:char:{}[0x{:x}]\n", sCurx, i, c, c); + i += 1; + } + } +} + +void check_strings() { + check_string(); + check_u8string(); + //check_wstring(); + check_wstring_basic(); } int main(int argc, char **argv) {