|
- import unicodedata
-
- from common_const import *
-
-
- class CommonModule:
- @staticmethod
- def is_wide (
- c: str) \
- -> bool:
- return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
-
- @classmethod
- def len_by_full (
- cls,
- string: str) \
- -> float:
- return sum (1 if cls.is_wide (c) else .5 for c in string)
-
- @classmethod
- def index_by_f2c (
- cls,
- string: str,
- index: float) \
- -> int:
- i: int = 0
- work: str = ''
- for c in string:
- work += c
- if cls.len_by_full (work) > index:
- break
- else:
- i += 1
-
- return i
-
- @classmethod
- def mid_by_full (
- cls,
- string: str,
- start: float,
- length: float) \
- -> str:
- trimmed_left: str = string[cls.index_by_f2c (string, start):]
-
- return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|