Whitespace tokenizer that keeps double-quoted values intact.
(src: &str)
| 331 | |
| 332 | /// Whitespace tokenizer that keeps double-quoted values intact. |
| 333 | fn tokenize(src: &str) -> Vec<String> { |
| 334 | let mut tokens = Vec::new(); |
| 335 | let mut cur = String::new(); |
| 336 | let mut in_quotes = false; |
| 337 | for c in src.chars() { |
| 338 | match c { |
| 339 | '"' => { |
| 340 | in_quotes = !in_quotes; |
| 341 | cur.push(c); |
| 342 | } |
| 343 | c if c.is_whitespace() && !in_quotes => { |
| 344 | if !cur.is_empty() { |
| 345 | tokens.push(std::mem::take(&mut cur)); |
| 346 | } |
| 347 | } |
| 348 | c => cur.push(c), |
| 349 | } |
| 350 | } |
| 351 | if !cur.is_empty() { |
| 352 | tokens.push(cur); |
| 353 | } |
| 354 | tokens |
| 355 | } |
| 356 | |
| 357 | #[cfg(test)] |
| 358 | mod tests { |
no test coverage detected