mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-29 22:00:09 +01:00
Fixed UTF8/16 converters to support empty string input
Previously an exception was thrown since Win32 WideCharToMultiByte API returns error on zero-length input.
This commit is contained in:
committed by
Victor Zverovich
parent
c37c4c437e
commit
acb469ae2e
@@ -665,6 +665,13 @@ TEST(UtilTest, UTF16ToUTF8) {
|
||||
EXPECT_EQ(s.size(), u.size());
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF16ToUTF8EmptyString) {
|
||||
std::string s = "";
|
||||
fmt::internal::utf16_to_utf8 u(L"");
|
||||
EXPECT_EQ(s, u.str());
|
||||
EXPECT_EQ(s.size(), u.size());
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF8ToUTF16) {
|
||||
std::string s = "лошадка";
|
||||
fmt::internal::utf8_to_utf16 u(s.c_str());
|
||||
@@ -672,6 +679,13 @@ TEST(UtilTest, UTF8ToUTF16) {
|
||||
EXPECT_EQ(7, u.size());
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF8ToUTF16EmptyString) {
|
||||
std::string s = "";
|
||||
fmt::internal::utf8_to_utf16 u(s.c_str());
|
||||
EXPECT_EQ(L"", u.str());
|
||||
EXPECT_EQ(s.size(), u.size());
|
||||
}
|
||||
|
||||
template <typename Converter, typename Char>
|
||||
void check_utf_conversion_error(
|
||||
const char *message,
|
||||
|
||||
Reference in New Issue
Block a user