Wraps strings on word boundaries to fit within a proscribed output width.
Wraps strings on word boundaries to fit within a proscribed output
width. The wrapped string may have a prefix or not; prefixes are useful
for error messages, for instance. You tell a WordWrapper
about
a prefix by passing a non-empty prefix to the constructor.
Unable to open file /usr/local/etc/wombat: No such file or directory
might appear like this without a prefix:
Unable to open file /usr/local/etc/wombat: No such file or directory
and like this if the prefix is "myprog:"
myprog: Unable to open file /usr/local/etc/wombat: No such file or directory
Alternatively, if the output width is shortened, the same message can be made to wrap something like this:
myprog: Unable to open file /usr/local/etc/wombat: No such file or directory
Note how the wrapping logic will "tab" past the prefix on wrapped lines.
This method also supports the notion of an indentation level, which is
independent of the prefix. A non-zero indentation level causes each line,
including the first line, to be indented that many characters. Thus,
initializing a WordWrapper
object with an indentation value of 4
will cause each output line to be preceded by 4 blanks. (It's also
possible to change the indentation character from a blank to any other
character.
- The class does not do any special processing of tab characters. Embedded tab characters can have surprising (and unwanted) effects on the rendered output. - Wrapping an already wrapped string is an invitation to trouble.
the number of characters after which to wrap each line
how many characters to indent
the prefix to use, or "" for none. Cannot be null.
set of characters to ignore when calculating wrapping. This feature can be useful when certain characters represent escape characters, and you intend to post-process the wrapped string.
the indentation character to use.
String and character implicits.
Scala classes that provide for variable substitution within strings,
akin to the Python StringTemplate
library.
Scala classes that provide for variable substitution within strings,
akin to the Python StringTemplate
library. Several syntaxes are
supported.
Useful string-related utility functions.
String- and text-related classes.