textlib: Routines for working with text

Routines for working with text

Functions

escapeAnsi(line)

Escape ansi codes

firstSentence(txt)

Returns the first sentence from txt

fuzzymatch(pattern, strings)

Find possible matches to pattern in strings.

getIndentation(code)

get the number of spaces used to indent code

joinPreservingIndentation(fragments)

Like join, but preserving indentation

linesStrip(lines)

Remove empty lines from the top and bottom

linesStripBottom(lines[, maxlines])

Strip empty lines from the end of the list

linesStripTop(lines)

Remove empty lines from the top

ljust(s, width[, fillchar])

Like str.ljust, but ensures that the output is always the given width

makeReplacer(conditions)

Create a function to replace many subtrings at once

matchIndentation(code, modelcode)

Indent code matching modelcode

quoteIfNeeded(s[, quote, defaultquote])

Add quotation marks around s if needed

reindent(text, prefix)

Reindent a given text.

splitInChunks(s, maxlen)

Split s into strings of max.

stripLines(text[, which, splitregex])

Strip leading and trailing empty lines

unicodeFraction(numerator, denominator[, ...])