Qore TextWrap Module Reference
1.0
|
main namespace for all public symbols in the TextWrap module More...
Classes | |
class | TextWrapper |
Functions | |
string | dedent (string text) |
Remove any common leading whitespace from every line in 'text'. More... | |
string | fill (string text, int width=70, *hash opts) |
Fill a single paragraph of text, returning a new string. More... | |
string | indent (string text, string prefix, *code predicate) |
Adds 'prefix' to the beginning of selected lines in 'text'. More... | |
string | shorten (string text, int width, *hash opts) |
Collapse and truncate the given text to fit in the given width. More... | |
list | wrap (string text, int width=70, *hash opts) |
Wrap a single paragraph of text, returning a list of wrapped lines. More... | |
main namespace for all public symbols in the TextWrap module
Remove any common leading whitespace from every line in 'text'.
This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.
Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines " hello" and "\\thello" are considered to have no common leading whitespace.
Fill a single paragraph of text, returning a new string.
Reformat the single paragraph in 'text' to fit in lines of no more than 'width' columns, and return a new string containing the entire wrapped paragraph. As with wrap(), tabs are expanded and other whitespace characters converted to space. See TextWrapper class for available keyword args to customize wrapping behaviour.
Adds 'prefix' to the beginning of selected lines in 'text'.
If 'predicate' is provided, 'prefix' will only be added to the lines where 'predicate(line)' is True. If 'predicate' is not provided, it will default to adding 'prefix' to all non-empty lines that do not consist solely of whitespace characters.
Collapse and truncate the given text to fit in the given width.
The text first has its whitespace collapsed. If it then fits in the 'width', it is returned as is. Otherwise, as many words as possible are joined and then the placeholder is appended:
>>> TextWrap::shorten("Hello world!", 12) 'Hello world!' >>> TextWrap::shorten("Hello world!", 11) 'Hello [...]'
Wrap a single paragraph of text, returning a list of wrapped lines.
Reformat the single paragraph in 'text' so it fits in lines of no more than 'width' columns, and return a list of wrapped lines. By default, tabs in 'text' are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space. See TextWrapper class for available keyword args to customize wrapping behaviour.