Skip to content

Commit

Permalink
optrx: escape special characters and fix mangled suffix coalescing wh…
Browse files Browse the repository at this point in the history
…en input is like 'tee tie'
  • Loading branch information
laniakea64 committed Dec 17, 2023
1 parent db122b7 commit e2e42ae
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ allFunctions := functionsWithArgs + zeroArgFunctions
optrx +strings:
#!/usr/bin/env python3
vparam = """{{strings}}"""
import collections
import collections, re
strings_list = vparam.split('|') if '|' in vparam else vparam.strip().split()
vimSpecialChars = tuple('~@$%^&*()+=[]{}\\|<>.?')
def vimEscape(c):
if type(c) is str and len(c) < 2:
return f'\\{c}' if c in vimSpecialChars else c
raise TypeError(f'{c!r} is not a character')
charByPrefix=dict()
for f in strings_list:
if len(f) < 1: continue
g=collections.deque(f)
g=collections.deque(map(vimEscape, f))
p=charByPrefix
while len(g):
if g[0] not in p: p[g[0]] = dict()
Expand Down Expand Up @@ -160,6 +165,9 @@ optrx +strings:
while len(tryCommonEnd):
c=0
for j in ss:
if re.search(r'%\((?:[^)]|\\\))+$', j):
# don't compare suffix in inner group to suffix of outer group
continue
c += int(j.endswith(tryCommonEnd))
if c == len(ss):
commonEnd = tryCommonEnd
Expand Down

0 comments on commit e2e42ae

Please sign in to comment.