From e2e42ae765f53569efb7178a7bbb9a6977d269e2 Mon Sep 17 00:00:00 2001 From: laniakea64 Date: Sun, 17 Dec 2023 12:08:07 -0500 Subject: [PATCH] optrx: escape special characters and fix mangled suffix coalescing when input is like 'tee tie' --- justfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index 25f70cf..9debb7d 100644 --- a/justfile +++ b/justfile @@ -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() @@ -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