Fix inconsistent display width for emoji outside East Asian Wide ranges - #4865
Open
edugomz wants to merge 3 commits into
Open
Fix inconsistent display width for emoji outside East Asian Wide ranges#4865edugomz wants to merge 3 commits into
edugomz wants to merge 3 commits into
Conversation
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 fmtlib#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.
edugomz
marked this pull request as ready for review
July 28, 2026 19:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4851
Problem
display_width_of()only counted East Asian Wide/Fullwidth code points and two hand-picked emoji ranges (U+1F300-1F64F, U+1F900-1F9FF) as 2 columns wide{:^N}padding vs. CJK textFix
Emoji_Presentationset from Unicode'semoji-data.txt(fetched from unicode.org, not hand-transcribed)Testing
Added regression tests (
test/format-test.cc) for:Full suite passes: 147/147
format-test, 21/21ctestbinaries.