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 "