From 601be1cbe784af4231b70870c48bea442767ea61 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 19 Oct 2024 07:58:53 -0700 Subject: [PATCH] Add support for code units > 0xFFFF in fill --- include/fmt/base.h | 4 +++- test/xchar-test.cc | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index daf7e3fed29d..e0baae256347 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -800,7 +800,8 @@ class basic_specs { template constexpr auto fill_unit() const -> Char { using uchar = unsigned char; return static_cast(static_cast(fill_data_[0]) | - (static_cast(fill_data_[1]) << 8)); + (static_cast(fill_data_[1]) << 8) | + (static_cast(fill_data_[2]) << 16)); } FMT_CONSTEXPR void set_fill(char c) { @@ -816,6 +817,7 @@ class basic_specs { unsigned uchar = static_cast>(s[0]); fill_data_[0] = static_cast(uchar); fill_data_[1] = static_cast(uchar >> 8); + fill_data_[2] = static_cast(uchar >> 16); return; } FMT_ASSERT(size <= max_fill_size, "invalid fill"); diff --git a/test/xchar-test.cc b/test/xchar-test.cc index 215b659ff1e2..0f91aa319e84 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -72,16 +72,17 @@ TEST(xchar_test, format_explicitly_convertible_to_wstring_view) { #endif TEST(xchar_test, format) { - EXPECT_EQ(L"42", fmt::format(L"{}", 42)); - EXPECT_EQ(L"4.2", fmt::format(L"{}", 4.2)); - EXPECT_EQ(L"abc", fmt::format(L"{}", L"abc")); - EXPECT_EQ(L"z", fmt::format(L"{}", L'z')); + EXPECT_EQ(fmt::format(L"{}", 42), L"42"); + EXPECT_EQ(fmt::format(L"{}", 4.2), L"4.2"); + EXPECT_EQ(fmt::format(L"{}", L"abc"), L"abc"); + EXPECT_EQ(fmt::format(L"{}", L'z'), L"z"); EXPECT_THROW(fmt::format(fmt::runtime(L"{:*\x343E}"), 42), fmt::format_error); - EXPECT_EQ(L"true", fmt::format(L"{}", true)); - EXPECT_EQ(L"a", fmt::format(L"{0}", L'a')); - EXPECT_EQ(L"Cyrillic letter \x42e", - fmt::format(L"Cyrillic letter {}", L'\x42e')); - EXPECT_EQ(L"abc1", fmt::format(L"{}c{}", L"ab", 1)); + EXPECT_EQ(fmt::format(L"{}", true), L"true"); + EXPECT_EQ(fmt::format(L"{0}", L'a'), L"a"); + EXPECT_EQ(fmt::format(L"Letter {}", L'\x40e'), L"Letter \x40e"); // Ў + if (sizeof(wchar_t) == 4) + EXPECT_EQ(fmt::format(fmt::runtime(L"{:𓀨>3}"), 42), L"𓀨42"); + EXPECT_EQ(fmt::format(L"{}c{}", L"ab", 1), L"abc1"); } TEST(xchar_test, is_formattable) {