Documentation ¶
Overview ¶
Package stringutil implements string utilities.
Index ¶
- func IsAlpha(r rune) bool
- func IsAlphanumeric(r rune) bool
- func IsLowerAlpha(r rune) bool
- func IsLowerAlphanumeric(r rune) bool
- func IsNumeric(r rune) bool
- func IsUpperAlpha(r rune) bool
- func JoinSliceQuoted(s []string, sep string) string
- func MapToSlice(m map[string]struct{}) []string
- func MapToSortedSlice(m map[string]struct{}) []string
- func SliceElementsContained(superset []string, subset []string) bool
- func SliceElementsEqual(one []string, two []string) bool
- func SliceToChunks(s []string, chunkSize int) [][]string
- func SliceToHumanString(s []string) string
- func SliceToHumanStringQuoted(s []string) string
- func SliceToMap(s []string) map[string]struct{}
- func SliceToString(s []string) string
- func SliceToUniqueSortedSlice(s []string) []string
- func SliceToUniqueSortedSliceFilterEmptyStrings(s []string) []string
- func SplitTrimLines(output string) []string
- func SplitTrimLinesNoEmpty(output string) []string
- func ToLowerSnakeCase(s string, options ...SnakeCaseOption) string
- func ToPascalCase(s string) string
- func ToUpperSnakeCase(s string, options ...SnakeCaseOption) string
- func TrimLines(output string) string
- type SnakeCaseOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlphanumeric ¶ added in v0.40.0
IsAlpha returns true for [0-9a-zA-Z].
func IsLowerAlpha ¶ added in v0.40.0
IsLowerAlpha returns true for [a-z].
func IsLowerAlphanumeric ¶ added in v0.31.1
IsLowerAlphanumeric returns true for [0-9a-z].
func IsUpperAlpha ¶ added in v0.40.0
IsUpperAlpha returns true for [A-Z].
func JoinSliceQuoted ¶ added in v0.4.1
JoinSliceQuoted joins the slice with quotes.
func MapToSlice ¶ added in v0.19.0
MapToSlice transforms m to a slice.
func MapToSortedSlice ¶
MapToSortedSlice transforms m to a sorted slice.
func SliceElementsContained ¶ added in v0.32.0
SliceElementsContained returns true if superset contains subset.
Nil and empty slices are treated as equals.
func SliceElementsEqual ¶ added in v0.4.1
SliceElementsEqual returns true if the two slices have equal elements.
Nil and empty slices are treated as equals.
func SliceToChunks ¶
SliceToChunks splits s into chunks of the given chunk size.
If s is nil or empty, returns empty. If chunkSize is <=0, returns [][]string{s}.
func SliceToHumanString ¶ added in v0.42.0
SliceToHumanString prints the slice as "e1, e2, and e3".
func SliceToHumanStringQuoted ¶ added in v0.42.0
SliceToHumanStringQuoted prints the slice as `"e1", "e2", and "e3"“.
func SliceToString ¶ added in v0.19.0
SliceToString prints the slice as [e1,e2].
func SliceToUniqueSortedSlice ¶
SliceToUniqueSortedSlice returns a sorted copy of s with no duplicates.
func SliceToUniqueSortedSliceFilterEmptyStrings ¶
SliceToUniqueSortedSliceFilterEmptyStrings returns a sorted copy of s with no duplicates and no empty strings.
Strings with only spaces are considered empty.
func SplitTrimLines ¶ added in v0.15.0
SplitTrimLines splits the output into individual lines and trims the spaces from each line.
func SplitTrimLinesNoEmpty ¶ added in v0.15.0
SplitTrimLinesNoEmpty splits the output into individual lines and trims the spaces from each line.
This removes any empty lines.
func ToLowerSnakeCase ¶
func ToLowerSnakeCase(s string, options ...SnakeCaseOption) string
ToLowerSnakeCase transforms s to lower_snake_case.
func ToPascalCase ¶
ToPascalCase converts s to PascalCase.
Splits on '-', '_', ' ', '\t', '\n', '\r'. Uppercase letters will stay uppercase,
func ToUpperSnakeCase ¶
func ToUpperSnakeCase(s string, options ...SnakeCaseOption) string
ToUpperSnakeCase transforms s to UPPER_SNAKE_CASE.
Types ¶
type SnakeCaseOption ¶
type SnakeCaseOption func(*snakeCaseOptions)
SnakeCaseOption is an option for snake_case conversions.
func SnakeCaseWithNewWordOnDigits ¶
func SnakeCaseWithNewWordOnDigits() SnakeCaseOption
SnakeCaseWithNewWordOnDigits is a SnakeCaseOption that signifies to split on digits, ie foo_bar_1 instead of foo_bar1.