Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A gross simple state machine
def join_quoted_strs(s):
r = ''
within_quotes = False
is_escaped = False
for c in s:
if within_quotes:
if is_escaped:
r += c
is_escaped = False
else:
if c == '\\':
is_escaped = True
elif c == '"':
within_quotes = False
else:
r += c
else:
if c == '"':
within_quotes = True
else:
assert c == " "
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.