stringutil

package
v0.52.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package stringutil implements string utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlpha added in v0.40.0

func IsAlpha(r rune) bool

IsAlpha returns true for [a-zA-Z].

func IsAlphanumeric added in v0.40.0

func IsAlphanumeric(r rune) bool

IsAlpha returns true for [0-9a-zA-Z].

func IsLowerAlpha added in v0.40.0

func IsLowerAlpha(r rune) bool

IsLowerAlpha returns true for [a-z].

func IsLowerAlphanumeric added in v0.31.1

func IsLowerAlphanumeric(r rune) bool

IsLowerAlphanumeric returns true for [0-9a-z].

func IsNumeric added in v0.40.0

func IsNumeric(r rune) bool

IsNumeric returns true for [0-9].

func IsUpperAlpha added in v0.40.0

func IsUpperAlpha(r rune) bool

IsUpperAlpha returns true for [A-Z].

func JoinSliceQuoted added in v0.4.1

func JoinSliceQuoted(s []string, sep string) string

JoinSliceQuoted joins the slice with quotes.

func MapToSlice added in v0.19.0

func MapToSlice(m map[string]struct{}) []string

MapToSlice transforms m to a slice.

func MapToSortedSlice

func MapToSortedSlice(m map[string]struct{}) []string

MapToSortedSlice transforms m to a sorted slice.

func SliceElementsContained added in v0.32.0

func SliceElementsContained(superset []string, subset []string) bool

SliceElementsContained returns true if superset contains subset.

Nil and empty slices are treated as equals.

func SliceElementsEqual added in v0.4.1

func SliceElementsEqual(one []string, two []string) bool

SliceElementsEqual returns true if the two slices have equal elements.

Nil and empty slices are treated as equals.

func SliceToChunks

func SliceToChunks(s []string, chunkSize int) [][]string

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

func SliceToHumanString(s []string) string

SliceToHumanString prints the slice as "e1, e2, and e3".

func SliceToHumanStringQuoted added in v0.42.0

func SliceToHumanStringQuoted(s []string) string

SliceToHumanStringQuoted prints the slice as `"e1", "e2", and "e3"“.

func SliceToMap

func SliceToMap(s []string) map[string]struct{}

SliceToMap transforms s to a map.

func SliceToString added in v0.19.0

func SliceToString(s []string) string

SliceToString prints the slice as [e1,e2].

func SliceToUniqueSortedSlice

func SliceToUniqueSortedSlice(s []string) []string

SliceToUniqueSortedSlice returns a sorted copy of s with no duplicates.

func SliceToUniqueSortedSliceFilterEmptyStrings

func SliceToUniqueSortedSliceFilterEmptyStrings(s []string) []string

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

func SplitTrimLines(output string) []string

SplitTrimLines splits the output into individual lines and trims the spaces from each line.

func SplitTrimLinesNoEmpty added in v0.15.0

func SplitTrimLinesNoEmpty(output string) []string

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

func ToPascalCase(s string) string

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.

func TrimLines

func TrimLines(output string) string

TrimLines splits the output into individual lines and trims the spaces from each line.

This also trims the start and end spaces from the original output.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL