final case class WordWrapper(wrapWidth: Int = 79, indentation: Int = 0, prefix: String = "", ignore: Set[Char] = Set.empty[Char], indentChar: Char = ' ') extends Product with Serializable
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:
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.
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.
- wrapWidth
the number of characters after which to wrap each line
- indentation
how many characters to indent
- prefix
the prefix to use, or "" for none. Cannot be null.
- ignore
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.
- indentChar
the indentation character to use.
- Alphabetic
- By Inheritance
- WordWrapper
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
WordWrapper(wrapWidth: Int = 79, indentation: Int = 0, prefix: String = "", ignore: Set[Char] = Set.empty[Char], indentChar: Char = ' ')
- wrapWidth
the number of characters after which to wrap each line
- indentation
how many characters to indent
- prefix
the prefix to use, or "" for none. Cannot be null.
- ignore
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.
- indentChar
the indentation character to use.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- val ignore: Set[Char]
- val indentChar: Char
- val indentation: Int
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val prefix: String
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
wrap(s: String): String
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.- s
the string to wrap
- returns
the wrapped string
- val wrapWidth: Int