mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-30 08:11:01 +00:00
abstract windows structures
This commit is contained in:
28
src/common/platform/unicode.hpp
Normal file
28
src/common/platform/unicode.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename Traits>
|
||||
struct UNICODE_STRING {
|
||||
USHORT Length;
|
||||
USHORT MaximumLength;
|
||||
EMULATOR_CAST(typename Traits::PVOID, char16_t*) Buffer;
|
||||
};
|
||||
|
||||
inline std::string u16_to_u8(std::u16string_view u16_view) {
|
||||
std::string utf8_str;
|
||||
utf8_str.reserve(u16_view.size() * 2);
|
||||
for (char16_t ch : u16_view) {
|
||||
if (ch <= 0x7F) {
|
||||
utf8_str.push_back(static_cast<char>(ch));
|
||||
} else if (ch <= 0x7FF) {
|
||||
utf8_str.push_back(static_cast<char>(0xC0 | (ch >> 6)));
|
||||
utf8_str.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
|
||||
} else {
|
||||
utf8_str.push_back(static_cast<char>(0xE0 | (ch >> 12)));
|
||||
utf8_str.push_back(static_cast<char>(0x80 | ((ch >> 6) & 0x3F)));
|
||||
utf8_str.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
|
||||
}
|
||||
}
|
||||
return utf8_str;
|
||||
}
|
||||
Reference in New Issue
Block a user