ParagraphFormatter

class ParagraphFormatter(windowWidth: Int = 80, leftMargin: Int = 0, rightMargin: Int = 0, firstIndent: Int = 0, restIndent: Int = 0)

A ParagraphFormatter object holds a particular paragraph style in the form of window width, margin, and indentation settings. It is then used to apply those whitespace and word-wrap settings to a String.

This is intended to be the final format procedure applied to a String before it is output, and all adjacent, non-newline character whitespace is condensed to a single space.

Author

Leslie Schultz

Parameters

windowWidth

The number of characters that can fit horizontally in the window.

leftMargin

The number of spaces that all text should be, minimum, from the left side of the screen.

rightMargin

The number of spaces that all text should be, minimum, from the right side of the screen.

Constructors

Link copied to clipboard
constructor(windowWidth: Int = 80, leftMargin: Int = 0, rightMargin: Int = 0, firstIndent: Int = 0, restIndent: Int = 0)

Construct a new ParagraphFormatter that formats strings to wrap within the supplied window width, if possible. All text is padded within the specified margins.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun format(str: String): String

Answer the supplied string reformatted with margins, indentation, and words wrapped within those constraints, if possible. Non-newline whitespace is collapsed into a single space.