Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -90,7 +90,8 @@
//! - Has [`Canonical_Combining_Class`] greater than 1, or
//! - Is a [default-ignorable][`Default_Ignorable_Code_Point`] [combining mark][combining marks].
//! 2. In all other cases, the width of the string equals the sum of its character widths:
//! 1. [`'\u{2D7F}'` TIFINAGH CONSONANT JOINER] has width 1 (outside of the ligatures described previously).
//! 1. [`'\u{2D7F}'` TIFINAGH CONSONANT JOINER], [`'\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) have width 1 (outside of the ligatures described previously).
Comment thread
tats-u marked this conversation as resolved.
Outdated
//! 2. [`'\u{115F}'` HANGUL CHOSEONG FILLER](https://util.unicode.org/UnicodeJsps/character.jsp?a=115F) and
//! [`'\u{17A4}'` KHMER INDEPENDENT VOWEL QAA](https://util.unicode.org/UnicodeJsps/character.jsp?a=17A4) have width 2.
//! 3. [`'\u{17D8}'` KHMER SIGN BEYYAL](https://util.unicode.org/UnicodeJsps/character.jsp?a=17D8) has width 3.
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