| commit | 08bb2463cdd2d0b43e613652852f3a8459e4794d | [log] [tgz] |
|---|---|---|
| author | Android Build Coastguard Worker <[email protected]> | Sun Sep 29 07:13:53 2024 +0000 |
| committer | Android Build Coastguard Worker <[email protected]> | Sun Sep 29 07:13:53 2024 +0000 |
| tree | 51618264976904c2126fec07194010352cd58915 | |
| parent | b4209d673a1389509ec2d99b240ee9864fa0c8c3 [diff] | |
| parent | a16641d5688f1e7719c52e623abe672a1d874e99 [diff] |
Snap for 12416476 from a16641d5688f1e7719c52e623abe672a1d874e99 to busytown-mac-infra-release Change-Id: I7ebc46b0c4b148ea76607f65a15e0d17929a0c37
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.