mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
17 lines
554 B
Python
17 lines
554 B
Python
![]() |
# -*- coding: utf-8 -*-
|
||
|
|
||
|
def shorten(text_ish, length):
|
||
|
""" If necessary, cuts-off the text or bytes input and appends ellipsis to
|
||
|
signal the cutoff, such that the result is below the provided length
|
||
|
(according to whatever "len" means on the text-ish so bytes or codepoints
|
||
|
or code units).
|
||
|
"""
|
||
|
if len(text_ish or ()) <= length:
|
||
|
return text_ish
|
||
|
|
||
|
cont = '...'
|
||
|
if isinstance(text_ish, bytes):
|
||
|
cont = cont.encode('ascii') # whatever
|
||
|
# add enough room for the ellipsis
|
||
|
return text_ish[:length-3] + cont
|