ParagraphFormatter

class ParagraphFormatter @JvmOverloads constructor(    val windowWidth: Int = 80,     val leftMargin: Int = 0,     val rightMargin: Int = 0,     val firstIndent: Int = 0,     val 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
fun ParagraphFormatter(    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.

Properties

Link copied to clipboard
val firstIndent: Int = 0

The number of spaces between the left margin and the initial line in a paragraph.

Link copied to clipboard
val leftMargin: Int = 0

The number of spaces in the left margin.

Link copied to clipboard
val restIndent: Int = 0

The number of spaces between the left margin and non-initial lines in a paragraph.

Link copied to clipboard
val rightMargin: Int = 0

The number of spaces in the right margin

Link copied to clipboard
val windowWidth: Int = 80

The width of the output window.