MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / tokenize

Function tokenize

atomic-canonical/src/directive.rs:333–355  ·  view source on GitHub ↗

Whitespace tokenizer that keeps double-quoted values intact.

(src: &str)

Source from the content-addressed store, hash-verified

331
332/// Whitespace tokenizer that keeps double-quoted values intact.
333fn 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)]
358mod tests {

Callers 1

parse_attrsFunction · 0.70

Calls 3

pushMethod · 0.45
is_whitespaceMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected