buf: github.com/bufbuild/buf/internal/pkg/stringutil Index | Files

package stringutil

import "github.com/bufbuild/buf/internal/pkg/stringutil"

Package stringutil implements string utilities.


Package Files


func JoinSliceQuoted Uses

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

JoinSliceQuoted joins the slice with quotes.

func MapToSlice Uses

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

MapToSlice transforms m to a slice.

func MapToSortedSlice Uses

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

MapToSortedSlice transforms m to a sorted slice.

func SliceElementsEqual Uses

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 Uses

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 Uses

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

SliceToMap transforms s to a map.

func SliceToString Uses

func SliceToString(s []string) string

SliceToString prints the slice as [e1,e2].

func SliceToUniqueSortedSlice Uses

func SliceToUniqueSortedSlice(s []string) []string

SliceToUniqueSortedSlice returns a sorted copy of s with no duplicates.

func SliceToUniqueSortedSliceFilterEmptyStrings Uses

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 Uses

func SplitTrimLines(output string) []string

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

func SplitTrimLinesNoEmpty Uses

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 Uses

func ToLowerSnakeCase(s string, options ...SnakeCaseOption) string

ToLowerSnakeCase transforms s to lower_snake_case.

func ToPascalCase Uses

func ToPascalCase(s string) string

ToPascalCase converts s to PascalCase.

Splits on '-', '_', ' ', '\t', '\n', '\r'. Uppercase letters will stay uppercase,

func ToUpperSnakeCase Uses

func ToUpperSnakeCase(s string, options ...SnakeCaseOption) string

ToUpperSnakeCase transforms s to UPPER_SNAKE_CASE.

func TrimLines Uses

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 Uses

type SnakeCaseOption func(*snakeCaseOptions)

SnakeCaseOption is an option for snake_case conversions.

func SnakeCaseWithNewWordOnDigits Uses

func SnakeCaseWithNewWordOnDigits() SnakeCaseOption

SnakeCaseWithNewWordOnDigits is a SnakeCaseOption that signifies to split on digits, ie foo_bar_1 instead of foo_bar1.

Package stringutil imports 3 packages (graph) and is imported by 12 packages. Updated 2020-10-25. Refresh now. Tools for package owners.