Import std.text.layout
std.text.layout
Wrapping, dedenting, and indenting a String's lines, and the edit distance between two.
WordWrap fills lines up to a width in a terminal's columns, Dedent takes away the indentation every line has, and Indent puts a prefix before each line. A line ends at "\n", "\r\n", or "\r", and each keeps its line break.
std/text/layout.fb
Functions
Levenshtein
function
Public Function Levenshtein(a: String, b: String): Int
How many single-character edits, inserting, deleting, or changing a character, turn a into
b, counting characters, code points.
Examples
Expect(Levenshtein("kitten", "sitting") == 3)
Expect(Levenshtein("same", "same") == 0)Extends
String
extend
Extend String
Wrapping, dedenting, and indenting a String's lines.
-
Its lines filled with words up to
widthcolumns each, as a terminal shows them, with DisplayWidth and a tab going on to the next multiple of 8 columns: each line breaks before the word that would go past it, at the spaces before that word, which go, while the spaces between words that stay on a line stay as they are. A no-break space, U+00A0, U+2007, or U+202F, is part of its word, not a place to break. A line's leading whitespace starts each line it becomes, and a word wider than the rest of thewidthis broken between its grapheme clusters. Panics whenwidthis below 1.Examples
Expect("the quick brown fox".WordWrap(10) == "the quick\nbrown fox") Expect("a\nb".Indent("> ") == "> a\n> b") -
A copy without the leading spaces and tabs that each line that isn't blank starts with, all alike, as when text is written indented in code. A blank line becomes empty.
-
A copy with
prefixbefore each line that isn't blank.
Report an issue with this page or with FutureBlitz on GitHub.