update mutf8

This commit is contained in:
2024-05-17 23:11:22 +08:00
parent 418f365d43
commit 27fb4b09ec
2 changed files with 5 additions and 5 deletions

View File

@@ -98,10 +98,10 @@ std::string UTF32ToUTF8(std::u32string_view utf32) {
return utf8; return utf8;
} }
std::string UTF16ToMUTF8(std::u16string_view utf16) { std::string UTF16ToModifiedUTF8(std::u16string_view utf16) {
std::string mutf8; std::string mutf8;
for (size_t i = 0; i < utf16.size(); ++i) { for (size_t i = 0; i < utf16.size(); ++i) {
if (utf16[i] < 0x80) { if (utf16[i] < 0x80 && utf16[i] != 0) {
mutf8.push_back(static_cast<char>(utf16[i])); mutf8.push_back(static_cast<char>(utf16[i]));
} else if (utf16[i] < 0x800) { } else if (utf16[i] < 0x800) {
mutf8.push_back(static_cast<char>(0xC0 | (utf16[i] >> 6))); mutf8.push_back(static_cast<char>(0xC0 | (utf16[i] >> 6)));
@@ -115,7 +115,7 @@ std::string UTF16ToMUTF8(std::u16string_view utf16) {
return mutf8; return mutf8;
} }
std::u16string MUTF8ToUTF16(std::string_view mutf8) { std::u16string ModifiedUTF8ToUTF16(std::string_view mutf8) {
std::vector<uint16_t> utf16; std::vector<uint16_t> utf16;
for (size_t i = 0; i < mutf8.size(); ++i) { for (size_t i = 0; i < mutf8.size(); ++i) {
if ((mutf8[i] & 0b10000000) == 0) { if ((mutf8[i] & 0b10000000) == 0) {

View File

@@ -22,9 +22,9 @@ std::string UTF32ToUTF8(std::u32string_view utf32);
std::u16string UTF32ToUTF16(std::u32string_view utf32); std::u16string UTF32ToUTF16(std::u32string_view utf32);
std::string UTF16ToMUTF8(std::u16string_view utf16); std::string UTF16ToModifiedUTF8(std::u16string_view utf16);
std::u16string MUTF8ToUTF16(std::string_view mutf8); std::u16string ModifiedUTF8ToUTF16(std::string_view mutf8);
// for windows, they are not implemented on linux // for windows, they are not implemented on linux