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.
set of characters to ignore when calculating wrapping.
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.
how many characters to indent
the prefix to use, or "" for none.
the prefix to use, or "" for none. Cannot be null.
Wrap a string, using the wrap width, prefix, indentation and indentation
character that were specified to the WordWrapper
constructor.
Wrap a string, using the wrap width, prefix, indentation and indentation
character that were specified to the WordWrapper
constructor.
The resulting string may have embedded newlines in it.
the string to wrap
the wrapped string
the number of characters after which to wrap each line
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.Examples:
might appear like this without a prefix:
and like this if the prefix is "myprog:"
Alternatively, if the output width is shortened, the same message can be made to wrap something like this:
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.Notes
- 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.