Documentation ¶
Overview ¶
Package txt provides various text utilities.
Index ¶
- Variables
- func CaselessSliceContains(slice []string, target string) bool
- func CloneStringSlice(in []string) []string
- func CollapseSpaces(in string) string
- func Comma[T constraints.Integer | constraints.Float](value T) string
- func CommaFromStringNum(s string) string
- func DigitToValue(ch rune) (int, error)
- func DurationToCode(duration time.Duration) string
- func FirstN(s string, n int) string
- func FirstToLower(in string) string
- func FirstToUpper(in string) string
- func FormatDuration(duration time.Duration, includeMillis bool) string
- func IsTruthy(in string) bool
- func IsVowel(ch rune) bool
- func IsVowely(ch rune) bool
- func LastN(s string, n int) string
- func MapToStringSlice(m map[string]bool) []string
- func NaturalCmp(s1, s2 string, caseInsensitive bool) int
- func NaturalLess(s1, s2 string, caseInsensitive bool) bool
- func NormalizeLineEndings(input string) string
- func ParseDuration(duration string) (time.Duration, error)
- func RomanNumerals(value int) string
- func RunesEqual(left, right []rune) bool
- func SortStringsNaturalAscending(in []string)
- func SortStringsNaturalDescending(in []string)
- func StringSliceToMap(slice []string) map[string]bool
- func StripBOM(b []byte) []byte
- func ToCamelCase(in string) string
- func ToCamelCaseWithExceptions(in string, exceptions *AllCaps) string
- func ToSnakeCase(in string) string
- func Truncate(s string, count int, keepFirst bool) string
- func Unquote(text string) string
- func UnquoteBytes(text []byte) []byte
- func Wrap(prefix, text string, maxColumns int) string
- type AllCaps
- type RuneReader
- type VowelChecker
Constants ¶
This section is empty.
Variables ¶
var SelectEmojiRegex = regexp.MustCompile(`[\x{200D}\x{203C}\x{2049}\x{20E3}\x{2122}\x{2139}\x{2194}-\x{2199}` +
`\x{21A9}-\x{21AA}\x{231A}-\x{231B}\x{2328}\x{2388}\x{23CF}\x{23E9}-\x{23F3}\x{23F8}-\x{23FA}\x{24C2}` +
`\x{25AA}-\x{25AB}\x{25B6}\x{25C0}\x{25FB}-\x{25FE}\x{2600}-\x{2605}\x{2607}-\x{2612}\x{2614}-\x{2705}` +
`\x{2708}-\x{2712}\x{2714}\x{2716}\x{271D}\x{2721}\x{2728}\x{2733}-\x{2734}\x{2744}\x{2747}\x{274C}\x{274E}` +
`\x{2753}-\x{2755}\x{2757}\x{2763}-\x{2767}\x{2795}-\x{2797}\x{27A1}\x{27B0}\x{27BF}\x{2934}-\x{2935}` +
`\x{2B05}-\x{2B07}\x{2B1B}-\x{2B1C}\x{2B50}\x{2B55}\x{3030}\x{303D}\x{3297}\x{3299}\x{FE00}-\x{FE0F}` +
`\x{1F000}-\x{1F0FF}\x{1F10D}-\x{1F10F}\x{1F12F}\x{1F16C}-\x{1F171}\x{1F17E}-\x{1F17F}\x{1F18E}` +
`\x{1F191}-\x{1F19A}\x{1F1AD}-\x{1F1FF}\x{1F201}-\x{1F20F}\x{1F21A}\x{1F22F}\x{1F232}-\x{1F23A}` +
`\x{1F23C}-\x{1F23F}\x{1F249}-\x{1F62B}\x{1F62C}-\x{1F64F}\x{1F680}-\x{1F6FF}\x{1F774}-\x{1F77F}` +
`\x{1F7D5}-\x{1F7FF}\x{1F80C}-\x{1F80F}\x{1F848}-\x{1F84F}\x{1F85A}-\x{1F85F}\x{1F888}-\x{1F88F}` +
`\x{1F8AE}-\x{1F93A}\x{1F93C}-\x{1F945}\x{1F947}-\x{1F9FF}\x{E0020}-\x{E007F}]`)
SelectEmojiRegex identifies emoji runs.
var StdAllCaps = MustNewAllCaps(strings.Split(NormalizeLineEndings(stdAllCaps), "\n")...)
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#L771-L808
Functions ¶
func CaselessSliceContains ¶
CaselessSliceContains returns true if the target is within the slice, regardless of case.
func CloneStringSlice ¶
CloneStringSlice returns a copy of the slice of strings.
func CollapseSpaces ¶
CollapseSpaces removes leading and trailing spaces and reduces any runs of two or more spaces to a single space.
func Comma ¶
func Comma[T constraints.Integer | constraints.Float](value T) string
Comma returns text version of the value that uses commas for every 3 orders of magnitude.
func CommaFromStringNum ¶
CommaFromStringNum returns a revised version of the numeric input string that uses commas for every 3 orders of magnitude.
func DigitToValue ¶
DigitToValue converts a unicode digit into a numeric value.
func DurationToCode ¶
DurationToCode turns a time.Duration into more human-readable text required for code than a simple number of nanoseconds.
func FirstToLower ¶
FirstToLower converts the first character to lower case.
func FirstToUpper ¶
FirstToUpper converts the first character to upper case.
func FormatDuration ¶
FormatDuration formats the duration as either "0:00:00" or "0:00:00.000".
func IsTruthy ¶
IsTruthy returns true for "truthy" values, i.e. ones that should be interpreted as true.
func MapToStringSlice ¶
MapToStringSlice returns a slice created from the keys of a map.
func NaturalCmp ¶
NaturalCmp compares two strings using natural ordering. This means that "a2" < "a12".
Non-digit sequences and numbers are compared separately. The former are compared byte-wise, 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 NaturalLess ¶
NaturalLess compares two strings using natural ordering. This means that "a2" < "a12".
Non-digit sequences and numbers are compared separately. The former are compared byte-wise, 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 NormalizeLineEndings ¶
NormalizeLineEndings converts CRLF and CR into LF.
func ParseDuration ¶
ParseDuration parses the duration string, as produced by FormatDuration().
func RomanNumerals ¶
RomanNumerals converts a number into roman numerals.
func RunesEqual ¶
RunesEqual returns true if the two slices of runes are equal.
func SortStringsNaturalAscending ¶
func SortStringsNaturalAscending(in []string)
SortStringsNaturalAscending sorts a slice of strings using NaturalLess in least to most order.
func SortStringsNaturalDescending ¶
func SortStringsNaturalDescending(in []string)
SortStringsNaturalDescending sorts a slice of strings using NaturalLess in most to least order.
func StringSliceToMap ¶
StringSliceToMap returns a map created from the strings of a slice.
func ToCamelCaseWithExceptions ¶
ToCamelCaseWithExceptions converts a string to CamelCase, but forces certain words to all caps.
func Truncate ¶
Truncate the input string to count runes, trimming from the end if keepFirst is true or the start if not. If trimming occurs, a … will be added in place of the trimmed characters.
func Unquote ¶
Unquote strips up to one set of surrounding double quotes from the bytes and returns them as a string. For a more capable version that supports different quoting types and unescaping, consider using strconv.Unquote().
func UnquoteBytes ¶
UnquoteBytes strips up to one set of surrounding double quotes from the bytes and returns them as a string. For a more capable version that supports different quoting types and unescaping, consider using strconv.Unquote().
Types ¶
type AllCaps ¶
type AllCaps struct {
// contains filtered or unexported fields
}
AllCaps holds information for transforming text with ToCamelCaseWithExceptions.
func MustNewAllCaps ¶
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 ¶
NewAllCaps takes a list of words that should be all uppercase when part of a camel-cased string.
type RuneReader ¶
RuneReader implements io.RuneReader
type VowelChecker ¶
VowelChecker defines a function that returns true if the specified rune is to be considered a vowel.