Skip to content

Fix utf8 display width - #4890

Closed
Satyakam-Mishra wants to merge 4 commits into
fmtlib:mainfrom
Satyakam-Mishra:fix-utf8-display-width
Closed

Fix utf8 display width#4890
Satyakam-Mishra wants to merge 4 commits into
fmtlib:mainfrom
Satyakam-Mishra:fix-utf8-display-width

Conversation

@Satyakam-Mishra

Copy link
Copy Markdown

Description

Fixes incorrect display width calculation for UTF-8 characters in formatted
strings.

Characters with East Asian Width properties W and F are treated as
double-width when calculating display width. The implementation uses a binary
search over a generated Unicode range table.

This fixes alignment issues for characters such as emoji and CJK characters.

Regional Indicator symbols are not included as double-width ranges, so flag
sequences such as 🇺🇸 are handled correctly.

Testing

Added regression tests covering:

  • 😀
  • 🇺🇸
  • Müller

All tests pass:

  • 21/21 tests passed
  • git diff --check passes

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add new headers.

@Satyakam-Mishra

Copy link
Copy Markdown
Author

Thank you, I have removed the separate unicode_width_table.h header and moved the unicode with table to format.h as suggested. I have also rerun the tests and it still passes. Pushing the update now.

@Satyakam-Mishra
Satyakam-Mishra requested a review from vitaut August 25, 2026 16:47
@vitaut

vitaut commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #4896 but thanks anyway.

@vitaut vitaut closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants