Fix conversion a surrogate pair (#4095)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov
2024-07-30 19:27:11 +05:00
committed by GitHub
parent 6e462b89aa
commit d326c7298a
2 changed files with 6 additions and 1 deletions

View File

@ -1418,10 +1418,12 @@ template <typename WChar, typename Buffer = memory_buffer> class to_utf8 {
if (policy == to_utf8_error_policy::abort) return false;
buf.append(string_view("\xEF\xBF\xBD"));
--p;
continue;
} else {
c = (c << 10) + static_cast<uint32_t>(*p) - 0x35fdc00;
}
} else if (c < 0x80) {
}
if (c < 0x80) {
buf.push_back(static_cast<char>(c));
} else if (c < 0x800) {
buf.push_back(static_cast<char>(0xc0 | (c >> 6)));

View File

@ -35,6 +35,9 @@ TEST(std_test, path) {
L"\x0447\x044B\x043D\x0430")),
"Шчучыншчына");
EXPECT_EQ(fmt::format("{}", path(L"\xd800")), "<EFBFBD>");
EXPECT_EQ(fmt::format("{}", path(L"HEAD \xd800 TAIL")), "HEAD <20> TAIL");
EXPECT_EQ(fmt::format("{}", path(L"HEAD \xD83D\xDE00 TAIL")), "HEAD \xF0\x9F\x98\x80 TAIL");
EXPECT_EQ(fmt::format("{}", path(L"HEAD \xD83D\xD83D\xDE00 TAIL")), "HEAD <20>\xF0\x9F\x98\x80 TAIL");
EXPECT_EQ(fmt::format("{:?}", path(L"\xd800")), "\"\\ud800\"");
# endif
}