Back to godoc.org

Package stringutil

v0.20.5
Latest Go to latest
Published: Jul 24, 2020 | License: Apache-2.0 | Module: github.com/bufbuild/buf

Overview

Package stringutil implements string utilities.

Index

Package Files

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 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 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.

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.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier