BUGFIX: Protect () and [] in searches

This commit is contained in:
Tim Mahrt
2016-07-18 17:08:02 +02:00
parent 4056b105c9
commit bce3c8ff23
+17 -3
View File
@@ -102,9 +102,23 @@ def _prepRESearchStr(matchStr, wordInitial='ok', wordFinal='ok',
# Protect sounds that are two characters # Protect sounds that are two characters
# After this we can assume that each character represents a sound # After this we can assume that each character represents a sound
# (We'll revert back when we're done processing the RE) # (We'll revert back when we're done processing the RE)
replList = ((u'ei', u'1'), (u'', u'2'), (u'', u'3'), replList = [(u'ei', u'9'), (u'', u'='), (u'', u'~'),
(u'', u'4'), (u'', u'5'), (u'ɑɪ', u'6'), (u'', u'@'), (u'', u'%'), (u'ɑɪ', u'&'),
(u'ɔi', u'7')) (u'ɔi', u'$')]
# Add to the replList
currentReplNum = 0
startI = 0
for left, right in (('(', ')'), ('[', ']')):
while True:
try:
i = matchStr.index(left, startI)
except ValueError:
break
j = matchStr.index(right, i) + 1
replList.append((matchStr[i:j], str(currentReplNum)))
currentReplNum += 1
startI = j
for charA, charB in replList: for charA, charB in replList:
matchStr = matchStr.replace(charA, charB) matchStr = matchStr.replace(charA, charB)