From 27fb4b09ec719fa89059234d35a267816abe763c7026e0b1ca382ecb0afeb52a Mon Sep 17 00:00:00 2001 From: ACh Sulfate Date: Fri, 17 May 2024 23:11:22 +0800 Subject: [PATCH] update mutf8 --- utf_convert.cc | 6 +++--- utf_convert.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utf_convert.cc b/utf_convert.cc index 8919860..fd6b0a5 100644 --- a/utf_convert.cc +++ b/utf_convert.cc @@ -98,10 +98,10 @@ std::string UTF32ToUTF8(std::u32string_view utf32) { return utf8; } -std::string UTF16ToMUTF8(std::u16string_view utf16) { +std::string UTF16ToModifiedUTF8(std::u16string_view utf16) { std::string mutf8; 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(utf16[i])); } else if (utf16[i] < 0x800) { mutf8.push_back(static_cast(0xC0 | (utf16[i] >> 6))); @@ -115,7 +115,7 @@ std::string UTF16ToMUTF8(std::u16string_view utf16) { return mutf8; } -std::u16string MUTF8ToUTF16(std::string_view mutf8) { +std::u16string ModifiedUTF8ToUTF16(std::string_view mutf8) { std::vector utf16; for (size_t i = 0; i < mutf8.size(); ++i) { if ((mutf8[i] & 0b10000000) == 0) { diff --git a/utf_convert.h b/utf_convert.h index 164da10..afbb734 100644 --- a/utf_convert.h +++ b/utf_convert.h @@ -22,9 +22,9 @@ std::string UTF32ToUTF8(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