Split comma-separated assignments, handling quoted strings
(assignments_str: &str)
| 617 | |
| 618 | /// Split comma-separated assignments, handling quoted strings |
| 619 | fn split_assignments(assignments_str: &str) -> Vec<String> { |
| 620 | let mut assignments = Vec::new(); |
| 621 | let mut current = String::new(); |
| 622 | let mut in_quotes = false; |
| 623 | let mut quote_char = ' '; |
| 624 | let mut paren_depth = 0; |
| 625 | |
| 626 | for ch in assignments_str.chars() { |
| 627 | match ch { |
| 628 | '\'' | '"' if !in_quotes => { |
| 629 | in_quotes = true; |
| 630 | quote_char = ch; |
| 631 | current.push(ch); |
| 632 | } |
| 633 | ch if ch == quote_char && in_quotes => { |
| 634 | in_quotes = false; |
| 635 | current.push(ch); |
| 636 | } |
| 637 | '(' if !in_quotes => { |
| 638 | paren_depth += 1; |
| 639 | current.push(ch); |
| 640 | } |
| 641 | ')' if !in_quotes => { |
| 642 | paren_depth -= 1; |
| 643 | current.push(ch); |
| 644 | } |
| 645 | ',' if !in_quotes && paren_depth == 0 => { |
| 646 | assignments.push(current.trim().to_string()); |
| 647 | current.clear(); |
| 648 | } |
| 649 | _ => current.push(ch), |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if !current.is_empty() { |
| 654 | assignments.push(current.trim().to_string()); |
| 655 | } |
| 656 | |
| 657 | assignments |
| 658 | } |
| 659 | |
| 660 | #[cfg(test)] |
| 661 | mod tests { |
no test coverage detected