Truncate text to a maximum number of characters.
(s: str, maxlen: int = 128, suffix: str = '...')
| 87 | |
| 88 | |
| 89 | def truncate(s: str, maxlen: int = 128, suffix: str = '...') -> str: |
| 90 | """Truncate text to a maximum number of characters.""" |
| 91 | if maxlen and len(s) >= maxlen: |
| 92 | return s[:maxlen].rsplit(' ', 1)[0] + suffix |
| 93 | return s |
| 94 | |
| 95 | |
| 96 | def pluralize(n: float, text: str, suffix: str = 's') -> str: |
no outgoing calls