Class/Object

grizzled.string

WordWrapper

Related Docs: object WordWrapper | package string

Permalink

class WordWrapper extends AnyRef

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. WordWrapper
  2. AnyRef
  3. 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 = ' ')

    Permalink

    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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. val ignore: Set[Char]

    Permalink

    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.

  12. val indentChar: Char

    Permalink

    the indentation character to use.

  13. val indentation: Int

    Permalink

    how many characters to indent

  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. val prefix: String

    Permalink

    the prefix to use, or "" for none.

    the prefix to use, or "" for none. Cannot be null.

  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. def wrap(s: String): String

    Permalink

    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

  25. val wrapWidth: Int

    Permalink

    the number of characters after which to wrap each line

Inherited from AnyRef

Inherited from Any

Ungrouped