commit | b587497f55301cfac33be85e1bba17194d1b7b92 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <[email protected]> | Sat Sep 21 01:16:23 2024 +0000 |
committer | Android Build Coastguard Worker <[email protected]> | Sat Sep 21 01:16:23 2024 +0000 |
tree | 51618264976904c2126fec07194010352cd58915 | |
parent | 0d7f81bcd5ca6146ba4aa14c5c0a40c1b4e3c069 [diff] | |
parent | d9754c9ab7dfbf942771a38afd741ee3a7164991 [diff] |
Snap for 12397640 from d9754c9ab7dfbf942771a38afd741ee3a7164991 to 24Q4-release Change-Id: I453674070cff19bd9f5da396506d699c82b09f75
Iterators which split strings on Grapheme Cluster or Word boundaries, according to the Unicode Standard Annex #29 rules.
use unicode_segmentation::UnicodeSegmentation; fn main() { let s = "a̐éö̲\r\n"; let g = s.graphemes(true).collect::<Vec<&str>>(); let b: &[_] = &["a̐", "é", "ö̲", "\r\n"]; assert_eq!(g, b); let s = "The quick (\"brown\") fox can't jump 32.3 feet, right?"; let w = s.unicode_words().collect::<Vec<&str>>(); let b: &[_] = &["The", "quick", "brown", "fox", "can't", "jump", "32.3", "feet", "right"]; assert_eq!(w, b); let s = "The quick (\"brown\") fox"; let w = s.split_word_bounds().collect::<Vec<&str>>(); let b: &[_] = &["The", " ", "quick", " ", "(", "\"", "brown", "\"", ")", " ", " ", "fox"]; assert_eq!(w, b); }
unicode-segmentation does not depend on libstd, so it can be used in crates with the #![no_std]
attribute.
You can use this package in your project by adding the following to your Cargo.toml
:
[dependencies] unicode-segmentation = "1.10.1"
GraphemeCursor
API allows random access and bidirectional iteration.as_str
methods to the iterator types.