Fix UTF-8 truncation

This commit is contained in:
Attila Tajti
2019-11-03 11:53:15 +00:00
committed by Victor Zverovich
parent d6eede9e08
commit 0889856d61
2 changed files with 30 additions and 1 deletions
+10
View File
@@ -2621,3 +2621,13 @@ TEST(FormatTest, FormatCustomChar) {
EXPECT_EQ(result.size(), 1);
EXPECT_EQ(result[0], mychar('x'));
}
TEST(FormatTest, FormatUTF8Precision) {
using str_type = std::basic_string<char8_t>;
str_type format(reinterpret_cast<const char8_t*>(u8"{:.4}"));
str_type str(reinterpret_cast<const char8_t*>(u8"caf\u00e9s")); // cafés
auto result = fmt::format(format, str);
EXPECT_EQ(fmt::internal::count_code_points(result), 4);
EXPECT_EQ(result.size(), 5);
EXPECT_EQ(result, str.substr(0, 5));
}