Skip to content

Commit

Permalink
Second attempt for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ABuffEr committed Feb 11, 2023
1 parent 9b46e84 commit 2e4d8d6
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions addon/globalPlugins/numberProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
lastProfile = None

def compileExps():
basePattern = r'\d{%s,}'%userMinLen
exp1 = re.compile(basePattern)
exp1 = re.compile(r'\d{%s,}'%userMinLen)
symbols = ''.join(CURRENCY_SYMBOLS)
exp2 = re.compile(r'([%s]\s*)(%s)'%(symbols, basePattern))
exp2 = re.compile(r'([%s])?\s*([\d,.]+)'%symbols)
return (exp1, exp2,)

# (re)load config
Expand All @@ -71,25 +70,20 @@ def loadConfig():

loadConfig()

def replaceFunc1(match):
def replaceFunc(match):
# group(0) returns digits captured by match
fixedText = ' '.join(list(match.group(0)))
return fixedText

def replaceFunc2(match):
fixedText = ' '.join([*list(match.group(2)), match.group(1)])
return fixedText

def newProcessText(text):
# pre-process to avoid problems with decimal separator,
# appending currency sign to the end of the amount
text = exp2.sub(r'\2\1', text)
# get spoken version
text = backupProcessText(text)
currencyMatch = exp2.match(text)
if currencyMatch:
endPos = currencyMatch.span(currencyMatch.lastindex)[1]
part1 = exp2.sub(replaceFunc2, text[0:endPos])
part2 = exp1.sub(replaceFunc1, text[endPos:])
newText = ''.join([part1, part2])
else:
newText = exp1.sub(replaceFunc1, text)
return newText
# add whitespace around digits
text = exp1.sub(replaceFunc, text)
return text

def enableProcessing():
global prevEnabled, myConf, globalEnabled
Expand Down

0 comments on commit 2e4d8d6

Please sign in to comment.