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 SliceToHumanStringOr(s []string) string
- func SliceToHumanStringOrQuoted(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 IsLowerAlphanumeric ¶
IsLowerAlphanumeric returns true for [0-9a-z].
func JoinSliceQuoted ¶
JoinSliceQuoted joins the slice with quotes.
func MapToSlice ¶
MapToSlice transforms m to a slice.
func MapToSortedSlice ¶
MapToSortedSlice transforms m to a sorted slice.
func SliceElementsContained ¶
SliceElementsContained returns true if superset contains subset.
Nil and empty slices are treated as equals.
func SliceElementsEqual ¶
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 ¶
SliceToHumanString prints the slice as "e1, e2, and e3".
func SliceToHumanStringOr ¶
SliceToHumanStringOr prints the slice as "e1, e2, or e3".
func SliceToHumanStringOrQuoted ¶
SliceToHumanStringOrQuoted prints the slice as `"e1", "e2", or "e3"`.
func SliceToHumanStringQuoted ¶
SliceToHumanStringQuoted prints the slice as `"e1", "e2", and "e3"`.
func SliceToString ¶
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 ¶
SplitTrimLines splits the output into individual lines and trims the spaces from each line.
func SplitTrimLinesNoEmpty ¶
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.