From 86663068a30bc4c837c10e56207278e9d73a4b34 Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Fri, 24 Jul 2026 00:10:08 +0200 Subject: [PATCH 1/9] Widen display_width_of() to cover Emoji_Presentation code points fmt::detail::display_width_of() only treated East Asian Wide/Fullwidth code points and two hand-picked emoji ranges as two columns wide, so emoji outside those ranges (e.g. the Dingbats block: cross mark U+274C, white heavy check mark U+2705) were measured as one column even though most terminals render them double-width. This produced visibly inconsistent padding under {:^N} compared to CJK text (fixes #4851). Replaced the ad hoc boolean expression with a sorted table of ranges (East Asian Wide/Fullwidth plus the full Emoji_Presentation set from Unicode's emoji-data.txt) looked up via binary search, and added regression tests covering the original report plus edge cases: multiple emoji, mixed emoji/CJK/ASCII content, precision truncation, alignment/fill variants, newly covered emoji ranges, and regional indicator (flag) pairs. --- include/fmt/format.h | 104 +++++++++++++++++++++++++++++++++++-------- test/format-test.cc | 65 +++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 19 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index d74c3e93c14d..f59c00fcaf6e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,26 +649,92 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } +struct wide_cp_range { + uint32_t first; + uint32_t last; +}; + +// Code points with display width 2: East Asian Wide/Fullwidth +// (https://www.unicode.org/reports/tr11/) and Emoji_Presentation +// (https://www.unicode.org/reports/tr51/) ranges, sorted and merged. +inline constexpr wide_cp_range wide_cp_ranges[] = { + {0x1100, 0x115f}, // Hangul Jamo init. consonants + {0x231a, 0x231b}, // Watch, hourglass done + {0x2329, 0x232a}, // Angle brackets + {0x23e9, 0x23ec}, // Fast-forward/-backward, next/last track buttons + {0x23f0, 0x23f0}, // Alarm clock + {0x23f3, 0x23f3}, // Hourglass not done + {0x25fd, 0x25fe}, // White/black medium-small square + {0x2614, 0x2615}, // Umbrella with rain drops, hot beverage + {0x2648, 0x2653}, // Zodiac signs + {0x267f, 0x267f}, // Wheelchair symbol + {0x2693, 0x2693}, // Anchor + {0x26a1, 0x26a1}, // High voltage + {0x26aa, 0x26ab}, // White/black circle + {0x26bd, 0x26be}, // Soccer ball, baseball + {0x26c4, 0x26c5}, // Snowman, sun behind cloud + {0x26ce, 0x26ce}, // Ophiuchus + {0x26d4, 0x26d4}, // No entry + {0x26ea, 0x26ea}, // Church + {0x26f2, 0x26f3}, // Fountain, flag in hole + {0x26f5, 0x26f5}, // Sailboat + {0x26fa, 0x26fa}, // Tent + {0x26fd, 0x26fd}, // Fuel pump + {0x2705, 0x2705}, // White heavy check mark + {0x270a, 0x270b}, // Raised fist/hand + {0x2728, 0x2728}, // Sparkles + {0x274c, 0x274c}, // Cross mark + {0x274e, 0x274e}, // Negative squared cross mark + {0x2753, 0x2755}, // Question/exclamation mark ornaments + {0x2757, 0x2757}, // Heavy exclamation mark + {0x2795, 0x2797}, // Heavy plus/minus/division sign + {0x27b0, 0x27b0}, // Curly loop + {0x27bf, 0x27bf}, // Double curly loop + {0x2b1b, 0x2b1c}, // Black/white large square + {0x2b50, 0x2b50}, // White medium star + {0x2b55, 0x2b55}, // Heavy large circle + // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: + {0x2e80, 0x303e}, {0x3040, 0xa4cf}, + {0xac00, 0xd7a3}, // Hangul Syllables + {0xf900, 0xfaff}, // CJK Compatibility Ideographs + {0xfe10, 0xfe19}, // Vertical Forms + {0xfe30, 0xfe6f}, // CJK Compatibility Forms + {0xff00, 0xff60}, // Fullwidth Forms + {0xffe0, 0xffe6}, // Fullwidth Forms + // The following are Emoji_Presentation code points from UTS #51 that + // fall outside the Unicode blocks above: + {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, + {0x1f191, 0x1f19a}, {0x1f1e6, 0x1f1ff}, // regional indicator symbols + {0x1f201, 0x1f201}, {0x1f21a, 0x1f21a}, {0x1f22f, 0x1f22f}, + {0x1f232, 0x1f236}, {0x1f238, 0x1f23a}, {0x1f250, 0x1f251}, + // Miscellaneous Symbols and Pictographs + Emoticons: + {0x1f300, 0x1f64f}, + {0x1f680, 0x1f6c5}, // Transport and Map Symbols + {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, {0x1f6d5, 0x1f6d8}, + {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, {0x1f6f4, 0x1f6fc}, + {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, + {0x1f900, 0x1f9ff}, // Supplemental Symbols and Pictographs + // Symbols and Pictographs Extended-A: + {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa8a}, {0x1fa8e, 0x1fac6}, + {0x1fac8, 0x1fac8}, {0x1facd, 0x1fadc}, {0x1fadf, 0x1faea}, + {0x1faef, 0x1faf8}, + {0x20000, 0x2fffd}, // CJK + {0x30000, 0x3fffd}, +}; + FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { - return to_unsigned( - 1 + (cp >= 0x1100 && - (cp <= 0x115f || // Hangul Jamo init. consonants - cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET - cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET - // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: - (cp >= 0x2e80 && cp <= 0xa4cf && cp != 0x303f) || - (cp >= 0xac00 && cp <= 0xd7a3) || // Hangul Syllables - (cp >= 0xf900 && cp <= 0xfaff) || // CJK Compatibility Ideographs - (cp >= 0xfe10 && cp <= 0xfe19) || // Vertical Forms - (cp >= 0xfe30 && cp <= 0xfe6f) || // CJK Compatibility Forms - (cp >= 0xff00 && cp <= 0xff60) || // Fullwidth Forms - (cp >= 0xffe0 && cp <= 0xffe6) || // Fullwidth Forms - (cp >= 0x20000 && cp <= 0x2fffd) || // CJK - (cp >= 0x30000 && cp <= 0x3fffd) || - // Miscellaneous Symbols and Pictographs + Emoticons: - (cp >= 0x1f300 && cp <= 0x1f64f) || - // Supplemental Symbols and Pictographs: - (cp >= 0x1f900 && cp <= 0x1f9ff)))); + if (cp < 0x1100) return 1; + size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); + while (lo < hi) { + size_t mid = lo + (hi - lo) / 2; + if (cp < wide_cp_ranges[mid].first) + hi = mid; + else if (cp > wide_cp_ranges[mid].last) + lo = mid + 1; + else + return 2; + } + return 1; } template struct is_integral : std::is_integral {}; diff --git a/test/format-test.cc b/test/format-test.cc index c16de4b2794d..040f357e010f 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -606,6 +606,71 @@ TEST(format_test, display_width_precision) { EXPECT_EQ(fmt::format("{:.5}", "🐱🐱🐱"), "🐱🐱"); } +TEST(format_test, display_width_emoji) { + // U+2705 and U+274C are Emoji_Presentation code points outside the East + // Asian Wide ranges; they should still occupy two columns like other + // emoji (https://github.com/fmtlib/fmt/issues/4851). + EXPECT_EQ(fmt::format("{:^6}", "βœ…"), " βœ… "); + EXPECT_EQ(fmt::format("{:^6}", "❌"), " ❌ "); +} + +// Reproduces the exact example from +// https://github.com/fmtlib/fmt/issues/4851: emoji should be centered like +// other double-width (e.g. CJK) text instead of like single-width text. +TEST(format_test, display_width_issue_4851) { + EXPECT_EQ(fmt::format("{:^20}", 12345), " 12345 "); + EXPECT_EQ(fmt::format("{:^20}", "normal string"), " normal string "); + EXPECT_EQ(fmt::format("{:^20}", "❌"), " ❌ "); + EXPECT_EQ(fmt::format("{:^20}", "βœ…"), " βœ… "); + EXPECT_EQ(fmt::format("{:^20}", "MΓΌller"), " MΓΌller "); + EXPECT_EQ(fmt::format("{:^20}", "ζˆ‘"), " ζˆ‘ "); +} + +TEST(format_test, display_width_multiple_emoji) { + // Several Emoji_Presentation code points back to back, each contributing + // two columns. + EXPECT_EQ(fmt::format("{:^10}", "βŒβœ…"), " βŒβœ… "); + EXPECT_EQ(fmt::format("{:^12}", "βŒβœ…βŒ"), " βŒβœ…βŒ "); + // Mixing an already-supported emoji range (🐱, U+1F431) with a newly + // covered one (βœ…, U+2705). + EXPECT_EQ(fmt::format("{:^10}", "πŸ±βœ…"), " πŸ±βœ… "); +} + +TEST(format_test, display_width_mixed_content) { + // ASCII + new-range emoji + CJK in the same string. + EXPECT_EQ(fmt::format("{:^11}", "Aβœ…ζˆ‘"), " Aβœ…ζˆ‘ "); + // Accented Latin (each combined character is one column) + emoji + ASCII. + EXPECT_EQ(fmt::format("{:^16}", "MΓΌller❌!"), " MΓΌller❌! "); +} + +TEST(format_test, display_width_precision_multiple_emoji) { + // Precision truncates by display width, not code point count: a third + // two-column emoji would push the total past the limit in both cases. + EXPECT_EQ(fmt::format("{:.5}", "βŒβœ…βŒ"), "βŒβœ…"); + EXPECT_EQ(fmt::format("{:.4}", "βŒβœ…βŒ"), "βŒβœ…"); +} + +TEST(format_test, display_width_emoji_alignment) { + EXPECT_EQ(fmt::format("{:<10}", "βœ…"), "βœ… "); + EXPECT_EQ(fmt::format("{:>10}", "βœ…"), " βœ…"); + EXPECT_EQ(fmt::format("{:*^10}", "βœ…"), "****βœ…****"); +} + +TEST(format_test, display_width_new_emoji_ranges) { + // Spot-check ranges added outside the two blocks fmt already supported + // (Transport and Map Symbols, Symbols and Pictographs Extended-A). + EXPECT_EQ(fmt::format("{:^10}", "πŸš—"), " πŸš— "); // U+1F697 + EXPECT_EQ(fmt::format("{:^10}", "🫠"), " 🫠 "); // U+1FAE0 +} + +TEST(format_test, display_width_regional_indicator_pair) { + // A flag is two regional indicator code points; fmt has no grapheme + // clustering, so each is measured independently at two columns (four + // columns total) even though most terminals render the pair as a single + // two-column glyph. + EXPECT_EQ(fmt::format("{:^10}", "πŸ‡ΊπŸ‡Έ"), " πŸ‡ΊπŸ‡Έ "); +} + template struct test_format { template static auto format(fmt::string_view fmt, const T&... args) -> std::string { From ffc66addc4adb1b919aceb519aba00ca6f91ffcf Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Tue, 28 Jul 2026 13:10:08 +0200 Subject: [PATCH 2/9] Make wide_cp_ranges C++11-compatible; apply clang-format --- include/fmt/format.h | 154 ++++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 69 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index f59c00fcaf6e..014947d0339f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -654,76 +654,92 @@ struct wide_cp_range { uint32_t last; }; -// Code points with display width 2: East Asian Wide/Fullwidth -// (https://www.unicode.org/reports/tr11/) and Emoji_Presentation -// (https://www.unicode.org/reports/tr51/) ranges, sorted and merged. -inline constexpr wide_cp_range wide_cp_ranges[] = { - {0x1100, 0x115f}, // Hangul Jamo init. consonants - {0x231a, 0x231b}, // Watch, hourglass done - {0x2329, 0x232a}, // Angle brackets - {0x23e9, 0x23ec}, // Fast-forward/-backward, next/last track buttons - {0x23f0, 0x23f0}, // Alarm clock - {0x23f3, 0x23f3}, // Hourglass not done - {0x25fd, 0x25fe}, // White/black medium-small square - {0x2614, 0x2615}, // Umbrella with rain drops, hot beverage - {0x2648, 0x2653}, // Zodiac signs - {0x267f, 0x267f}, // Wheelchair symbol - {0x2693, 0x2693}, // Anchor - {0x26a1, 0x26a1}, // High voltage - {0x26aa, 0x26ab}, // White/black circle - {0x26bd, 0x26be}, // Soccer ball, baseball - {0x26c4, 0x26c5}, // Snowman, sun behind cloud - {0x26ce, 0x26ce}, // Ophiuchus - {0x26d4, 0x26d4}, // No entry - {0x26ea, 0x26ea}, // Church - {0x26f2, 0x26f3}, // Fountain, flag in hole - {0x26f5, 0x26f5}, // Sailboat - {0x26fa, 0x26fa}, // Tent - {0x26fd, 0x26fd}, // Fuel pump - {0x2705, 0x2705}, // White heavy check mark - {0x270a, 0x270b}, // Raised fist/hand - {0x2728, 0x2728}, // Sparkles - {0x274c, 0x274c}, // Cross mark - {0x274e, 0x274e}, // Negative squared cross mark - {0x2753, 0x2755}, // Question/exclamation mark ornaments - {0x2757, 0x2757}, // Heavy exclamation mark - {0x2795, 0x2797}, // Heavy plus/minus/division sign - {0x27b0, 0x27b0}, // Curly loop - {0x27bf, 0x27bf}, // Double curly loop - {0x2b1b, 0x2b1c}, // Black/white large square - {0x2b50, 0x2b50}, // White medium star - {0x2b55, 0x2b55}, // Heavy large circle - // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: - {0x2e80, 0x303e}, {0x3040, 0xa4cf}, - {0xac00, 0xd7a3}, // Hangul Syllables - {0xf900, 0xfaff}, // CJK Compatibility Ideographs - {0xfe10, 0xfe19}, // Vertical Forms - {0xfe30, 0xfe6f}, // CJK Compatibility Forms - {0xff00, 0xff60}, // Fullwidth Forms - {0xffe0, 0xffe6}, // Fullwidth Forms - // The following are Emoji_Presentation code points from UTS #51 that - // fall outside the Unicode blocks above: - {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, - {0x1f191, 0x1f19a}, {0x1f1e6, 0x1f1ff}, // regional indicator symbols - {0x1f201, 0x1f201}, {0x1f21a, 0x1f21a}, {0x1f22f, 0x1f22f}, - {0x1f232, 0x1f236}, {0x1f238, 0x1f23a}, {0x1f250, 0x1f251}, - // Miscellaneous Symbols and Pictographs + Emoticons: - {0x1f300, 0x1f64f}, - {0x1f680, 0x1f6c5}, // Transport and Map Symbols - {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, {0x1f6d5, 0x1f6d8}, - {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, {0x1f6f4, 0x1f6fc}, - {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, - {0x1f900, 0x1f9ff}, // Supplemental Symbols and Pictographs - // Symbols and Pictographs Extended-A: - {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa8a}, {0x1fa8e, 0x1fac6}, - {0x1fac8, 0x1fac8}, {0x1facd, 0x1fadc}, {0x1fadf, 0x1faea}, - {0x1faef, 0x1faf8}, - {0x20000, 0x2fffd}, // CJK - {0x30000, 0x3fffd}, -}; - -FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { +inline auto display_width_of(uint32_t cp) noexcept -> size_t { if (cp < 0x1100) return 1; + // Code points with display width 2: East Asian Wide/Fullwidth + // (https://www.unicode.org/reports/tr11/) and Emoji_Presentation + // (https://www.unicode.org/reports/tr51/) ranges, sorted and merged. + static constexpr wide_cp_range wide_cp_ranges[] = { + {0x1100, 0x115f}, // Hangul Jamo init. consonants + {0x231a, 0x231b}, // Watch, hourglass done + {0x2329, 0x232a}, // Angle brackets + {0x23e9, 0x23ec}, // Fast-forward/-backward, next/last track buttons + {0x23f0, 0x23f0}, // Alarm clock + {0x23f3, 0x23f3}, // Hourglass not done + {0x25fd, 0x25fe}, // White/black medium-small square + {0x2614, 0x2615}, // Umbrella with rain drops, hot beverage + {0x2648, 0x2653}, // Zodiac signs + {0x267f, 0x267f}, // Wheelchair symbol + {0x2693, 0x2693}, // Anchor + {0x26a1, 0x26a1}, // High voltage + {0x26aa, 0x26ab}, // White/black circle + {0x26bd, 0x26be}, // Soccer ball, baseball + {0x26c4, 0x26c5}, // Snowman, sun behind cloud + {0x26ce, 0x26ce}, // Ophiuchus + {0x26d4, 0x26d4}, // No entry + {0x26ea, 0x26ea}, // Church + {0x26f2, 0x26f3}, // Fountain, flag in hole + {0x26f5, 0x26f5}, // Sailboat + {0x26fa, 0x26fa}, // Tent + {0x26fd, 0x26fd}, // Fuel pump + {0x2705, 0x2705}, // White heavy check mark + {0x270a, 0x270b}, // Raised fist/hand + {0x2728, 0x2728}, // Sparkles + {0x274c, 0x274c}, // Cross mark + {0x274e, 0x274e}, // Negative squared cross mark + {0x2753, 0x2755}, // Question/exclamation mark ornaments + {0x2757, 0x2757}, // Heavy exclamation mark + {0x2795, 0x2797}, // Heavy plus/minus/division sign + {0x27b0, 0x27b0}, // Curly loop + {0x27bf, 0x27bf}, // Double curly loop + {0x2b1b, 0x2b1c}, // Black/white large square + {0x2b50, 0x2b50}, // White medium star + {0x2b55, 0x2b55}, // Heavy large circle + // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: + {0x2e80, 0x303e}, + {0x3040, 0xa4cf}, + {0xac00, 0xd7a3}, // Hangul Syllables + {0xf900, 0xfaff}, // CJK Compatibility Ideographs + {0xfe10, 0xfe19}, // Vertical Forms + {0xfe30, 0xfe6f}, // CJK Compatibility Forms + {0xff00, 0xff60}, // Fullwidth Forms + {0xffe0, 0xffe6}, // Fullwidth Forms + // The following are Emoji_Presentation code points from UTS #51 that + // fall outside the Unicode blocks above: + {0x1f004, 0x1f004}, + {0x1f0cf, 0x1f0cf}, + {0x1f18e, 0x1f18e}, + {0x1f191, 0x1f19a}, + {0x1f1e6, 0x1f1ff}, // regional indicator symbols + {0x1f201, 0x1f201}, + {0x1f21a, 0x1f21a}, + {0x1f22f, 0x1f22f}, + {0x1f232, 0x1f236}, + {0x1f238, 0x1f23a}, + {0x1f250, 0x1f251}, + // Miscellaneous Symbols and Pictographs + Emoticons: + {0x1f300, 0x1f64f}, + {0x1f680, 0x1f6c5}, // Transport and Map Symbols + {0x1f6cc, 0x1f6cc}, + {0x1f6d0, 0x1f6d2}, + {0x1f6d5, 0x1f6d8}, + {0x1f6dc, 0x1f6df}, + {0x1f6eb, 0x1f6ec}, + {0x1f6f4, 0x1f6fc}, + {0x1f7e0, 0x1f7eb}, + {0x1f7f0, 0x1f7f0}, + {0x1f900, 0x1f9ff}, // Supplemental Symbols and Pictographs + // Symbols and Pictographs Extended-A: + {0x1fa70, 0x1fa7c}, + {0x1fa80, 0x1fa8a}, + {0x1fa8e, 0x1fac6}, + {0x1fac8, 0x1fac8}, + {0x1facd, 0x1fadc}, + {0x1fadf, 0x1faea}, + {0x1faef, 0x1faf8}, + {0x20000, 0x2fffd}, // CJK + {0x30000, 0x3fffd}, + }; size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; From 6985557e9021e0d6133137d5a5e940b59f34ffe3 Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Tue, 28 Jul 2026 13:32:28 +0200 Subject: [PATCH 3/9] Move wide_cp_range struct into display_width_of() --- include/fmt/format.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 014947d0339f..82279be6709d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,13 +649,12 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } -struct wide_cp_range { - uint32_t first; - uint32_t last; -}; - inline auto display_width_of(uint32_t cp) noexcept -> size_t { if (cp < 0x1100) return 1; + struct wide_cp_range { + uint32_t first; + uint32_t last; + }; // Code points with display width 2: East Asian Wide/Fullwidth // (https://www.unicode.org/reports/tr11/) and Emoji_Presentation // (https://www.unicode.org/reports/tr51/) ranges, sorted and merged. From e262b7a3971f8140b053483a40dae25032040bdf Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Sun, 23 Aug 2026 20:44:34 +0200 Subject: [PATCH 4/9] Derive wide_cp_ranges from East_Asian_Width data, restore constexpr --- include/fmt/format.h | 142 ++++++++++++++++--------------------------- test/format-test.cc | 10 +-- 2 files changed, 58 insertions(+), 94 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 82279be6709d..00cde78c9baa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,96 +649,60 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } -inline auto display_width_of(uint32_t cp) noexcept -> size_t { +struct wide_cp_range { + uint32_t first; + uint32_t last; +}; + +// Code points with display width 2, i.e. those with the Unicode +// East_Asian_Width property set to W(ide) or F(ullwidth) +// (https://www.unicode.org/reports/tr11/), sorted and merged. +inline constexpr wide_cp_range wide_cp_ranges[] = { + {0x1100, 0x115f}, {0x231a, 0x231b}, {0x2329, 0x232a}, + {0x23e9, 0x23ec}, {0x23f0, 0x23f0}, {0x23f3, 0x23f3}, + {0x25fd, 0x25fe}, {0x2614, 0x2615}, {0x2630, 0x2637}, + {0x2648, 0x2653}, {0x267f, 0x267f}, {0x268a, 0x268f}, + {0x2693, 0x2693}, {0x26a1, 0x26a1}, {0x26aa, 0x26ab}, + {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26ce, 0x26ce}, + {0x26d4, 0x26d4}, {0x26ea, 0x26ea}, {0x26f2, 0x26f3}, + {0x26f5, 0x26f5}, {0x26fa, 0x26fa}, {0x26fd, 0x26fd}, + {0x2705, 0x2705}, {0x270a, 0x270b}, {0x2728, 0x2728}, + {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, + {0x2757, 0x2757}, {0x2795, 0x2797}, {0x27b0, 0x27b0}, + {0x27bf, 0x27bf}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, + {0x2b55, 0x2b55}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, + {0x2f00, 0x2fd5}, {0x2ff0, 0x303e}, {0x3041, 0x3096}, + {0x3099, 0x30ff}, {0x3105, 0x312f}, {0x3131, 0x318e}, + {0x3190, 0x31e5}, {0x31ef, 0x321e}, {0x3220, 0x3247}, + {0x3250, 0xa48c}, {0xa490, 0xa4c6}, {0xa960, 0xa97c}, + {0xac00, 0xd7a3}, {0xf900, 0xfaff}, {0xfe10, 0xfe19}, + {0xfe30, 0xfe52}, {0xfe54, 0xfe66}, {0xfe68, 0xfe6b}, + {0xff01, 0xff60}, {0xffe0, 0xffe6}, {0x16fe0, 0x16fe4}, + {0x16ff0, 0x16ff1}, {0x17000, 0x187f7}, {0x18800, 0x18cd5}, + {0x18cff, 0x18d08}, {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, + {0x1affd, 0x1affe}, {0x1b000, 0x1b122}, {0x1b132, 0x1b132}, + {0x1b150, 0x1b152}, {0x1b155, 0x1b155}, {0x1b164, 0x1b167}, + {0x1b170, 0x1b2fb}, {0x1d300, 0x1d356}, {0x1d360, 0x1d376}, + {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, + {0x1f191, 0x1f19a}, {0x1f200, 0x1f202}, {0x1f210, 0x1f23b}, + {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, + {0x1f300, 0x1f320}, {0x1f32d, 0x1f335}, {0x1f337, 0x1f37c}, + {0x1f37e, 0x1f393}, {0x1f3a0, 0x1f3ca}, {0x1f3cf, 0x1f3d3}, + {0x1f3e0, 0x1f3f0}, {0x1f3f4, 0x1f3f4}, {0x1f3f8, 0x1f43e}, + {0x1f440, 0x1f440}, {0x1f442, 0x1f4fc}, {0x1f4ff, 0x1f53d}, + {0x1f54b, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f57a, 0x1f57a}, + {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a4}, {0x1f5fb, 0x1f64f}, + {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, + {0x1f6d5, 0x1f6d7}, {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, + {0x1f6f4, 0x1f6fc}, {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, + {0x1f90c, 0x1f93a}, {0x1f93c, 0x1f945}, {0x1f947, 0x1f9ff}, + {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa89}, {0x1fa8f, 0x1fac6}, + {0x1face, 0x1fadc}, {0x1fadf, 0x1fae9}, {0x1faf0, 0x1faf8}, + {0x20000, 0x2fffd}, {0x30000, 0x3fffd}, +}; + +FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { if (cp < 0x1100) return 1; - struct wide_cp_range { - uint32_t first; - uint32_t last; - }; - // Code points with display width 2: East Asian Wide/Fullwidth - // (https://www.unicode.org/reports/tr11/) and Emoji_Presentation - // (https://www.unicode.org/reports/tr51/) ranges, sorted and merged. - static constexpr wide_cp_range wide_cp_ranges[] = { - {0x1100, 0x115f}, // Hangul Jamo init. consonants - {0x231a, 0x231b}, // Watch, hourglass done - {0x2329, 0x232a}, // Angle brackets - {0x23e9, 0x23ec}, // Fast-forward/-backward, next/last track buttons - {0x23f0, 0x23f0}, // Alarm clock - {0x23f3, 0x23f3}, // Hourglass not done - {0x25fd, 0x25fe}, // White/black medium-small square - {0x2614, 0x2615}, // Umbrella with rain drops, hot beverage - {0x2648, 0x2653}, // Zodiac signs - {0x267f, 0x267f}, // Wheelchair symbol - {0x2693, 0x2693}, // Anchor - {0x26a1, 0x26a1}, // High voltage - {0x26aa, 0x26ab}, // White/black circle - {0x26bd, 0x26be}, // Soccer ball, baseball - {0x26c4, 0x26c5}, // Snowman, sun behind cloud - {0x26ce, 0x26ce}, // Ophiuchus - {0x26d4, 0x26d4}, // No entry - {0x26ea, 0x26ea}, // Church - {0x26f2, 0x26f3}, // Fountain, flag in hole - {0x26f5, 0x26f5}, // Sailboat - {0x26fa, 0x26fa}, // Tent - {0x26fd, 0x26fd}, // Fuel pump - {0x2705, 0x2705}, // White heavy check mark - {0x270a, 0x270b}, // Raised fist/hand - {0x2728, 0x2728}, // Sparkles - {0x274c, 0x274c}, // Cross mark - {0x274e, 0x274e}, // Negative squared cross mark - {0x2753, 0x2755}, // Question/exclamation mark ornaments - {0x2757, 0x2757}, // Heavy exclamation mark - {0x2795, 0x2797}, // Heavy plus/minus/division sign - {0x27b0, 0x27b0}, // Curly loop - {0x27bf, 0x27bf}, // Double curly loop - {0x2b1b, 0x2b1c}, // Black/white large square - {0x2b50, 0x2b50}, // White medium star - {0x2b55, 0x2b55}, // Heavy large circle - // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: - {0x2e80, 0x303e}, - {0x3040, 0xa4cf}, - {0xac00, 0xd7a3}, // Hangul Syllables - {0xf900, 0xfaff}, // CJK Compatibility Ideographs - {0xfe10, 0xfe19}, // Vertical Forms - {0xfe30, 0xfe6f}, // CJK Compatibility Forms - {0xff00, 0xff60}, // Fullwidth Forms - {0xffe0, 0xffe6}, // Fullwidth Forms - // The following are Emoji_Presentation code points from UTS #51 that - // fall outside the Unicode blocks above: - {0x1f004, 0x1f004}, - {0x1f0cf, 0x1f0cf}, - {0x1f18e, 0x1f18e}, - {0x1f191, 0x1f19a}, - {0x1f1e6, 0x1f1ff}, // regional indicator symbols - {0x1f201, 0x1f201}, - {0x1f21a, 0x1f21a}, - {0x1f22f, 0x1f22f}, - {0x1f232, 0x1f236}, - {0x1f238, 0x1f23a}, - {0x1f250, 0x1f251}, - // Miscellaneous Symbols and Pictographs + Emoticons: - {0x1f300, 0x1f64f}, - {0x1f680, 0x1f6c5}, // Transport and Map Symbols - {0x1f6cc, 0x1f6cc}, - {0x1f6d0, 0x1f6d2}, - {0x1f6d5, 0x1f6d8}, - {0x1f6dc, 0x1f6df}, - {0x1f6eb, 0x1f6ec}, - {0x1f6f4, 0x1f6fc}, - {0x1f7e0, 0x1f7eb}, - {0x1f7f0, 0x1f7f0}, - {0x1f900, 0x1f9ff}, // Supplemental Symbols and Pictographs - // Symbols and Pictographs Extended-A: - {0x1fa70, 0x1fa7c}, - {0x1fa80, 0x1fa8a}, - {0x1fa8e, 0x1fac6}, - {0x1fac8, 0x1fac8}, - {0x1facd, 0x1fadc}, - {0x1fadf, 0x1faea}, - {0x1faef, 0x1faf8}, - {0x20000, 0x2fffd}, // CJK - {0x30000, 0x3fffd}, - }; size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; diff --git a/test/format-test.cc b/test/format-test.cc index 040f357e010f..ef373c455ba8 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -664,11 +664,11 @@ TEST(format_test, display_width_new_emoji_ranges) { } TEST(format_test, display_width_regional_indicator_pair) { - // A flag is two regional indicator code points; fmt has no grapheme - // clustering, so each is measured independently at two columns (four - // columns total) even though most terminals render the pair as a single - // two-column glyph. - EXPECT_EQ(fmt::format("{:^10}", "πŸ‡ΊπŸ‡Έ"), " πŸ‡ΊπŸ‡Έ "); + // A flag is two regional indicator code points; each is Neutral under + // East_Asian_Width (not Wide), so each is measured as one column, giving + // the pair a total of two columns, matching how terminals render the flag + // as a single two-column glyph. + EXPECT_EQ(fmt::format("{:^10}", "πŸ‡ΊπŸ‡Έ"), " πŸ‡ΊπŸ‡Έ "); } template struct test_format { From 6b0ed6f19d21d79432fe6e18778543f79b268c27 Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Tue, 25 Aug 2026 12:05:21 +0200 Subject: [PATCH 5/9] Move wide_cp_ranges to display_width_of function body --- include/fmt/format.h | 104 +++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 00cde78c9baa..f44eadcbdc8f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,60 +649,58 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } -struct wide_cp_range { - uint32_t first; - uint32_t last; -}; - -// Code points with display width 2, i.e. those with the Unicode -// East_Asian_Width property set to W(ide) or F(ullwidth) -// (https://www.unicode.org/reports/tr11/), sorted and merged. -inline constexpr wide_cp_range wide_cp_ranges[] = { - {0x1100, 0x115f}, {0x231a, 0x231b}, {0x2329, 0x232a}, - {0x23e9, 0x23ec}, {0x23f0, 0x23f0}, {0x23f3, 0x23f3}, - {0x25fd, 0x25fe}, {0x2614, 0x2615}, {0x2630, 0x2637}, - {0x2648, 0x2653}, {0x267f, 0x267f}, {0x268a, 0x268f}, - {0x2693, 0x2693}, {0x26a1, 0x26a1}, {0x26aa, 0x26ab}, - {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26ce, 0x26ce}, - {0x26d4, 0x26d4}, {0x26ea, 0x26ea}, {0x26f2, 0x26f3}, - {0x26f5, 0x26f5}, {0x26fa, 0x26fa}, {0x26fd, 0x26fd}, - {0x2705, 0x2705}, {0x270a, 0x270b}, {0x2728, 0x2728}, - {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, - {0x2757, 0x2757}, {0x2795, 0x2797}, {0x27b0, 0x27b0}, - {0x27bf, 0x27bf}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, - {0x2b55, 0x2b55}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, - {0x2f00, 0x2fd5}, {0x2ff0, 0x303e}, {0x3041, 0x3096}, - {0x3099, 0x30ff}, {0x3105, 0x312f}, {0x3131, 0x318e}, - {0x3190, 0x31e5}, {0x31ef, 0x321e}, {0x3220, 0x3247}, - {0x3250, 0xa48c}, {0xa490, 0xa4c6}, {0xa960, 0xa97c}, - {0xac00, 0xd7a3}, {0xf900, 0xfaff}, {0xfe10, 0xfe19}, - {0xfe30, 0xfe52}, {0xfe54, 0xfe66}, {0xfe68, 0xfe6b}, - {0xff01, 0xff60}, {0xffe0, 0xffe6}, {0x16fe0, 0x16fe4}, - {0x16ff0, 0x16ff1}, {0x17000, 0x187f7}, {0x18800, 0x18cd5}, - {0x18cff, 0x18d08}, {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, - {0x1affd, 0x1affe}, {0x1b000, 0x1b122}, {0x1b132, 0x1b132}, - {0x1b150, 0x1b152}, {0x1b155, 0x1b155}, {0x1b164, 0x1b167}, - {0x1b170, 0x1b2fb}, {0x1d300, 0x1d356}, {0x1d360, 0x1d376}, - {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, - {0x1f191, 0x1f19a}, {0x1f200, 0x1f202}, {0x1f210, 0x1f23b}, - {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, - {0x1f300, 0x1f320}, {0x1f32d, 0x1f335}, {0x1f337, 0x1f37c}, - {0x1f37e, 0x1f393}, {0x1f3a0, 0x1f3ca}, {0x1f3cf, 0x1f3d3}, - {0x1f3e0, 0x1f3f0}, {0x1f3f4, 0x1f3f4}, {0x1f3f8, 0x1f43e}, - {0x1f440, 0x1f440}, {0x1f442, 0x1f4fc}, {0x1f4ff, 0x1f53d}, - {0x1f54b, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f57a, 0x1f57a}, - {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a4}, {0x1f5fb, 0x1f64f}, - {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, - {0x1f6d5, 0x1f6d7}, {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, - {0x1f6f4, 0x1f6fc}, {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, - {0x1f90c, 0x1f93a}, {0x1f93c, 0x1f945}, {0x1f947, 0x1f9ff}, - {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa89}, {0x1fa8f, 0x1fac6}, - {0x1face, 0x1fadc}, {0x1fadf, 0x1fae9}, {0x1faf0, 0x1faf8}, - {0x20000, 0x2fffd}, {0x30000, 0x3fffd}, -}; - -FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { +FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) { if (cp < 0x1100) return 1; + struct wide_cp_range { + uint32_t first; + uint32_t last; + }; + // Code points with display width 2, i.e. those with the Unicode + // East_Asian_Width property set to W(ide) or F(ullwidth) + // (https://www.unicode.org/reports/tr11/), sorted and merged. + static constexpr wide_cp_range wide_cp_ranges[] = { + {0x1100, 0x115f}, {0x231a, 0x231b}, {0x2329, 0x232a}, + {0x23e9, 0x23ec}, {0x23f0, 0x23f0}, {0x23f3, 0x23f3}, + {0x25fd, 0x25fe}, {0x2614, 0x2615}, {0x2630, 0x2637}, + {0x2648, 0x2653}, {0x267f, 0x267f}, {0x268a, 0x268f}, + {0x2693, 0x2693}, {0x26a1, 0x26a1}, {0x26aa, 0x26ab}, + {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26ce, 0x26ce}, + {0x26d4, 0x26d4}, {0x26ea, 0x26ea}, {0x26f2, 0x26f3}, + {0x26f5, 0x26f5}, {0x26fa, 0x26fa}, {0x26fd, 0x26fd}, + {0x2705, 0x2705}, {0x270a, 0x270b}, {0x2728, 0x2728}, + {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, + {0x2757, 0x2757}, {0x2795, 0x2797}, {0x27b0, 0x27b0}, + {0x27bf, 0x27bf}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, + {0x2b55, 0x2b55}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, + {0x2f00, 0x2fd5}, {0x2ff0, 0x303e}, {0x3041, 0x3096}, + {0x3099, 0x30ff}, {0x3105, 0x312f}, {0x3131, 0x318e}, + {0x3190, 0x31e5}, {0x31ef, 0x321e}, {0x3220, 0x3247}, + {0x3250, 0xa48c}, {0xa490, 0xa4c6}, {0xa960, 0xa97c}, + {0xac00, 0xd7a3}, {0xf900, 0xfaff}, {0xfe10, 0xfe19}, + {0xfe30, 0xfe52}, {0xfe54, 0xfe66}, {0xfe68, 0xfe6b}, + {0xff01, 0xff60}, {0xffe0, 0xffe6}, {0x16fe0, 0x16fe4}, + {0x16ff0, 0x16ff1}, {0x17000, 0x187f7}, {0x18800, 0x18cd5}, + {0x18cff, 0x18d08}, {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, + {0x1affd, 0x1affe}, {0x1b000, 0x1b122}, {0x1b132, 0x1b132}, + {0x1b150, 0x1b152}, {0x1b155, 0x1b155}, {0x1b164, 0x1b167}, + {0x1b170, 0x1b2fb}, {0x1d300, 0x1d356}, {0x1d360, 0x1d376}, + {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, + {0x1f191, 0x1f19a}, {0x1f200, 0x1f202}, {0x1f210, 0x1f23b}, + {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, + {0x1f300, 0x1f320}, {0x1f32d, 0x1f335}, {0x1f337, 0x1f37c}, + {0x1f37e, 0x1f393}, {0x1f3a0, 0x1f3ca}, {0x1f3cf, 0x1f3d3}, + {0x1f3e0, 0x1f3f0}, {0x1f3f4, 0x1f3f4}, {0x1f3f8, 0x1f43e}, + {0x1f440, 0x1f440}, {0x1f442, 0x1f4fc}, {0x1f4ff, 0x1f53d}, + {0x1f54b, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f57a, 0x1f57a}, + {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a4}, {0x1f5fb, 0x1f64f}, + {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, + {0x1f6d5, 0x1f6d7}, {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, + {0x1f6f4, 0x1f6fc}, {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, + {0x1f90c, 0x1f93a}, {0x1f93c, 0x1f945}, {0x1f947, 0x1f9ff}, + {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa89}, {0x1fa8f, 0x1fac6}, + {0x1face, 0x1fadc}, {0x1fadf, 0x1fae9}, {0x1faf0, 0x1faf8}, + {0x20000, 0x2fffd}, {0x30000, 0x3fffd}, + }; size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; From f6d719367ceb7a432a785f47e4d63089f1e99d9d Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Tue, 25 Aug 2026 16:53:21 +0200 Subject: [PATCH 6/9] Update format.h --- include/fmt/format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index f44eadcbdc8f..9a602a25eb1e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -701,7 +701,8 @@ FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) { {0x1face, 0x1fadc}, {0x1fadf, 0x1fae9}, {0x1faf0, 0x1faf8}, {0x20000, 0x2fffd}, {0x30000, 0x3fffd}, }; - size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); + size_t lo = 0; + size_t hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; if (cp < wide_cp_ranges[mid].first) From c1b33dec2f4d0574e405ad63402206f4d8a25a5d Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Tue, 25 Aug 2026 17:17:38 +0200 Subject: [PATCH 7/9] Update wide_cp_ranges array to include comments --- include/fmt/format.h | 217 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 172 insertions(+), 45 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9a602a25eb1e..d6c8d02f809c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,7 +649,7 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } -FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) { +FMT_CONSTEXPR auto display_width_of(uint32_t cp) noexcept -> size_t { if (cp < 0x1100) return 1; struct wide_cp_range { uint32_t first; @@ -658,51 +658,178 @@ FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) { // Code points with display width 2, i.e. those with the Unicode // East_Asian_Width property set to W(ide) or F(ullwidth) // (https://www.unicode.org/reports/tr11/), sorted and merged. - static constexpr wide_cp_range wide_cp_ranges[] = { - {0x1100, 0x115f}, {0x231a, 0x231b}, {0x2329, 0x232a}, - {0x23e9, 0x23ec}, {0x23f0, 0x23f0}, {0x23f3, 0x23f3}, - {0x25fd, 0x25fe}, {0x2614, 0x2615}, {0x2630, 0x2637}, - {0x2648, 0x2653}, {0x267f, 0x267f}, {0x268a, 0x268f}, - {0x2693, 0x2693}, {0x26a1, 0x26a1}, {0x26aa, 0x26ab}, - {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26ce, 0x26ce}, - {0x26d4, 0x26d4}, {0x26ea, 0x26ea}, {0x26f2, 0x26f3}, - {0x26f5, 0x26f5}, {0x26fa, 0x26fa}, {0x26fd, 0x26fd}, - {0x2705, 0x2705}, {0x270a, 0x270b}, {0x2728, 0x2728}, - {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, - {0x2757, 0x2757}, {0x2795, 0x2797}, {0x27b0, 0x27b0}, - {0x27bf, 0x27bf}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, - {0x2b55, 0x2b55}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, - {0x2f00, 0x2fd5}, {0x2ff0, 0x303e}, {0x3041, 0x3096}, - {0x3099, 0x30ff}, {0x3105, 0x312f}, {0x3131, 0x318e}, - {0x3190, 0x31e5}, {0x31ef, 0x321e}, {0x3220, 0x3247}, - {0x3250, 0xa48c}, {0xa490, 0xa4c6}, {0xa960, 0xa97c}, - {0xac00, 0xd7a3}, {0xf900, 0xfaff}, {0xfe10, 0xfe19}, - {0xfe30, 0xfe52}, {0xfe54, 0xfe66}, {0xfe68, 0xfe6b}, - {0xff01, 0xff60}, {0xffe0, 0xffe6}, {0x16fe0, 0x16fe4}, - {0x16ff0, 0x16ff1}, {0x17000, 0x187f7}, {0x18800, 0x18cd5}, - {0x18cff, 0x18d08}, {0x1aff0, 0x1aff3}, {0x1aff5, 0x1affb}, - {0x1affd, 0x1affe}, {0x1b000, 0x1b122}, {0x1b132, 0x1b132}, - {0x1b150, 0x1b152}, {0x1b155, 0x1b155}, {0x1b164, 0x1b167}, - {0x1b170, 0x1b2fb}, {0x1d300, 0x1d356}, {0x1d360, 0x1d376}, - {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, - {0x1f191, 0x1f19a}, {0x1f200, 0x1f202}, {0x1f210, 0x1f23b}, - {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, - {0x1f300, 0x1f320}, {0x1f32d, 0x1f335}, {0x1f337, 0x1f37c}, - {0x1f37e, 0x1f393}, {0x1f3a0, 0x1f3ca}, {0x1f3cf, 0x1f3d3}, - {0x1f3e0, 0x1f3f0}, {0x1f3f4, 0x1f3f4}, {0x1f3f8, 0x1f43e}, - {0x1f440, 0x1f440}, {0x1f442, 0x1f4fc}, {0x1f4ff, 0x1f53d}, - {0x1f54b, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f57a, 0x1f57a}, - {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a4}, {0x1f5fb, 0x1f64f}, - {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, - {0x1f6d5, 0x1f6d7}, {0x1f6dc, 0x1f6df}, {0x1f6eb, 0x1f6ec}, - {0x1f6f4, 0x1f6fc}, {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, - {0x1f90c, 0x1f93a}, {0x1f93c, 0x1f945}, {0x1f947, 0x1f9ff}, - {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa89}, {0x1fa8f, 0x1fac6}, - {0x1face, 0x1fadc}, {0x1fadf, 0x1fae9}, {0x1faf0, 0x1faf8}, - {0x20000, 0x2fffd}, {0x30000, 0x3fffd}, + constexpr wide_cp_range wide_cp_ranges[] = { + // Hangul Jamo + {0x1100, 0x115f}, + // Miscellaneous Technical + {0x231a, 0x231b}, + {0x2329, 0x232a}, + {0x23e9, 0x23ec}, + {0x23f0, 0x23f0}, + {0x23f3, 0x23f3}, + // Geometric Shapes + {0x25fd, 0x25fe}, + // Miscellaneous Symbols + {0x2614, 0x2615}, + {0x2630, 0x2637}, + {0x2648, 0x2653}, + {0x267f, 0x267f}, + {0x268a, 0x268f}, + {0x2693, 0x2693}, + {0x26a1, 0x26a1}, + {0x26aa, 0x26ab}, + {0x26bd, 0x26be}, + {0x26c4, 0x26c5}, + {0x26ce, 0x26ce}, + {0x26d4, 0x26d4}, + {0x26ea, 0x26ea}, + {0x26f2, 0x26f3}, + {0x26f5, 0x26f5}, + {0x26fa, 0x26fa}, + {0x26fd, 0x26fd}, + // Dingbats + {0x2705, 0x2705}, + {0x270a, 0x270b}, + {0x2728, 0x2728}, + {0x274c, 0x274c}, + {0x274e, 0x274e}, + {0x2753, 0x2755}, + {0x2757, 0x2757}, + {0x2795, 0x2797}, + {0x27b0, 0x27b0}, + {0x27bf, 0x27bf}, + // Miscellaneous Symbols and Arrows + {0x2b1b, 0x2b1c}, + {0x2b50, 0x2b50}, + {0x2b55, 0x2b55}, + // CJK Radicals Supplement + {0x2e80, 0x2e99}, + {0x2e9b, 0x2ef3}, + // Kangxi Radicals + {0x2f00, 0x2fd5}, + // Ideographic Description Characters .. CJK Symbols and Punctuation + {0x2ff0, 0x303e}, + // Hiragana + {0x3041, 0x3096}, + // Hiragana .. Katakana + {0x3099, 0x30ff}, + // Bopomofo + {0x3105, 0x312f}, + // Hangul Compatibility Jamo + {0x3131, 0x318e}, + // Kanbun .. CJK Strokes + {0x3190, 0x31e5}, + // CJK Strokes .. Enclosed CJK Letters and Months + {0x31ef, 0x321e}, + // Enclosed CJK Letters and Months + {0x3220, 0x3247}, + // Enclosed CJK Letters and Months .. Yi Syllables + {0x3250, 0xa48c}, + // Yi Radicals + {0xa490, 0xa4c6}, + // Hangul Jamo Extended-A + {0xa960, 0xa97c}, + // Hangul Syllables + {0xac00, 0xd7a3}, + // CJK Compatibility Ideographs + {0xf900, 0xfaff}, + // Vertical Forms + {0xfe10, 0xfe19}, + // CJK Compatibility Forms .. Small Form Variants + {0xfe30, 0xfe52}, + // Small Form Variants + {0xfe54, 0xfe66}, + {0xfe68, 0xfe6b}, + // Halfwidth and Fullwidth Forms + {0xff01, 0xff60}, + {0xffe0, 0xffe6}, + // Ideographic Symbols and Punctuation + {0x16fe0, 0x16fe4}, + {0x16ff0, 0x16ff1}, + // Tangut + {0x17000, 0x187f7}, + // Tangut Components .. Khitan Small Script + {0x18800, 0x18cd5}, + // Khitan Small Script .. Tangut Supplement + {0x18cff, 0x18d08}, + // Kana Extended-B + {0x1aff0, 0x1aff3}, + {0x1aff5, 0x1affb}, + {0x1affd, 0x1affe}, + // Kana Supplement .. Kana Extended-A + {0x1b000, 0x1b122}, + // Small Kana Extension + {0x1b132, 0x1b132}, + {0x1b150, 0x1b152}, + {0x1b155, 0x1b155}, + {0x1b164, 0x1b167}, + // Nushu + {0x1b170, 0x1b2fb}, + // Tai Xuan Jing Symbols + {0x1d300, 0x1d356}, + // Counting Rod Numerals + {0x1d360, 0x1d376}, + // Mahjong Tiles + {0x1f004, 0x1f004}, + // Playing Cards + {0x1f0cf, 0x1f0cf}, + // Enclosed Alphanumeric Supplement + {0x1f18e, 0x1f18e}, + {0x1f191, 0x1f19a}, + // Enclosed Ideographic Supplement + {0x1f200, 0x1f202}, + {0x1f210, 0x1f23b}, + {0x1f240, 0x1f248}, + {0x1f250, 0x1f251}, + {0x1f260, 0x1f265}, + // Miscellaneous Symbols and Pictographs + {0x1f300, 0x1f320}, + {0x1f32d, 0x1f335}, + {0x1f337, 0x1f37c}, + {0x1f37e, 0x1f393}, + {0x1f3a0, 0x1f3ca}, + {0x1f3cf, 0x1f3d3}, + {0x1f3e0, 0x1f3f0}, + {0x1f3f4, 0x1f3f4}, + {0x1f3f8, 0x1f43e}, + {0x1f440, 0x1f440}, + {0x1f442, 0x1f4fc}, + {0x1f4ff, 0x1f53d}, + {0x1f54b, 0x1f54e}, + {0x1f550, 0x1f567}, + {0x1f57a, 0x1f57a}, + {0x1f595, 0x1f596}, + {0x1f5a4, 0x1f5a4}, + // Miscellaneous Symbols and Pictographs .. Emoticons + {0x1f5fb, 0x1f64f}, + // Transport and Map Symbols + {0x1f680, 0x1f6c5}, + {0x1f6cc, 0x1f6cc}, + {0x1f6d0, 0x1f6d2}, + {0x1f6d5, 0x1f6d7}, + {0x1f6dc, 0x1f6df}, + {0x1f6eb, 0x1f6ec}, + {0x1f6f4, 0x1f6fc}, + // Geometric Shapes Extended + {0x1f7e0, 0x1f7eb}, + {0x1f7f0, 0x1f7f0}, + // Supplemental Symbols and Pictographs + {0x1f90c, 0x1f93a}, + {0x1f93c, 0x1f945}, + {0x1f947, 0x1f9ff}, + // Symbols and Pictographs Extended-A + {0x1fa70, 0x1fa7c}, + {0x1fa80, 0x1fa89}, + {0x1fa8f, 0x1fac6}, + {0x1face, 0x1fadc}, + {0x1fadf, 0x1fae9}, + {0x1faf0, 0x1faf8}, + // CJK Unified Ideographs Extension B (plane 2) + {0x20000, 0x2fffd}, + // CJK Unified Ideographs Extension G (plane 3) + {0x30000, 0x3fffd}, }; - size_t lo = 0; - size_t hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); + size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; if (cp < wide_cp_ranges[mid].first) From d23b30b4e26cd22fb70c744671cd990b5f2ac7b0 Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Wed, 26 Aug 2026 13:50:17 +0200 Subject: [PATCH 8/9] Add inline to display_width_of and add 1F300-1F5FF and 1F900-1F9FF ranges to match [format.string.std] --- include/fmt/format.h | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index d6c8d02f809c..fbb9996cf373 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -649,7 +649,7 @@ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { } while (buf_ptr < buf + num_chars_left); } -FMT_CONSTEXPR auto display_width_of(uint32_t cp) noexcept -> size_t { +FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { if (cp < 0x1100) return 1; struct wide_cp_range { uint32_t first; @@ -782,26 +782,9 @@ FMT_CONSTEXPR auto display_width_of(uint32_t cp) noexcept -> size_t { {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, - // Miscellaneous Symbols and Pictographs - {0x1f300, 0x1f320}, - {0x1f32d, 0x1f335}, - {0x1f337, 0x1f37c}, - {0x1f37e, 0x1f393}, - {0x1f3a0, 0x1f3ca}, - {0x1f3cf, 0x1f3d3}, - {0x1f3e0, 0x1f3f0}, - {0x1f3f4, 0x1f3f4}, - {0x1f3f8, 0x1f43e}, - {0x1f440, 0x1f440}, - {0x1f442, 0x1f4fc}, - {0x1f4ff, 0x1f53d}, - {0x1f54b, 0x1f54e}, - {0x1f550, 0x1f567}, - {0x1f57a, 0x1f57a}, - {0x1f595, 0x1f596}, - {0x1f5a4, 0x1f5a4}, - // Miscellaneous Symbols and Pictographs .. Emoticons - {0x1f5fb, 0x1f64f}, + // Miscellaneous Symbols and Pictographs .. Emoticons, treated as + // fully wide per [format.string.std] regardless of East_Asian_Width. + {0x1f300, 0x1f64f}, // Transport and Map Symbols {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, @@ -813,10 +796,9 @@ FMT_CONSTEXPR auto display_width_of(uint32_t cp) noexcept -> size_t { // Geometric Shapes Extended {0x1f7e0, 0x1f7eb}, {0x1f7f0, 0x1f7f0}, - // Supplemental Symbols and Pictographs - {0x1f90c, 0x1f93a}, - {0x1f93c, 0x1f945}, - {0x1f947, 0x1f9ff}, + // Supplemental Symbols and Pictographs, treated as fully wide per + // [format.string.std] regardless of East_Asian_Width. + {0x1f900, 0x1f9ff}, // Symbols and Pictographs Extended-A {0x1fa70, 0x1fa7c}, {0x1fa80, 0x1fa89}, From 79afe09c1c5f45779c4d818a59aaf0203d7a0d4f Mon Sep 17 00:00:00 2001 From: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com> Date: Wed, 26 Aug 2026 17:37:43 +0200 Subject: [PATCH 9/9] Update display_width_of lo hi varible declaration --- include/fmt/format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index fbb9996cf373..fe299dc0fc1c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -811,7 +811,8 @@ FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { // CJK Unified Ideographs Extension G (plane 3) {0x30000, 0x3fffd}, }; - size_t lo = 0, hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); + size_t lo = 0; + size_t hi = sizeof(wide_cp_ranges) / sizeof(wide_cp_range); while (lo < hi) { size_t mid = lo + (hi - lo) / 2; if (cp < wide_cp_ranges[mid].first)