Skip to main content

graphemes

Function graphemes 

Source
pub fn graphemes(s: &str) -> Graphemes<'_> ⓘ
Expand description

Iterate the extended grapheme clusters of a string (UAX #29).

let g: Vec<&str> = graphemes("a👍🏽🇯🇵").collect();
assert_eq!(g, ["a", "👍🏽", "🇯🇵"]);
Examples found in repository?
examples/wrap_shrink.rs (line 7)
3fn bad(s: &str, w: usize) -> bool {
4    cellwidth::wrap(s, w).iter().any(|line| {
5        cellwidth::width(line) > w && {
6            let plain = cellwidth::strip_ansi(line);
7            cellwidth::graphemes(&plain)
8                .filter(|g| cellwidth::width(g) > 0)
9                .count()
10                > 1
11        }
12    })
13}