Documentation
¶
Index ¶
- Constants
- func BuildFQDN(namelets ...string) string
- func BuildFQDN2(delimiter string, namelets ...string) string
- func CopySlice(src []string) []string
- func CopyStrPtr(sp *string) *string
- func FirstNonBlank(strs ...string) string
- func HasDup(src []string) bool
- func IndexWithEsc(s, delim string, esc *rune) int
- func IsStrNonBlank(s string) bool
- func IsStrPtrNonBlank(sp *string) bool
- func LastNameletOfFQDN(fqdn string) string
- func LastNameletOfFQDN2(delimiter, fqdn string) string
- func MapSlice(src []string, f func(string) (string, error)) ([]string, error)
- func MergeSlices(a, b []string) []string
- func NoErrMapSlice(src []string, f func(string) string) []string
- func RunePtr(r rune) *rune
- func SplitWithEsc(s, delim string, esc *rune) []string
- func StrPtr(s string) *string
- func StrPtrOrElse(sp *string, orElse string) string
- func Unescape(s string, esc *rune) string
- type KeyMapper
- type RuneTrie
Constants ¶
const (
// FQDNDelimiter is the default FQDN delimiter.
FQDNDelimiter = "."
)
Variables ¶
This section is empty.
Functions ¶
func BuildFQDN2 ¶
BuildFQDN2 builds an FQDN from a slice of namelet strings and a given delimiter.
func CopySlice ¶
CopySlice copies a string slice. The returned slice is guaranteed to be a different slice (thus the name Copy) so modifying the src from the caller side won't affect the returned slice.
func CopyStrPtr ¶
CopyStrPtr copies a string pointer and its underlying string value, if set, into a new string pointer.
func FirstNonBlank ¶
FirstNonBlank returns the first non-blank string value of the input strings, if any; or "" is returned.
func IndexWithEsc ¶
IndexWithEsc is similar to strings.Index but taking escape sequence into consideration. For example, IndexWithEsc("abc%|efg|xyz", "|", RunePtr("%")) would return 8, not 4.
func IsStrNonBlank ¶
IsStrNonBlank checks if a string is blank or not.
func IsStrPtrNonBlank ¶
IsStrPtrNonBlank checks if the value represented by a string pointer is blank or not.
func LastNameletOfFQDN ¶
LastNameletOfFQDN returns the last namelet of an FQDN delimited by default delimiter. If there is no delimiter in the FQDN, then the FQDN itself is // returned.
func LastNameletOfFQDN2 ¶
LastNameletOfFQDN2 returns the last namelet of an FQDN delimited by given delimiter. If there is no delimiter in the FQDN, then the FQDN itself is returned.
func MapSlice ¶
MapSlice returns a new string slice whose element is transformed from input slice's corresponding element by a transform func. If any error occurs during any transform, returned slice will be nil together with the error.
func MergeSlices ¶
MergeSlices returns a new slice with two input slice content merged together. The result is guaranteed to be a new slice thus modifying a or b from the caller side won't affect the returned slice.
func NoErrMapSlice ¶
NoErrMapSlice returns a new string slice whose element is transformed from input slice's corresponding element by a transform func. The transform func must not fail and NoErrMapSlice guarantees to succeed.
func SplitWithEsc ¶
SplitWithEsc is similar to strings.Split but taking escape sequence into consideration. For example, SplitWithEsc("abc%|efg|xyz", "|", RunePtr("%")) would return []string{"abc%|efg", "xyz"}.
func StrPtrOrElse ¶
StrPtrOrElse returns the string value of the string pointer if non-nil, or the default string value.
Types ¶
type KeyMapper ¶
KeyMapper maps one rune or a segment of consecutive runes into a key for inserting into RuneTrie, and returns how many bytes needs to be advanced
type RuneTrie ¶
type RuneTrie struct {
// contains filtered or unexported fields
}
RuneTrie is a trie of strings. By default, each trie node corresponds to a rune in a string, however, user of RuneTrie can provide a custom mapper that can map one or multiple consecutive runes into a trie key.
func NewRuneTrie ¶
NewRuneTrie creates a new RuneTrie.
func (*RuneTrie) Add ¶
Add inserts a string and its associated value into RuneTrie and returns true if the value is added; false if an existing value is replaced.
func (*RuneTrie) MarshalJSON ¶
MarshalJSON json marshals a RuneTrie. Should only be used in tests.