#text #width #unicode

no-std unicode-width

Determine displayed width of char and str types according to Unicode Standard Annex #11 rules

8 releases

0.1.6 Aug 19, 2019
0.1.5 May 19, 2018
0.1.4 Dec 23, 2016
0.1.3 Aug 20, 2015
0.0.1 Apr 14, 2015

#8 in Text processing

Download history 70626/week @ 2019-05-06 75941/week @ 2019-05-13 78619/week @ 2019-05-20 80566/week @ 2019-05-27 82875/week @ 2019-06-03 80863/week @ 2019-06-10 84835/week @ 2019-06-17 81498/week @ 2019-06-24 74246/week @ 2019-07-01 74577/week @ 2019-07-08 78308/week @ 2019-07-15 80224/week @ 2019-07-22 81765/week @ 2019-07-29 84074/week @ 2019-08-05 85552/week @ 2019-08-12

343,787 downloads per month
Used in 5,270 crates (89 directly)

MIT/Apache

46KB
621 lines

unicode-width

Determine displayed width of char and str types according to Unicode Standard Annex #11 rules.

Build Status

Documentation

extern crate unicode_width;

use unicode_width::UnicodeWidthStr;

fn main() {
    let teststr = "Hello, world!";
    let width = UnicodeWidthStr::width(teststr);
    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 column width. For example, the woman scientist emoji comprises of a woman emoji, a zero-width joiner and a microscope emoji.

extern crate unicode_width;
use unicode_width::UnicodeWidthStr;

fn main() {
    assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman
    assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope
    assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist
}

See Unicode Standard Annex #11 for precise details on what is and isn't covered by this crate.

features

unicode-width does not depend on libstd, so it can be used in crates with the #![no_std] attribute.

crates.io

You can use this package in your project by adding the following to your Cargo.toml:

[dependencies]
unicode-width = "0.1.5"

Dependencies

~135KB