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