Handle quotes and debug stripping of last element
This commit is contained in:
@@ -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"}
|
||||||
|
|||||||
@@ -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"}
|
||||||
|
|||||||
Reference in New Issue
Block a user