simplify token replace, catch one-char end-of-string tokens

This commit is contained in:
jesopo 2019-12-21 21:40:44 +00:00
parent 2218d4a888
commit b2c5ad041c

View file

@ -129,12 +129,8 @@ def format_tokens(s: str, names: typing.List[str], sigil: str="$"
while i < max:
if s[i] == sigil:
if s[i+1] == sigil:
if not s[i+1] == sigil:
i += 1
else:
sigil_found = True
elif sigil_found:
sigil_found = False
for name in names:
if len(name) <= (len(s)-i) and s[i:i+len(name)] == name:
tokens.append((i-1, "%s%s" % (sigil, name)))