mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-09-29 08:51:14 +13:00
Optimized counting words and characters via regex
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
7e05b72d83
commit
a58de3b1f6
1 changed files with 6 additions and 9 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue