MCPcopy
hub / github.com/github/spec-kit / _split_top_level_commas

Function _split_top_level_commas

src/specify_cli/workflows/expressions.py:186–217  ·  view source on GitHub ↗

Split *text* on commas that are not inside quotes or nested brackets. Used for list-literal elements so a quoted element containing a comma (e.g. ``["a, b", "c"]``) is not split mid-string, and nested lists/calls (e.g. ``[[1, 2], 3]``) are kept intact.

(text: str)

Source from the content-addressed store, hash-verified

184
185
186def _split_top_level_commas(text: str) -> list[str]:
187 """Split *text* on commas that are not inside quotes or nested brackets.
188
189 Used for list-literal elements so a quoted element containing a comma
190 (e.g. ``["a, b", "c"]``) is not split mid-string, and nested lists/calls
191 (e.g. ``[[1, 2], 3]``) are kept intact.
192 """
193 parts: list[str] = []
194 buf: list[str] = []
195 quote: str | None = None
196 depth = 0
197 for ch in text:
198 if quote is not None:
199 buf.append(ch)
200 if ch == quote:
201 quote = None
202 elif ch in ("'", '"'):
203 quote = ch
204 buf.append(ch)
205 elif ch in "([{":
206 depth += 1
207 buf.append(ch)
208 elif ch in ")]}":
209 depth = max(0, depth - 1)
210 buf.append(ch)
211 elif ch == "," and depth == 0:
212 parts.append("".join(buf))
213 buf = []
214 else:
215 buf.append(ch)
216 parts.append("".join(buf))
217 return parts
218
219
220def _find_top_level(text: str, token: str) -> int:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected