Documentation ¶
Overview ¶
Package stringutil includes string utility functions and helpers.
Index ¶
- Constants
- Variables
- func CSV(values []string) string
- func CombineRunsets(runesets ...[]rune) []rune
- func CompressSpace(text string) (output string)
- func EqualsCaseless(a, b string) bool
- func FileSize(sizeBytes int) string
- func Fixed(text string, width int) string
- func FixedLeft(text string, width int) string
- func Glob(subj, pattern string) bool
- func GlobAny(subj string, patterns ...string) bool
- func HasPrefixCaseless(corpus, prefix string) bool
- func HasSuffixCaseless(corpus, suffix string) bool
- func Indent(indent string, corpus string) string
- func IndentLines(indent string, corpus []string) []string
- func MustParseBool(str string) bool
- func ParseBool(str string) (bool, error)
- func Random(runeset []rune, length int) string
- func ReplaceAny(corpus string, replacement rune, replaced ...rune) string
- func Slugify(v string) string
- func SplitCSV(text string) (output []string)
- func SplitLines(contents string, opts ...SplitLinesOption) []string
- func SplitSpace(text string) (output []string)
- func SplitSpaceQuoted(text string) (output []string)
- func TSV(values []string) string
- func Title(corpus string) string
- func Tokenize(corpus string, tokens Tokens) string
- func TrimLen(val string, length int) string
- func TrimPrefixCaseless(corpus, prefix string) string
- func TrimSuffixCaseless(corpus, suffix string) string
- type Runeset
- type SplitLinesOption
- type SplitLinesOptions
- type Tokens
Constants ¶
const ( // Empty is the empty string Empty string = "" // RuneSpace is a single rune representing a space. RuneSpace rune = ' ' // RuneNewline is a single rune representing a newline. RuneNewline rune = '\n' // LowerA is the ascii int value for 'a' LowerA uint = uint('a') // LowerZ is the ascii int value for 'z' LowerZ uint = uint('z') )
const (
ErrInvalidBoolValue ex.Class = "invalid bool value"
)
Error Constants
const (
GlobStar = "*"
)
Glob constants
Variables ¶
var ( // LowerLetters is a runset of lowercase letters. LowerLetters Runeset = []rune("abcdefghijklmnopqrstuvwxyz") // UpperLetters is a runset of uppercase letters. UpperLetters Runeset = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") // Letters is a runset of both lower and uppercase letters. Letters = append(LowerLetters, UpperLetters...) // Numbers is a runset of numeric characters. Numbers Runeset = []rune("0123456789") // LettersAndNumbers is a runset of letters and numeric characters. LettersAndNumbers = append(Letters, Numbers...) // Symbols is a runset of symbol characters. Symbols Runeset = []rune(`!@#$%^&*()_+-=[]{}\|:;`) // LettersNumbersAndSymbols is a runset of letters, numbers and symbols. LettersNumbersAndSymbols = append(LettersAndNumbers, Symbols...) )
var ( // LowerDiff is the difference between lower Z and lower A LowerDiff = (LowerZ - LowerA) )
Functions ¶
func CombineRunsets ¶
CombineRunsets combines given runsets into a single runset.
func CompressSpace ¶
CompressSpace compresses whitespace characters into single spaces. It trims leading and trailing whitespace as well.
func EqualsCaseless ¶
EqualsCaseless compares two strings regardless of case.
func Fixed ¶
Fixed returns a fixed width, right aligned, string with a given minimum space padded width.
func FixedLeft ¶
FixedLeft returns a fixed width, left aligned, string with a given minimum space padded width.
func GlobAny ¶ added in v1.20210116.3
GlobAny tests if a file matches a (potentially) csv of glob filters.
func HasPrefixCaseless ¶
HasPrefixCaseless returns if a corpus has a prefix regardless of casing.
func HasSuffixCaseless ¶
HasSuffixCaseless returns if a corpus has a suffix regardless of casing.
func IndentLines ¶
IndentLines adds a prefix to a given list of strings.
func MustParseBool ¶
MustParseBool parses a boolean value and panics if there is an error.
func ReplaceAny ¶
ReplaceAny replaces any runes in the 'replaced' list with a given replacement. Example:
output := ReplaceAny("foo bar_baz", '-', []rune(` _`)...)
func SplitCSV ¶
SplitCSV splits a corpus by the `,`, dropping leading or trailing whitespace unless quoted.
func SplitLines ¶
func SplitLines(contents string, opts ...SplitLinesOption) []string
SplitLines splits a corpus into individual lines by the ascii control character `\n`. You can control some behaviors of the splitting process with variadic options.
func SplitSpace ¶
SplitSpace splits a string on whitespace.
func SplitSpaceQuoted ¶
SplitSpaceQuoted splits a corpus on space but treats quoted strings i.e. within `"` as being atomic chunks.
func Tokenize ¶
Tokenize replaces a given set of tokens in a corpus. Tokens should appear in the corpus in the form ${[KEY]} where [KEY] is the key in the map. Examples: corpus: "foo/${bar}/baz", { "bar": "example-string" } => "foo/example-string/baz" UTF-8 is handled via. runes.
func TrimPrefixCaseless ¶
TrimPrefixCaseless trims a prefix from a corpus ignoring case.
func TrimSuffixCaseless ¶
TrimSuffixCaseless trims a case insensitive suffix from a corpus.
Types ¶
type Runeset ¶
type Runeset []rune
Runeset is a set of runes
type SplitLinesOption ¶
type SplitLinesOption func(*SplitLinesOptions)
SplitLinesOption is a mutator for SplitLinesOptions.
func OptSplitLinesIncludeEmptyLines ¶
func OptSplitLinesIncludeEmptyLines(include bool) SplitLinesOption
OptSplitLinesIncludeEmptyLines sets if we should omit newlines in the returned lines.
func OptSplitLinesIncludeNewLine ¶
func OptSplitLinesIncludeNewLine(include bool) SplitLinesOption
OptSplitLinesIncludeNewLine sets if we should omit newlines in the returned lines.
type SplitLinesOptions ¶
SplitLinesOptions are options for the SplitLines function.
Source Files ¶
- compress_whitespace.go
- constants.go
- csv.go
- doc.go
- equals_caseless.go
- filesize.go
- fixed.go
- glob.go
- has_prefix_caseless.go
- has_suffix_caseless.go
- indent.go
- parse_bool.go
- random.go
- replace_any.go
- runeset.go
- slugify.go
- split_csv.go
- split_lines.go
- split_space.go
- split_space_quoted.go
- title.go
- tokenize.go
- trim_prefix_caseless.go
- trim_suffix_caseless.go
- trimlen.go
- tsv.go