mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-30 22:29:23 +01:00
Unification utf16/utf32 to utf8 conversion
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
committed by
Victor Zverovich
parent
e84b00e014
commit
dde8cf3bb7
@@ -60,19 +60,9 @@ inline void write_escaped_path<char>(memory_buffer& quoted,
|
||||
const std::filesystem::path& p) {
|
||||
auto buf = basic_memory_buffer<wchar_t>();
|
||||
write_escaped_string<wchar_t>(std::back_inserter(buf), p.native());
|
||||
for (unsigned c : buf) {
|
||||
// Convert UTF-16 to UTF-8.
|
||||
if (c < 0x80) {
|
||||
quoted.push_back(static_cast<unsigned char>(c));
|
||||
} else if (c < 0x800) {
|
||||
quoted.push_back(0b1100'0000 | ((c >> 6) & 0b01'1111));
|
||||
quoted.push_back(0b1000'0000 | (c & 0b11'1111));
|
||||
} else {
|
||||
quoted.push_back(0b1110'0000 | ((c >> 12) & 0b01'1111));
|
||||
quoted.push_back(0b1000'0000 | ((c >> 6) & 0b11'1111));
|
||||
quoted.push_back(0b1000'0000 | (c & 0b11'1111));
|
||||
}
|
||||
}
|
||||
// Convert UTF-16 to UTF-8.
|
||||
if (!unicode_to_utf8<wchar_t>::convert(quoted, {buf.data(), buf.size()}))
|
||||
FMT_THROW(std::runtime_error("invalid utf16"));
|
||||
}
|
||||
# endif
|
||||
template <>
|
||||
|
||||
Reference in New Issue
Block a user