Handle block boundaries in utf8_to_utf16
This commit is contained in:
parent
8cf4c52068
commit
e6b37b4aff
@ -1292,9 +1292,12 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) {
|
||||
for (auto end = p + s.size() - block_size + 1; p < end;) p = transcode(p);
|
||||
}
|
||||
if (auto num_chars_left = s.data() + s.size() - p) {
|
||||
char buf[4] = {};
|
||||
char buf[2 * block_size - 1] = {};
|
||||
memcpy(buf, p, num_chars_left);
|
||||
transcode(buf);
|
||||
p = buf;
|
||||
do {
|
||||
p = transcode(p);
|
||||
} while (p - buf < num_chars_left);
|
||||
}
|
||||
buffer_.push_back(0);
|
||||
}
|
||||
|
@ -410,6 +410,7 @@ TEST(UtilTest, UTF8ToUTF16) {
|
||||
"invalid utf8");
|
||||
EXPECT_THROW_MSG(fmt::internal::utf8_to_utf16(fmt::string_view("л", 1)),
|
||||
std::runtime_error, "invalid utf8");
|
||||
EXPECT_EQ(L"123456", fmt::internal::utf8_to_utf16("123456").str());
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF8ToUTF16EmptyString) {
|
||||
|
Loading…
Reference in New Issue
Block a user