properly escape `\[`

This commit is contained in:
Daylin Morgan 2023-09-11 00:30:29 -05:00
parent 780c60ad7e
commit 887a724606
Signed by: daylin
GPG Key ID: C1E52E7DD81DF79F
1 changed files with 8 additions and 1 deletions

View File

@ -17,7 +17,14 @@ proc bb*(s: string): string =
while i < s.len:
# start extracting pattern when you see '[' but not '[['
if s[i] == '[' and preChar notin {'\\','['} and s[i+1] != '[':
if s[i] == '\\':
inc i
if s[i] == '[':
result.add s[i]
inc i
continue
if s[i] == '[' and preChar != '\\':
inc i
while i < s.len and s[i] != ']':
preChar = s[i]