Skip to content

Commit 6e52282

Browse files
committed
Add LINE SEPARATOR and PARAGRAPH SEPARATOR as zero-width
1 parent 731798b commit 6e52282

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Index fixes and updates:
1515

1616
- Private-use characters are considered ambiguous (were given width 1 before)
1717
- Fix that some zero-width ignorable codepoints from recent Unicode were missing
18+
- Consider the following separators to be zero-width:
19+
- U+2028 - LINE SEPARATOR - Zl
20+
- U+2029 - PARAGRAPH SEPARATOR - Zp
1821

1922
Other:
2023

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](https://badge.fury.io/rb/unicode-display_width) [<img src="https://github.com/janlelis/unicode-display_width/workflows/Test/badge.svg" />](https://github.com/janlelis/unicode-display_width/actions?query=workflow%3ATest)
22

3-
Determines the monospace display width of a string in Ruby. Useful for all kinds of terminal-based applications. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. It does not rely on the OS vendor (like [wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an up-to-date method for measuring string width.
3+
Determines the monospace display width of a string in Ruby. Useful for all kinds of terminal-based applications. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. It does not rely on the OS vendor (like [wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an up-to-date method for measuring string width in terminals.
44

55
Unicode version: **16.0.0** (September 2024)
66

@@ -12,7 +12,7 @@ Unicode version: **16.0.0** (September 2024)
1212

1313
**If you use this gem, you should really upgrade to 2.4.2 or newer. It's often 100x faster, sometimes even 1000x and more!**
1414

15-
This is possible because the gem now detects if you use very basic (and common) characters, like ASCII characters. Furthermore, the charachter width lookup code has been optimized, so even when full-width or ambiguous characters are involved, the gem is much faster now.
15+
This is possible because the gem now detects if you use very basic (and common) characters, like ASCII characters. Furthermore, the character width lookup code has been optimized, so even when the string involves full-width or ambiguous characters, the gem is much faster now.
1616

1717
## Introduction to Character Widths
1818

@@ -31,7 +31,7 @@ Width | Characters | Comment
3131
1 | `"\u{00AD}"` | SOFT HYPHEN
3232
2 | `"\u{2E3A}"` | TWO-EM DASH
3333
3 | `"\u{2E3B}"` | THREE-EM DASH
34-
0 | General Categories: Mn, Me, Cf (non-arabic) | Excludes ARABIC format characters
34+
0 | General Categories: Mn, Me, Zl, Zp, Cf (non-arabic)| Excludes ARABIC format characters
3535
0 | Derived Property: Default_Ignorable_Code_Point | Ignorable ranges
3636
0 | `"\u{1160}".."\u{11FF}"`, `"\u{D7B0}".."\u{D7FF}"` | HANGUL JUNGSEONG
3737
2 | East Asian Width: F, W | Full-width characters

data/display_width.marshal.gz

-4 Bytes
Binary file not shown.

spec/display_width_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@
142142
expect( "\x7f".display_width ).to eq 1
143143
end
144144

145+
it 'returns 0 for LINE SEPARATOR' do
146+
expect( "\u{2028}".display_width ).to eq 0
147+
end
148+
149+
it 'returns 0 for PARAGRAPH SEPARATOR' do
150+
expect( "\u{2029}".display_width ).to eq 0
151+
end
152+
145153
it 'returns 1 for SOFT HYPHEN' do
146154
expect( "­".display_width ).to eq 1
147155
end

0 commit comments

Comments
 (0)