# loki.tools.strings

Functions

`truncate_string`(string[, length, continuation]) | Truncates a string to have a maximum given number of characters and indicates the truncation by continuation characters '...'.

Classes

`JoinableStringList`(items, sep, width, cont) | Helper class that takes a list of `items` and joins them into a long string, when converting the object to a string using custom separator `sep`.

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 separator `sep`. 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 strings as well as other instances of `JoinableStringList`.

  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).