伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
826 B

  1. import unicodedata
  2. class CommonModule:
  3. @staticmethod
  4. def is_wide (c: str) -> bool:
  5. return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
  6. @classmethod
  7. def len_by_full (cls, string: str) -> float:
  8. return sum (1 if cls.is_wide (c) else .5 for c in string)
  9. @classmethod
  10. def index_by_f2c (cls, string: str, index: float) -> int:
  11. i: int = 0
  12. work: str = ''
  13. for c in string:
  14. work += c
  15. if cls.len_by_full (work) > index:
  16. break
  17. else:
  18. i += 1
  19. return i
  20. @classmethod
  21. def mid_by_full (cls, string: str, start: float, length: float) -> str:
  22. trimmed_left: str = string[cls.index_by_f2c (string, start):]
  23. return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]