Skip to content

Rust library for unicode-aware algorithm to pad or truncate `str` in terms of displayed width.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Aetf/unicode-truncate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

95b4d26 · Nov 10, 2024

History

47 Commits
Nov 10, 2024
Jun 25, 2024
Nov 9, 2024
Apr 24, 2024
Apr 25, 2024
Nov 10, 2024
Aug 14, 2019
Nov 10, 2024
Nov 10, 2024
Aug 14, 2019
Aug 14, 2019
Apr 25, 2024
Jun 24, 2024

Repository files navigation

unicode-truncate

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

crates.io Documentation Build Status

Examples

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

use unicode_truncate::UnicodeTruncateStr;

fn main() {
    assert_eq!("你好吗".unicode_truncate(5), ("你好", 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;

fn main() {
    let str = "你好吗".unicode_pad(5, Alignment::Left, true);
    assert_eq!(str, "你好 ");
    assert_eq!(str.width(), 5);
}

Features

unicode-truncate can be built without std by disabling the default feature std. However, in that case unicode_truncate::UnicodeTruncateStr::unicode_pad won't be available because it depends on std::string::String and std::borrow::Cow.

About

Rust library for unicode-aware algorithm to pad or truncate `str` in terms of displayed width.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages