Packages

  • package root
    Definition Classes
    root
  • package grizzled

    The Grizzled Scala Library contains a variety of miscellaneous, general purpose utility classes and objects.

    The Grizzled Scala Library contains a variety of miscellaneous, general purpose utility classes and objects.

    The home page for the Grizzled Scala Library is http://software.clapper.org/grizzled-scala/. Please see that page for complete details, including installation instructions.

    Definition Classes
    root
  • package string

    String- and text-related classes.

    String- and text-related classes.

    Definition Classes
    grizzled
  • package template

    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.

    Definition Classes
    string
  • Implicits
  • WordWrapper
  • util
c

grizzled.string

WordWrapper

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.

Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. WordWrapper
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  8. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  9. val ignore: Set[Char]
  10. val indentChar: Char
  11. val indentation: Int
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. val prefix: String
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  21. 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

  22. val wrapWidth: Int

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped