txt

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: MPL-2.0 Imports: 10 Imported by: 34

Documentation

Overview

Package txt provides various text utilities.

Index

Constants

This section is empty.

Variables

View Source
var StdAllCaps = MustNewAllCaps("acl", "api", "ascii", "cpu", "css", "dns",
	"eof", "guid", "html", "http", "https", "id", "ip", "json", "lhs", "qps",
	"ram", "rhs", "rpc", "sla", "smtp", "sql", "ssh", "tcp", "tls", "ttl",
	"udp", "ui", "uid", "uuid", "uri", "url", "utf8", "vm", "xml", "xmpp",
	"xsrf", "xss")

StdAllCaps provides the standard list of words that golint expects to be capitalized, found in the variable 'commonInitialisms' in https://github.com/golang/lint/blob/master/lint.go

Functions

func CollapseSpaces

func CollapseSpaces(in string) string

CollapseSpaces removes leading and trailing spaces and reduces any runs of two or more spaces to a single space.

func DigitToValue

func DigitToValue(ch rune) (int, error)

DigitToValue converts a unicode digit into a numeric value.

func DurationToCode

func DurationToCode(duration time.Duration) string

DurationToCode turns a time.Duration into more human-readable text required for code than a simple number of nanoseconds.

func FirstN

func FirstN(s string, n int) string

FirstN returns the first n runes of a string.

func FirstToLower added in v1.2.1

func FirstToLower(in string) string

FirstToLower converts the first character to lower case.

func FirstToUpper

func FirstToUpper(in string) string

FirstToUpper converts the first character to upper case.

func FormatDuration

func FormatDuration(duration time.Duration, includeMillis bool) string

FormatDuration formats the duration as either "0:00:00" or "0:00:00.000".

func LastN

func LastN(s string, n int) string

LastN returns the last n runes of a string.

func NaturalLess

func NaturalLess(s1, s2 string, caseInsensitive bool) bool

NaturalLess compares two strings using natural ordering. This means that "a2" < "a12".

Non-digit sequences and numbers are compared separately. The former are compared bytewise, while the latter are compared numerically (except that the number of leading zeros is used as a tie-breaker, so "2" < "02").

Limitations:

  • only ASCII digits (0-9) are considered.

Original algorithm:

https://github.com/fvbommel/util/blob/master/sortorder/natsort.go

func ParseDuration

func ParseDuration(duration string) (time.Duration, error)

ParseDuration parses the duration string, as produced by FormatDuration().

func ToCamelCase

func ToCamelCase(in string) string

ToCamelCase converts a string to CamelCase.

func ToCamelCaseWithExceptions added in v1.1.5

func ToCamelCaseWithExceptions(in string, exceptions *AllCaps) string

ToCamelCaseWithExceptions converts a string to CamelCase, but forces certain words to all caps.

func ToSnakeCase

func ToSnakeCase(in string) string

ToSnakeCase converts a string to snake_case.

func Wrap added in v1.3.0

func Wrap(prefix, text string, maxColumns int) string

Wrap text to a certain length, giving it an optional prefix on each line. Words will not be broken, even if they exceed the maximum column size and instead will extend past the desired length.

Types

type AllCaps added in v1.1.5

type AllCaps struct {
	// contains filtered or unexported fields
}

AllCaps holds information for transforming text with ToCamelCaseWithExceptions.

func MustNewAllCaps added in v1.1.5

func MustNewAllCaps(in ...string) *AllCaps

MustNewAllCaps takes a list of words that should be all uppercase when part of a camel-cased string. Failure to create the AllCaps object causes the program to exit.

func NewAllCaps added in v1.1.5

func NewAllCaps(in ...string) (*AllCaps, error)

NewAllCaps takes a list of words that should be all uppercase when part of a camel-cased string.

type RuneReader added in v1.1.5

type RuneReader struct {
	Src []rune
	Pos int
}

RuneReader implements io.RuneReader

func (*RuneReader) ReadRune added in v1.1.5

func (rr *RuneReader) ReadRune() (r rune, size int, err error)

ReadRune returns the next rune and its size in bytes.

Jump to

Keyboard shortcuts

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