Skip to main content

char_width

Function char_width 

Source
pub fn char_width(c: char) -> usize
Expand description

Returns the number of monospace columns c occupies: 0, 1, or 2.

See the module-level documentation for the exact contract.

§Examples

use unicode_lang::char_width;

assert_eq!(char_width('A'), 1);
assert_eq!(char_width('世'), 2);          // CJK ideograph, wide
assert_eq!(char_width('\u{0301}'), 0);    // COMBINING ACUTE ACCENT
assert_eq!(char_width('\n'), 0);          // control characters take no column
assert_eq!(char_width('\u{200B}'), 0);    // ZERO WIDTH SPACE