- Notifications
You must be signed in to change notification settings - Fork0
Displayed width of Unicode characters and strings according to UAX#11 rules.
License
correabuscar/unicode-width
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Determine displayed width ofchar andstr types according toUnicode Standard Annex #11and other portions of the Unicode standard.
This crate is#![no_std].
use unicode_width::UnicodeWidthStr;fnmain(){let teststr ="Hello, world!";let width = teststr.width();println!("{}", teststr);println!("The above string is {} columns wide.", width);let width = teststr.width_cjk();println!("The above string is {} columns wide (CJK).", width);}
NOTE: The computed width values may not match the actual rendered columnwidth. For example, the woman scientist emoji comprises of a woman emoji, azero-width joiner and a microscope emoji. Suchemoji ZWJ sequencesare considered to have the sum of the widths of their constituent parts:
externcrate unicode_width;use unicode_width::UnicodeWidthStr;fnmain(){assert_eq!("👩".width(),2);// Womanassert_eq!("🔬".width(),2);// Microscopeassert_eq!("👩🔬".width(),4);// Woman scientist}
Additionally,defective combining character sequencesand nonstandardKorean jamo sequences maybe rendered with a different width than what this crate says. (This is not anexhaustive list.)
You can use this package in your project by adding the followingto yourCargo.toml:
[dependencies]unicode-width ="0.1.11"
About
Displayed width of Unicode characters and strings according to UAX#11 rules.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Rust71.7%
- Python28.3%