textutil

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 3 Imported by: 0

README

GoDoc

textutil

Text utils.

Wordwrap

Copied from https://github.com/mitchellh/go-wordwrap and improved.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CRLF = []byte{'\r', '\n'}
	LF   = []byte{'\n'}
)

Functions

func WrapString

func WrapString(s string, opts *WrapOptions) string

WrapString wraps the given string within lim width in characters.

Wrapping is currently naive and only happens at white-space. A future version of the library will implement smarter wrapping. This means that pathological cases can dramatically reach past the limit, such as a very long word. pfx can be set to define a prefix for each new line.

Types

type WrapOptions

type WrapOptions struct {
	// Linebreak defines the line break used between lines in wordwrap, and
	// defaults to \n if not set.
	Linebreak []byte

	// Maximum characters in a line, will default to 76 if set to zero.
	Limit int

	// Prefix is a prefix set on each line if
	Prefix string

	// Will break words if set to true
	BreakWords bool
}

func DefaultWrapOptions

func DefaultWrapOptions() *WrapOptions

DefaultWrapOptions returns a WrapOptions object with the default values set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL