Function quoted_words

Source
pub fn quoted_words<'a, W>(phrase: W) -> impl Iterator<Item = Substr<'a>>
where W: Into<Substr<'a>>,
Expand description

Iterate through all words in the input, treating multiple words surrounded by quotation marks as a single word. Returns Substr objects, preserving the word’s context within the larger string.

§Examples

let mut iter = quoted_words(r#"   Ronny  "Two Spoons" Johnson  "#)
    .map(|substr| substr.as_str());

assert_eq!(Some("Ronny"), iter.next());
assert_eq!(Some("Two Spoons"), iter.next());
assert_eq!(Some("Johnson"), iter.next());
assert_eq!(None, iter.next());

§Interacting with the Substr object

let mut iter = quoted_words(r#"   Ronny  "Two Spoons" Johnson  "#);
let word = iter.nth(1).unwrap();

assert_eq!("Two Spoons", word.as_str());
assert_eq!(r#""Two Spoons""#, word.as_outer_str());
assert_eq!(" Johnson  ", word.after().as_str());
assert_eq!(r#"   Ronny  "Two Spoons" Johnson  "#, word.as_original_str());