manuskript/manuskript/util/counter.py
TheJackiMonster 3481e40b4f
Implement basic outline overview
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
2022-10-30 17:48:02 +01:00

39 lines
659 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
from enum import Enum, unique
@unique
class CounterKind(Enum):
WORDS = 0
CHARACTERS = 1
PAGES = 2
class CharCounter:
@classmethod
def count(cls, text: str, use_spaces: bool = False):
if use_spaces:
return len(re.findall(r"[\S ]", text))
else:
return len(re.findall(r"\S", text))
class WordCounter:
@classmethod
def count(cls, text: str):
return len(re.findall(r"\S+", text))
class PageCounter:
@classmethod
def count(cls, text: str):
wc = WordCounter.count(text)
return int(wc / 25) / 10.