stringutil

package
v0.0.0-...-26f4575 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stringutil implements string utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlpha

func IsAlpha(r rune) bool

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

func IsAlphanumeric

func IsAlphanumeric(r rune) bool

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

func IsLowerAlpha

func IsLowerAlpha(r rune) bool

IsLowerAlpha returns true for [a-z].

func IsLowerAlphanumeric

func IsLowerAlphanumeric(r rune) bool

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

func IsNumeric

func IsNumeric(r rune) bool

IsNumeric returns true for [0-9].

func IsUpperAlpha

func IsUpperAlpha(r rune) bool

IsUpperAlpha returns true for [A-Z].

func JoinSliceQuoted

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

JoinSliceQuoted joins the slice with quotes.

func MapToSlice

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

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

SliceElementsContained returns true if superset contains subset.

Nil and empty slices are treated as equals.

func SliceElementsEqual

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

func SliceToHumanString(s []string) string

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

func SliceToHumanStringOr

func SliceToHumanStringOr(s []string) string

SliceToHumanStringOr prints the slice as "e1, e2, or e3".

func SliceToHumanStringOrQuoted

func SliceToHumanStringOrQuoted(s []string) string

SliceToHumanStringOrQuoted prints the slice as `"e1", "e2", or "e3"`.

func SliceToHumanStringQuoted

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

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

func SplitTrimLines(output string) []string

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

func SplitTrimLinesNoEmpty

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