unicode width 16
1.0.0
该板条箱是https://github.com/unicode-rs/unicode-width的叉子,并带有Unicode 16支持并删除了normalization 。
根据Unicode标准附件#11规则确定char和str类型的宽度。
use unicode_width_16 :: 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 ) ;
}注意:计算的宽度值可能与实际渲染列宽度不匹配。例如,女科学家表情符号包括一个女性表情符号,零宽的木匠和显微镜表情符号。
use unicode_width_16 :: UnicodeWidthStr ;
fn main ( ) {
assert_eq ! ( UnicodeWidthStr ::width ( "?" ) , 2 ) ; // Woman
assert_eq ! ( UnicodeWidthStr ::width ( "?" ) , 2 ) ; // Microscope
assert_eq ! ( UnicodeWidthStr ::width ( "??" ) , 4 ) ; // Woman scientist
}有关此板条箱的确切详细信息,请参见Unicode Standard Annex#11。
Unicode宽度不取决于libstd,因此可以在带有#![no_std]属性的板条箱中使用。
您可以通过将以下内容添加到您的Cargo.toml中:
[ dependencies ]
unicode-width-16 = " 0.1.0 "