Add support for ANSI-C quoted strings to shlex

This commit is contained in:
Kovid Goyal
2024-05-09 11:46:23 +05:30
parent 0d68a21be5
commit 098ed41716
4 changed files with 127 additions and 26 deletions

View File

@@ -1227,14 +1227,14 @@ def key_val_matcher(items: Iterable[Tuple[str, str]], key_pat: 're.Pattern[str]'
return False
def shlex_split(text: str) -> Iterator[str]:
s = Shlex(text)
def shlex_split(text: str, allow_ansi_quoted_strings: bool = False) -> Iterator[str]:
s = Shlex(text, allow_ansi_quoted_strings)
while (q := s.next_word())[0] > -1:
yield q[1]
def shlex_split_with_positions(text: str) -> Iterator[Tuple[int, str]]:
s = Shlex(text)
def shlex_split_with_positions(text: str, allow_ansi_quoted_strings: bool = False) -> Iterator[Tuple[int, str]]:
s = Shlex(text, allow_ansi_quoted_strings)
while (q := s.next_word())[0] > -1:
yield q