loki.tools.strings
Functions
|
Truncates a string to have a maximum given number of characters and indicates the truncation by continuation characters '...'. |
Classes
|
Helper class that takes a list of items and joins them into a long string, when converting the object to a string using custom separators. |
- truncate_string(string, length=16, continuation='...')
Truncates a string to have a maximum given number of characters and indicates the truncation by continuation characters ‘…’. This is used, for example, in the representation strings of IR nodes.
- class JoinableStringList(items, sep, width, cont, separable=True)
Bases:
object
Helper class that takes a list of items and joins them into a long string, when converting the object to a string using custom separators. Long lines are wrapped automatically.
The behaviour is essentially the same as sep.join(items) but with the automatic wrapping of long lines. items can contain st
- Parameters:
items (list or tuple) – the list (or tuple) of items (that can be instances of str or JoinableStringList) that is to be joined.
sep (str) – the separator to be inserted between consecutive items.
width (int) – the line width after which long lines should be wrapped.
cont ((str, str) or str) – the line continuation string to be inserted on a line break.
separable (bool) – an indicator whether this can be split up to fill lines or should stay as a unit (this is for cosmetic purposes only, as too long lines will be wrapped in any case).