text

package
v1.42.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const (
	IndentOptionNone            = 0
	IndentOptionIndentFirstLine = 1 << 0
)

Variables

View Source
var ErrEmptyInput = fmt.Errorf("Empty input")

Errors

Functions

func Coalesce

func Coalesce(v ...string) string

Return the first non-empty string from those provided

func CollapseSpaces

func CollapseSpaces(s string) string

*

  • Collapse whitespace

func Hexdump

func Hexdump(w io.Writer, b []byte, cols int)

Write a string in the manner of the output of `hexdump -C`, with byte values on the left corresponding to characters on the right, when printable

func IdentizeString

func IdentizeString(s string) string

Identize terms

func Indent

func Indent(s, p string) string

Indent a string by prefixing each line with the provided string

func IndentWithOptions

func IndentWithOptions(s, p string, opt IndentOptions) string

Indent a string by prefixing each line with the provided string

func NewIndentWriter

func NewIndentWriter(p string, opt IndentOptions, w io.Writer) io.Writer

Create an indent writer

func NormalizeDiacritics

func NormalizeDiacritics(s string) string

Convert characters with diacritical marks to their unaccented/base counterparts. See also: http://stackoverflow.com/questions/26722450/remove-diacritics-using-go

func NormalizeJoin

func NormalizeJoin(l []string, d, f string) string

Normalize a list, using a special final delimiter between the last two elements.

func NormalizeString

func NormalizeString(s string) string

Normalize a string for general purpose matching

func NormalizeTerms

func NormalizeTerms(s string) string

Normalize query terms

func ParseRanges

func ParseRanges(s string, b []int) ([][]int, error)

Parse a series of ranges from text. Multiple ranges can be represented in a comma-delimited list. Individual numbers in the list are treated as a range that includes only that number.

An empty bound in a range is interpreted as "all the numbers from the constraining bound to the other bound". For example, the range "-10", with constraining bounds of [0, 100] means the range "0-10".

Contiguous ranges are merged together.

For example, the input: 0-5,5,6,7,8-10 produces: [[0,10]]

And the input: 0-5,7,9-10 produces: [[0,5],[7,7],[9,10]]

func ParseRangesFunc

func ParseRangesFunc(s string, b []int, d string, c NumberParser) ([][]int, error)

Parse ranges where the values are parsed by a function

func Stringer

func Stringer(v interface{}) string

Convert a value to a reasonable string representation

func StripControl

func StripControl(s string) string

Strip out control characters in place

func Truncate

func Truncate(s string, n int, x string) string

Truncate a string to n characters (not bytes). If the string is truncated, the provided suffix is appended. Something like ' [...]' would be appropriate as a suffix to indicate that text was removed.

Types

type IndentOptions

type IndentOptions uint32

Indentiation options

type NumberParser

type NumberParser func(string) (int, error)

Number parser function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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