stringhelpers

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisallowedLabelCharacters = regexp.MustCompile("[^a-z0-9-]")

DisallowedLabelCharacters regex of chars not allowed in lables

Functions

func CheckMark

func CheckMark() string

CheckMark returns the check mark unicode character. We could configure this to use no color or avoid unicode using platform, env vars or config?

func DiffSlices

func DiffSlices(oldSlice []string, newSlice []string) ([]string, []string)

DiffSlices compares the two slices and returns an array of items to delete from the old slice and a slice of new values to add to

func ExtractKeyValuePairs

func ExtractKeyValuePairs(values []string, sep string) (map[string]string, error)

ExtractKeyValuePairs creates a map of an string array assuming that each array element is of the form <key><sep><value>. An error is returned is a array element cannot be split into a key/value pair using the specified separator.

func FirstNotEmptyString

func FirstNotEmptyString(values ...string) string

FirstNotEmptyString returns the first non empty string or the empty string if none can be found

func HasPrefix added in v1.0.48

func HasPrefix(text string, prefixes ...string) bool

HasPrefix returns true if the given string has one of the prefixes

func HasSuffix added in v1.0.48

func HasSuffix(text string, suffixes ...string) bool

HasSuffix returns true if the given string has one of the suffixes

func IsValidUrl

func IsValidUrl(s string) bool

IsValidUrl tests a string to determine if it is a well-structured url or not.

func ParseBool

func ParseBool(text string) (bool, error)

ParseBool parses the boolean string. Returns false if the string is empty

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) (string, error)

RandStringBytesMaskImprSrc returns a random hexadecimal string of length n.

func RegexpSplit

func RegexpSplit(text string, regexSeperator string) []string

RegexpSplit splits a string into an array using the regexSep as a separator

func RemoveStringFromSlice

func RemoveStringFromSlice(strings []string, toRemove string) []string

RemoveStringFromSlice removes the first occurrence of the specified string from a slice, if it exists and returns the result

func ReverseStrings

func ReverseStrings(a []string)

func SanitizeURL

func SanitizeURL(unsanitizedUrl string) string

SanitizeURL sanitizes by stripping the user and password

func SortedMapKeys

func SortedMapKeys(m map[string]string) []string

SortedMapKeys returns the sorted keys of the given map

func StringArrayHasPrefixIndex

func StringArrayHasPrefixIndex(array []string, prefix string) int

StringArrayHasPrefixIndex returns the index in the slice which the value has the given prefix

func StringArrayIndex

func StringArrayIndex(array []string, value string) int

StringArrayIndex returns the index in the slice which equals the given value

func StringArrayToLower

func StringArrayToLower(values []string) []string

StringArrayToLower returns a string slice with all the values converted to lower case

func StringArraysEqual

func StringArraysEqual(a1 []string, a2 []string) bool

StringArraysEqual returns true if the two string slices are equal

func StringContainsAny

func StringContainsAny(text string, includes []string, excludes []string) bool

StringContainsAny returns true if the given text contains the includes/excludes lists

func StringIndexes

func StringIndexes(text string, value string) []int

StringIndexes returns all the indices where the value occurs in the given string

func StringMatchesAny

func StringMatchesAny(text string, includes []string, excludes []string) bool

StringMatchesAny returns true if the given text matches the includes/excludes lists

func StringMatchesPattern

func StringMatchesPattern(text string, pattern string) bool

StringMatchesPattern returns true if the given text matches the includes/excludes lists

func StringsContaining

func StringsContaining(slice []string, filter string) []string

StringsContaining if the filter is not empty return all the strings which contain the text

func StripTrailingSlash

func StripTrailingSlash(url string) string

StripTrailingSlash removes any trailing forward slashes on the URL

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase turn "my-super-name" into "MySuperName" Usefule for creating valid go-template variable names

func URLSetUserPassword added in v1.0.56

func URLSetUserPassword(rawURL, username, password string) (string, error)

URLSetUserPassword adds the user and password to the URL

func URLToHostName

func URLToHostName(svcURL string) string

URLToHostName converts the given URL to a host name returning the error string if its not a URL

func UrlEqual

func UrlEqual(url1, url2 string) bool

UrlEqual verifies if URLs are equal

func UrlHostNameWithoutPort

func UrlHostNameWithoutPort(rawUri string) (string, error)

UrlHostNameWithoutPort returns the host name without any port of the given URL like string

func UrlJoin

func UrlJoin(paths ...string) string

UrlJoin joins the given paths so that there is only ever one '/' character between the paths

func YesNo

func YesNo(t bool) string

YesNo returns a Yes/No conversion for a boolean parameter

Types

This section is empty.

Jump to

Keyboard shortcuts

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