diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/core/StarString_windows.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/core/StarString_windows.cpp')
-rw-r--r-- | source/core/StarString_windows.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/core/StarString_windows.cpp b/source/core/StarString_windows.cpp new file mode 100644 index 0000000..77c3e89 --- /dev/null +++ b/source/core/StarString_windows.cpp @@ -0,0 +1,34 @@ +#include "StarString_windows.hpp" + +namespace Star { + +size_t wcharLen(WCHAR const* s) { + size_t size = 0; + while (*s) { + ++size; + ++s; + } + return size; +} + +String utf16ToString(WCHAR const* s) { + if (!s) + return ""; + int sLen = wcharLen(s); + int utf8Len = WideCharToMultiByte(CP_UTF8, 0, s, sLen + 1, NULL, 0, NULL, NULL); + auto utf8Buffer = new char[utf8Len]; + WideCharToMultiByte(CP_UTF8, 0, s, sLen + 1, utf8Buffer, utf8Len, NULL, NULL); + auto result = String(utf8Buffer, utf8Len - 1); + delete[] utf8Buffer; + return result; +} + +unique_ptr<WCHAR[]> stringToUtf16(String const& s) { + int utf16Len = MultiByteToWideChar(CP_UTF8, 0, s.utf8Ptr(), s.utf8Size() + 1, NULL, 0); + unique_ptr<WCHAR[]> result; + result.reset(new WCHAR[utf16Len]); + MultiByteToWideChar(CP_UTF8, 0, s.utf8Ptr(), s.utf8Size() + 1, result.get(), utf16Len); + return result; +} + +} |