commit | 57887dd695e28e63cc938dc901efa0196c115ad5 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Mar 04 02:05:56 2022 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Mar 04 02:05:56 2022 +0000 |
tree | ed23f02709b7a5c4ccfef074596728ff950fe78e | |
parent | d9190ed598a38c371cbe383a4d5c8eb4df1043db [diff] | |
parent | ca6c3ad74a310ba9da4b09a10a874e15b6b3a74d [diff] |
Snap for 8249732 from ca6c3ad74a310ba9da4b09a10a874e15b6b3a74d to tm-release Change-Id: I8b904d489965091ef142333050dd19604c058c23
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.9.0"
GraphemeCursor
API allows random access and bidirectional iteration.as_str
methods to the iterator types.