Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ def load_zero_widths() -> list[bool]:
lambda cp: operator.setitem(zw_map, cp, True),
)

# HALFWIDTH KATAKANA VOICED SOUND MARK and HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
# are `Lm` letters even though they currently carry `Grapheme_Extend`.
# They occupy their own cell in terminal-style width calculations.
zw_map[0xFF9E] = False
zw_map[0xFF9F] = False

# Treat `Hangul_Syllable_Type`s of `Vowel_Jamo` and `Trailing_Jamo`
# as zero-width. This matches the behavior of glibc `wcwidth`.
#
Expand Down
6 changes: 3 additions & 3 deletions src/gen/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ pub(crate) static WIDTH_LEAVES: Align32<[[u8; 32]; WIDTH_LEAVES_LEN]> = Align32(
0x55, 0x55,
],
[
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x05, 0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xAA, 0x6A, 0x55, 0x55, 0x00, 0x00,
0x54, 0x55,
],
Expand Down Expand Up @@ -1157,7 +1157,7 @@ pub(crate) static WIDTH_LEAVES: Align32<[[u8; 32]; WIDTH_LEAVES_LEN]> = Align32(
],
#[cfg(feature = "cjk")]
[
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x05, 0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xAA, 0x6A, 0x55, 0x55, 0x00, 0x00,
0x54, 0x59,
],
Expand Down Expand Up @@ -1217,7 +1217,7 @@ pub(crate) static NON_TRANSPARENT_ZERO_WIDTHS: [([u8; 3], [u8; 3]); 71] = [
([0xC0, 0xA9, 0x00], [0xC0, 0xA9, 0x00]),
([0xB0, 0xD7, 0x00], [0xC6, 0xD7, 0x00]),
([0xCB, 0xD7, 0x00], [0xFB, 0xD7, 0x00]),
([0x9E, 0xFF, 0x00], [0xA0, 0xFF, 0x00]),
([0xA0, 0xFF, 0x00], [0xA0, 0xFF, 0x00]),
([0xF0, 0xFF, 0x00], [0xF8, 0xFF, 0x00]),
([0xC0, 0x11, 0x01], [0xC0, 0x11, 0x01]),
([0xC2, 0x11, 0x01], [0xC3, 0x11, 0x01]),
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BDefault_Ignorable_Code_Point%7D)
//! with the [`Default_Ignorable_Code_Point`] property.
//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BGrapheme_Extend%7D)
//! with the [`Grapheme_Extend`] property.
//! with the [`Grapheme_Extend`] property, except [`'\u{FF9E}'` HALFWIDTH KATAKANA VOICED SOUND MARK](https://util.unicode.org/UnicodeJsps/character.jsp?a=FF9E)
//! and [`'\u{FF9F}'` HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK](https://util.unicode.org/UnicodeJsps/character.jsp?a=FF9F).
Comment on lines +101 to +102
Copy link
Copy Markdown
Contributor

@Jules-Bertholet Jules-Bertholet May 27, 2026

Choose a reason for hiding this comment

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

Instead of making this a carve-out in rule 4, I think these should be added to rule 1 above. In other word, replace "U+2D7F has width 1" above with "U+2D7F, U+FF9E, and U+FF9F have width 1".

//! - [Characters](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BHangul_Syllable_Type%3DV%7D%5Cp%7BHangul_Syllable_Type%3DT%7D)
//! with a [`Hangul_Syllable_Type`] of `Vowel_Jamo` (`V`) or `Trailing_Jamo` (`T`).
//! - The following [`Prepended_Concatenation_Mark`]s:
Expand Down
7 changes: 7 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ fn test_emoji() {
assert_width!("👩‍🔬", 2, 2); // Woman scientist
}

#[test]
fn test_halfwidth_katakana() {
assert_width!("パグ", 4, 4); // Halfwidth Katakana letters Pa, Gu (pug dog)
}

// From README
#[test]
fn test_bad_devanagari() {
Expand All @@ -63,6 +68,8 @@ fn test_char2() {
assert_width!('\u{1160}', Some(0), Some(0));
assert_width!('\u{a1}', Some(1), Some(2));
assert_width!('\u{300}', Some(0), Some(0));
assert_width!('\u{FF9E}', Some(1), Some(1));
assert_width!('\u{FF9F}', Some(1), Some(1));
}

#[test]
Expand Down
Loading