unicode width 16
1.0.0
このクレートは、https://github.com/unicode-rs/unicode-widthのフォークであり、 Unicode 16サポートと削除normalization削除されます。
Unicode Standard Annex#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-widthはLIBSTDに依存しないため、 #![no_std]属性を使用してクレートで使用できます。
このパッケージをプロジェクトで使用して、 Cargo.tomlに以下を追加できます。TOML:
[ dependencies ]
unicode-width-16 = " 0.1.0 "