edit_file.py 389 B

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