Skip to content

Introduce UAX #14 Line breaking into wrap() - #322

Merged
jquast merged 4 commits into
masterfrom
jq/unicode-word-wrap
Nov 13, 2026
Merged

jquast merged 4 commits into
masterfrom
jq/unicode-word-wrap

Conversation

@jquast

@jquast jquast commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

It seems only proper, as a unicode library, that our wrap() functions implement the UAX #14 line breaking algorithm.

This is on by default, with new default wrap(..., line_break='unicode') argument. Use line_break='ascii' to match original std python behavior.

UAX #14 is often criticized for its complexity, which can be seen through our implementation, and that some of the special unicode points like SOFT HYPHEN are very infrequently implemented correctly in text viewers, editors, etc., that it usually "stuffs up" rather than helps, these are sometimes used in web content, and people can sometimes copy and paste them into files and terminals where they are hidden (zero width) with sometimes strange or disastrous effects, or UnicodeDecodeError, for what appears to the human eye to contain only ASCII.

These codes have provided a lot of folks a lot of grief. Only to say, this might induce surprising word wrap behavior to downstream users because of these strange unicode codepoints, many people are unaware of their presence

@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.3

3 warnings

⚠️ Upgrade your CodSpeed plugin for Python 3.15

pytest-codspeed 5.0.3 is only tested on Python 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14, so your Python 3.15 measurements may be inaccurate. Upgrade pytest-codspeed to 5.0.4 or later.

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

⚡ 1 improved benchmark
✅ 141 untouched benchmarks
🆕 4 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_wrap_japanese 11.6 ms 3.6 ms ×3.3
🆕 test_iter_line_breaks_ascii N/A 1.1 ms N/A
🆕 test_iter_line_breaks_long_text N/A 5 ms N/A
🆕 test_wrap_long_text_ascii_mode N/A 6.2 ms N/A
🆕 test_wrap_regional_indicators N/A 2 ms N/A

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing jq/unicode-word-wrap (350297b) with master (bff731c)

Open in CodSpeed

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.25520% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.07%. Comparing base (bff731c) to head (350297b).

Files with missing lines Patch % Lines
libwcwidth/src/textwrap.c 86.46% 0 Missing and 18 partials ⚠️
libwcwidth/src/linebreak.c 96.59% 0 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #322      +/-   ##
==========================================
+ Coverage   88.74%   90.07%   +1.32%     
==========================================
  Files          41       44       +3     
  Lines        5677     6447     +770     
  Branches     1526     1810     +284     
==========================================
+ Hits         5038     5807     +769     
+ Misses        254      241      -13     
- Partials      385      399      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast
jquast force-pushed the jq/unicode-word-wrap branch from f4ec14e to 614a8cf Compare November 12, 2026 19:51
@jquast
jquast merged commit 6cb47aa into master Nov 13, 2026
37 of 38 checks passed
@jquast
jquast deleted the jq/unicode-word-wrap branch November 13, 2026 13:55
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.

1 participant