unicode-rs / unicode-width

Displayed width of Unicode characters and strings according to UAX#11 rules.
https://unicode-rs.github.io/unicode-width
Other
217 stars 27 forks source link

impl UnicodeWidthChar for u8 #2

Closed nrc closed 9 years ago

nrc commented 9 years ago

To replace the old unicode::str::utf8_char_width

kwantam commented 9 years ago

rustc_unicode::str::utf8_char_width is still there, though it's behind the unicode feature gate. I don't think there are any plans to deprecate utf8_char_width in librustc_unicode, since it has to do with UTF-8 representation, not Unicode semantics. I'll inquire.

More to the point, though: it's not really possible to implement UnicodeWidthChar for u8 (though I suppose it is for u32, or for &[u8]). The two senses of "width" (width() vs utf8_char_width()) are not the same. The former has to do with how many displayed columns a character takes up; the latter has to do with how many bytes it takes to represent a character in UTF-8.

nrc commented 9 years ago

@kwantam libunicode is gone from the distro. It does look like it is the wrong kind of width though. I should look in one of the other unicode libs.

kwantam commented 9 years ago

libunicode is renamed librustc_unicode. The following works on the 4/20 nightly:

#![feature(unicode)]

extern crate rustc_unicode;

use rustc_unicode::str as ustr;

fn main() {
    for i in (0 .. 256) {
        print!("{} ", ustr::utf8_char_width(i as u8));
    }
    println!("");
}