Split s on commas, except during quoted sections. Returns the parts and a list of error messages.
(s: str)
| 606 | |
| 607 | |
| 608 | def split_directive(s: str) -> tuple[list[str], list[str]]: |
| 609 | """Split s on commas, except during quoted sections. |
| 610 | |
| 611 | Returns the parts and a list of error messages.""" |
| 612 | parts = [] |
| 613 | cur: list[str] = [] |
| 614 | errors = [] |
| 615 | i = 0 |
| 616 | while i < len(s): |
| 617 | if s[i] == ",": |
| 618 | parts.append("".join(cur).strip()) |
| 619 | cur = [] |
| 620 | elif s[i] == '"': |
| 621 | i += 1 |
| 622 | while i < len(s) and s[i] != '"': |
| 623 | cur.append(s[i]) |
| 624 | i += 1 |
| 625 | if i == len(s): |
| 626 | errors.append("Unterminated quote in configuration comment") |
| 627 | cur.clear() |
| 628 | else: |
| 629 | cur.append(s[i]) |
| 630 | i += 1 |
| 631 | if cur: |
| 632 | parts.append("".join(cur).strip()) |
| 633 | |
| 634 | return parts, errors |
| 635 | |
| 636 | |
| 637 | def mypy_comments_to_config_map(line: str, template: Options) -> tuple[dict[str, str], list[str]]: |