Fix inconsistent display width for emoji outside East Asian Wide ranges - #4896
Open
edugomz wants to merge 9 commits into
Open
Fix inconsistent display width for emoji outside East Asian Wide ranges#4896edugomz wants to merge 9 commits into
edugomz wants to merge 9 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.
vitaut
requested changes
Aug 25, 2026
vitaut
left a comment
Contributor
There was a problem hiding this comment.
The standard width rules are not just East_Asian_Width=W/F; [format.string.std] also explicitly includes 1F300–1F5FF and 1F900–1F9FF.
vitaut
reviewed
Aug 25, 2026
Closed
…nges to match [format.string.std]
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
Continues #4865 with the requested changes addressed:
East_Asian_Width=W/Fdata instead ofEmoji_Presentation, so regional indicators (flag halves) aren't individually double-counted - 🇺🇸 still measures 2 columns, not 4display_width_of()remainsFMT_CONSTEXPRTesting
Regression tests added to
test/format-test.cc: the #4851 example, multiple/mixed emoji, precision truncation, alignment, newly-covered ranges, and a regional indicator (flag) pair.