Skip to main content

str_width

Function str_width 

Source
pub fn str_width(s: &str) -> usize
Expand description

Returns the total monospace width of s: the sum of char_width over its scalar values.

§Examples

use unicode_lang::str_width;

assert_eq!(str_width("hello"), 5);
assert_eq!(str_width("日本語"), 6);      // three wide ideographs
assert_eq!(str_width("café"), 4);        // precomposed é is one column

// A base letter plus a combining mark still advances by one column.
assert_eq!(str_width("e\u{0301}"), 1);   // e + COMBINING ACUTE ACCENT