grizzled.string

WordWrapper

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
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new WordWrapper(wrapWidth: Int = 79, indentation: Int = 0, prefix: String = "", ignore: Set[Char] = scala.this.Predef.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: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

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

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

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

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

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

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

    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.

  14. val indentChar: Char

    the indentation character to use.

  15. val indentation: Int

    how many characters to indent

  16. final def isInstanceOf[T0]: Boolean

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

    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  20. val prefix: String

    the prefix to use, or "" for none.

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

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

    Definition Classes
    AnyRef
  22. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. 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

  27. val wrapWidth: Int

    the number of characters after which to wrap each line

Inherited from AnyRef

Inherited from Any

Ungrouped