utilstring

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package utilstring implements string utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinSliceQuoted

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

JoinSliceQuoted joins the slice with quotes.

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