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 |
- 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:
objectHelper class that takes a list of
itemsand joins them into a long string, when converting the object to a string using custom separatorsep. Long lines are wrapped automatically.The behaviour is essentially the same as
sep.join(items)but with the automatic wrapping of long lines.itemscan contain strings as well as other instances ofJoinableStringList.- Parameters:
items (list of str or
JoinableStringList) – The list (or tuple) of items that should be joined into a string.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, optionally separated as end-of-line and beginning-of-next-line strings
separable (bool) – An indicator whether this object 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).