INNER CODE UNIT · Python

_extract_balanced

Far-Se/tabame · plugins/api-client/main.py:544

def _extract_balanced(text, start_idx):
    """Return the substring of a balanced {...} block starting at start_idx, respecting quoted strings."""
    depth, in_str, quote, escape = 0, False, "", False
    i, n = start_idx, len(text)
    while i < n:
        c = text[i]
        if in_str:
            if escape:
                escape = False
            elif c == "\\":
                escape = True
            elif c == quote:
                in_str = False
        else:
            if c in ('"', "'"):
                in_str, quote = True, c
            elif c == "{":
                depth += 1

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…