mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-17 02:14:33 +12:00
Optimized counting words and characters via regex
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
7e05b72d83
commit
a58de3b1f6
|
@ -24,17 +24,14 @@ MW = None
|
||||||
|
|
||||||
|
|
||||||
def wordCount(text):
|
def wordCount(text):
|
||||||
t = text.strip().replace(" ", "\n").split("\n")
|
return len(re.findall(r"\S+", text))
|
||||||
t = [l for l in t if l]
|
|
||||||
return len(t)
|
|
||||||
|
|
||||||
def charCount(text, use_spaces = True):
|
def charCount(text, use_spaces = True):
|
||||||
t = text.strip()
|
if use_spaces:
|
||||||
|
return len(re.findall(r"[\S ]", text))
|
||||||
if not use_spaces:
|
else:
|
||||||
t = t.replace(" ", "")
|
return len(re.findall(r"\S", text))
|
||||||
|
|
||||||
return len(t)
|
|
||||||
|
|
||||||
validate_ok = lambda *args, **kwargs: True
|
validate_ok = lambda *args, **kwargs: True
|
||||||
def uiParse(input, default, converter, validator=validate_ok):
|
def uiParse(input, default, converter, validator=validate_ok):
|
||||||
|
|
Loading…
Reference in a new issue