INNER CODE UNIT · Python
_mapping_pair
christopherkarani/Wax · Resources/hermes/wax-memory-plugin/cli.py:86
def _mapping_pair(value: str) -> tuple[str, str] | None:
depth = 0
quote = ""
for index, character in enumerate(value):
if character in {"'", '"'}:
if not quote:
quote = character
elif quote == character:
quote = ""
elif not quote:
if character in "{[":
depth += 1
elif character in "}]":
depth -= 1
elif character == ":" and depth == 0:
return _yaml_key(value[:index]), value[index + 1:].strip()
return None