Handle quotes and debug stripping of last element

This commit is contained in:
Adrien Ufferte
2025-08-18 13:20:30 +02:00
parent 01f7c2b9c7
commit 946427a896
2 changed files with 58 additions and 10 deletions
+29 -5
View File
@@ -7,21 +7,45 @@ def split_params(param_string: str):
"""Split parameters on commas while ignoring nested structures.""" """Split parameters on commas while ignoring nested structures."""
params = [] params = []
current = "" current = ""
stack = [] stack: list[str] = []
pairs = {')': '(', ']': '[', '}': '{'} pairs = {')': '(', ']': '[', '}': '{'}
in_quote = None
escape = False
for char in param_string: for char in param_string:
if escape:
current += char
escape = False
continue
if char == "\\":
current += char
escape = True
continue
if in_quote:
current += char
if char == in_quote:
in_quote = None
continue
if char in "'\"":
current += char
in_quote = char
continue
if char in '([{': if char in '([{':
stack.append(char) stack.append(char)
elif char in ')]}': elif char in ')]}':
if stack and stack[-1] == pairs.get(char): if stack and stack[-1] == pairs.get(char):
stack.pop() stack.pop()
if char == ',' and not stack: if char == ',' and not stack:
params.append(current.strip()) params.append(current.strip())
current = "" current = ""
continue else:
current += char current += char
if current:
params.append(current.strip()) params.append(current.strip())
return params return params
EXCLUDED_DIRS = {"addons", ".git", ".github"} EXCLUDED_DIRS = {"addons", ".git", ".github"}
+29 -5
View File
@@ -7,21 +7,45 @@ def split_params(param_string: str):
"""Split parameters on commas while ignoring nested structures.""" """Split parameters on commas while ignoring nested structures."""
params = [] params = []
current = "" current = ""
stack = [] stack: list[str] = []
pairs = {')': '(', ']': '[', '}': '{'} pairs = {')': '(', ']': '[', '}': '{'}
in_quote = None
escape = False
for char in param_string: for char in param_string:
if escape:
current += char
escape = False
continue
if char == "\\":
current += char
escape = True
continue
if in_quote:
current += char
if char == in_quote:
in_quote = None
continue
if char in "'\"":
current += char
in_quote = char
continue
if char in '([{': if char in '([{':
stack.append(char) stack.append(char)
elif char in ')]}': elif char in ')]}':
if stack and stack[-1] == pairs.get(char): if stack and stack[-1] == pairs.get(char):
stack.pop() stack.pop()
if char == ',' and not stack: if char == ',' and not stack:
params.append(current.strip()) params.append(current.strip())
current = "" current = ""
continue else:
current += char current += char
if current:
params.append(current.strip()) params.append(current.strip())
return params return params
EXCLUDED_DIRS = {"addons", ".git", ".github"} EXCLUDED_DIRS = {"addons", ".git", ".github"}