[][src]Crate unicode_truncate

Unicode-aware algorithm to pad or truncate str in terms of displayed width.

See the UnicodeTruncateStr trait for new methods available on str.


Safely truncate string to display width even not at character boundaries.

use unicode_truncate::UnicodeTruncateStr;

let (rv, w) = "你好吗".unicode_truncate(5);
assert_eq!(rv, "你好");
assert_eq!(w, 4);

Making sure the string is displayed in exactly number of columns by combining padding and truncating.

use unicode_truncate::UnicodeTruncateStr;
use unicode_truncate::Alignment;
use unicode_width::UnicodeWidthStr;

let rv = "你好吗".unicode_pad(5, Alignment::Left, true);
assert_eq!(rv, "你好 ");
assert_eq!(rv.width(), 5);



Defines the alignment for padding. Only available when the std feature of this library is activated, and it is activated by default.



Methods for padding or truncating using displayed width of Unicode strings.