If a string is long enough, and has at least 3 dots, replace the middle part with ellipses. If a string naming a file is long enough, and has at least 3 slashes, replace the middle part with ellipses. If three consecutive dots, or two consecutive dots are encountered these are
(string:str, *, min_elide=30)
| 24 | _completion_sentinel = object() |
| 25 | |
| 26 | def _elide_point(string:str, *, min_elide=30)->str: |
| 27 | """ |
| 28 | If a string is long enough, and has at least 3 dots, |
| 29 | replace the middle part with ellipses. |
| 30 | |
| 31 | If a string naming a file is long enough, and has at least 3 slashes, |
| 32 | replace the middle part with ellipses. |
| 33 | |
| 34 | If three consecutive dots, or two consecutive dots are encountered these are |
| 35 | replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode |
| 36 | equivalents |
| 37 | """ |
| 38 | string = string.replace('...','\N{HORIZONTAL ELLIPSIS}') |
| 39 | string = string.replace('..','\N{TWO DOT LEADER}') |
| 40 | if len(string) < min_elide: |
| 41 | return string |
| 42 | |
| 43 | object_parts = string.split('.') |
| 44 | file_parts = string.split(os.sep) |
| 45 | if file_parts[-1] == '': |
| 46 | file_parts.pop() |
| 47 | |
| 48 | if len(object_parts) > 3: |
| 49 | return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(object_parts[0], object_parts[1][0], object_parts[-2][-1], object_parts[-1]) |
| 50 | |
| 51 | elif len(file_parts) > 3: |
| 52 | return ('{}' + os.sep + '{}\N{HORIZONTAL ELLIPSIS}{}' + os.sep + '{}').format(file_parts[0], file_parts[1][0], file_parts[-2][-1], file_parts[-1]) |
| 53 | |
| 54 | return string |
| 55 | |
| 56 | def _elide_typed(string:str, typed:str, *, min_elide:int=30)->str: |
| 57 | """ |