aboutsummaryrefslogtreecommitdiff
path: root/src/base/StringUtil.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-10-17 22:57:30 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-17 22:57:30 +0800
commitca9334f53b9456a517f8fa4a687e2d2a6cc1ca86 (patch)
treea49651d6af538f90f4033e1ff6361d309ed3fed9 /src/base/StringUtil.cpp
parent728d592f4075ae78b67dab6911ada05875a470a3 (diff)
downloadcru-ca9334f53b9456a517f8fa4a687e2d2a6cc1ca86.tar.gz
cru-ca9334f53b9456a517f8fa4a687e2d2a6cc1ca86.tar.bz2
cru-ca9334f53b9456a517f8fa4a687e2d2a6cc1ca86.zip
Fix windows build.
Diffstat (limited to 'src/base/StringUtil.cpp')
-rw-r--r--src/base/StringUtil.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/base/StringUtil.cpp b/src/base/StringUtil.cpp
index 4cd662d1..5c8686dd 100644
--- a/src/base/StringUtil.cpp
+++ b/src/base/StringUtil.cpp
@@ -404,4 +404,25 @@ Index Utf16IndexCodePointToCodeUnit(const Utf16CodeUnit* ptr, Index size,
position);
}
+#ifdef _WIN32
+std::wstring ToUtf16(std::string_view str) {
+ Utf8CodePointIterator iter(str.data(),str.size());
+ std::wstring result;
+ for (auto c : iter) {
+ Utf16EncodeCodePointAppend(c, [&result](char16_t c) { result += c; });
+ }
+ return result;
+}
+
+std::string ToUtf8(std::wstring_view str) {
+ Utf16CodePointIterator iter(reinterpret_cast<const char16_t*>( str.data()),str.size());
+ std::string result;
+ for (auto c : iter) {
+ Utf8EncodeCodePointAppend(c, [&result](char c) { result += c; });
+ }
+ return result;
+}
+
+#endif
+
} // namespace cru::string