Documentation
¶
Overview ¶
Package text provides methods for reading UTF-8 text handling
Index ¶
- type Wrapper
- func (wrapper *Wrapper) ChangeIndentStringForFirstRowTo(indent string) *Wrapper
- func (wrapper *Wrapper) ChangeIndentStringForRowsAfterTheFirstTo(indent string) *Wrapper
- func (wrapper *Wrapper) ChangeRowWidthTo(numberOfColumns uint) *Wrapper
- func (wrapper *Wrapper) MustWrapStringText(unwrappedString string) (wrappedText string)
- func (wrapper *Wrapper) MustWrapUTF8TextFromAReader(reader io.Reader) (wrappedText string)
- func (wrapper *Wrapper) UsingIndentStringForFirstRow(indent string) *Wrapper
- func (wrapper *Wrapper) UsingIndentStringForRowsAfterTheFirst(indent string) *Wrapper
- func (wrapper *Wrapper) UsingRowWidth(numberOfColumns uint) *Wrapper
- func (wrapper *Wrapper) WrapStringText(unwrappedString string) (wrappedText string, err error)
- func (wrapper *Wrapper) WrapUTF8TextFromAReader(reader io.Reader) (wrappedText string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Wrapper ¶
type Wrapper struct {
// contains filtered or unexported fields
}
Wrapper provides UTF-8 text line wrapping. At the start of each inserted line, any whitespace is removed. The Wrapper converts tab characters (code point 9) to a set (but configurable) number of spaces (code point 32). Line break sequences (code point 10 and and 13) are converted into a single space. If more than one line break occurs in a row, they are flattened to a single space. The Wrapper breaks the text stream into runs of unicode spaces and non-spaces. Runs of non-spaces are considered "words". At the start of a new wrapped line, any leading whitespace (after conversions noted above) are discarded. Alternating word and whitespace sequences are emitted until the (configurable) column width (minus the length of the line break sequence) is reached. If the column width would break a word the Wrapper rewinds to the last whitespace sequence, removes it, then inserts the (configurable) line break sequence. If there is no whitespace sequence before the start of the line (i.e., there are more contiguous word characters in the line than the column width minus the line break sequence length), the line break sequence is inserted at the column width minus the line break sequence length and the word continues on the next line. At the start of each indented line, a configurable preamble may be inserted. The characters in the preamble count against the row column count. A configurable preamble may also be be inserted on the initial line, but it is configured separately from the subsequent line indents in case the two should be different (a common case is to have no initial indent, but have a fixed number of spaces on subsequent lines).
func (*Wrapper) ChangeIndentStringForFirstRowTo ¶
ChangeIndentStringForFirstRowTo sets the indent string for the first row. By default, it is the empty string (meaning "no indent").
func (*Wrapper) ChangeIndentStringForRowsAfterTheFirstTo ¶
ChangeIndentStringForRowsAfterTheFirstTo sets the indent string for rows after the first. By default, it is the empty string (meaning "no indent").
func (*Wrapper) ChangeRowWidthTo ¶
ChangeRowWidthTo changes the column width to the provided value. The default column width is 79.
func (*Wrapper) MustWrapStringText ¶ added in v0.2.0
MustWrapStringText is the same as WrapStringText but panics if an error occurs
func (*Wrapper) MustWrapUTF8TextFromAReader ¶ added in v0.2.0
MustWrapUTF8TextFromAReader is the same as WrapUTF8TextFromAReader but panics if an error occurs
func (*Wrapper) UsingIndentStringForFirstRow ¶
UsingIndentStringForFirstRow is the same as ChangeIndentStringForFirstRowTo(), but provides a more readable name if this chained with the constructor.
func (*Wrapper) UsingIndentStringForRowsAfterTheFirst ¶
UsingIndentStringForRowsAfterTheFirst is the same as ChangeIndentStringForRowsAfterTheFirstTo(), but provides a more readable name if this chained with the constructor.
func (*Wrapper) UsingRowWidth ¶
UsingRowWidth is the same as ChangeRowWidthTo(), but provides a more readable name if this is chained with the constructor, as in:
wrapper := text.NewWrapper().UsingRowWidth(120)
func (*Wrapper) WrapStringText ¶
WrapStringText takes a string and wraps it using the rules described above. It returns the wrapped text or an error if one occurs.
func (*Wrapper) WrapUTF8TextFromAReader ¶
WrapUTF8TextFromAReader resets the Wrapper parser state. It begins to Read from the supplied reader, treating incoming bytes as UTF-8 encoded text, wrapping using the rules described above. It will Read() until it reaches io.EOF. It returns the wrapped text or an error if one occurs.