12 lines
351 B
Python
12 lines
351 B
Python
|
import os
|
||
|
|
||
|
|
||
|
def ellipsize(string: str, max_length: int, ellipsis="…") -> str:
|
||
|
if len(string) <= max_length:
|
||
|
return string
|
||
|
if "." not in string:
|
||
|
return string[:-len(ellipsis)] + ellipsis
|
||
|
else:
|
||
|
name, ext = os.path.splitext(string)
|
||
|
name = name[:-len(ellipsis)] + ellipsis
|
||
|
return ".".join([name, ext])
|