Optimized counting words and characters via regex

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2021-06-01 15:17:54 +02:00
parent 7e05b72d83
commit a58de3b1f6
No known key found for this signature in database
GPG key ID: D850A5F772E880F9

View file

@ -24,17 +24,14 @@ MW = None
def wordCount(text):
t = text.strip().replace(" ", "\n").split("\n")
t = [l for l in t if l]
return len(t)
return len(re.findall(r"\S+", text))
def charCount(text, use_spaces = True):
t = text.strip()
if not use_spaces:
t = t.replace(" ", "")
return len(t)
if use_spaces:
return len(re.findall(r"[\S ]", text))
else:
return len(re.findall(r"\S", text))
validate_ok = lambda *args, **kwargs: True
def uiParse(input, default, converter, validator=validate_ok):