commit | c36c0749aba82e330eca43b672d7e65c6fd013d4 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <[email protected]> | Fri Mar 10 05:18:15 2023 +0000 |
committer | Android Build Coastguard Worker <[email protected]> | Fri Mar 10 05:18:15 2023 +0000 |
tree | a56d56ffb52987fa7b8502500dd0912ab98e2278 | |
parent | 1c36b1abb7d9db79b28a7c0022fefdcc3a37430f [diff] | |
parent | 5a7db1201128997b9acfd8a2996dcea12c0ceb83 [diff] |
Snap for 9722771 from 5a7db1201128997b9acfd8a2996dcea12c0ceb83 to udc-d1-release Change-Id: Ie02fa3aa6c7348598755223f0aa2fcfce481e0ec
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.