edit_file_1.py 312 B

1234567891011121314
  1. def elide_text(string, max):
  2. if len(string) <= max - 1:
  3. return string
  4. p = re.compile(
  5. r'^((?:[\ud800-\udbff][\udc00-\udfff]|.){' + str(max - 1) + '}).',
  6. re.UNICODE
  7. )
  8. m = p.match(string)
  9. if not m:
  10. return string
  11. return re.sub(r'…*$', r'…', m.group(1))