|
1234567891011121314151617181920212223242526272829303132 |
- import unicodedata
-
-
- 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.decode ('utf-8')])
-
- @classmethod
- def index_by_f2c (cls, string: str, index: float) -> int:
- i = 0
- work = ''
- for c in string.decode ('utf-8'):
- 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 = string[cls.index_by_f2c (string, start):]
-
- return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
-
|