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 HasPrefixCaseless(corpus, prefix string) bool
- func HasSuffixCaseless(corpus, suffix string) bool
- 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) []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 Buffer
- type Runeset
- 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') )
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 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 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 ¶
SplitLines splits a corpus into individual lines by end of line character(s). Possible end of line characters include `\n`, `\r` and `\r\n`.
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": "bailey" } => "foo/bailey/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 Buffer ¶
Buffer is an extension of bytes.Buffer with some helpers.
Source Files ¶
- buffer.go
- compress_whitespace.go
- constants.go
- csv.go
- equals_caseless.go
- filesize.go
- fixed.go
- has_prefix_caseless.go
- has_suffix_caseless.go
- package.go
- random.go
- replace_any.go
- runset.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