strs

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 5 Imported by: 24

Documentation

Index

Constants

View Source
const (
	// FQDNDelimiter is the default FQDN delimiter.
	FQDNDelimiter = "."
	// FQDNEsc is the default escape char for FQDN. Esc is used for escaping "." and itself.
	FQDNEsc = "%"
)

Variables

This section is empty.

Functions

func BuildFQDN

func BuildFQDN(namelets ...string) string

BuildFQDN builds an FQDN (dot delimited) from a slice of namelet strings.

func BuildFQDN2

func BuildFQDN2(delimiter string, namelets ...string) string

BuildFQDN2 builds an FQDN from a slice of namelet strings and a given delimiter.

func BuildFQDNWithEsc added in v0.0.14

func BuildFQDNWithEsc(namelets ...string) string

BuildFQDNWithEsc builds an FQDN (dot delimited) from a slice of namelet strings with proper escaping. e.g. If namelets are 'a.b', 'c%d', it will return 'a%.b.c%%d'. Note this function isn't optimized for alloc/perf.

func ByteIndexWithEsc added in v0.0.8

func ByteIndexWithEsc(s, delim, esc []byte) int

ByteIndexWithEsc searches for 'delim' inside 's' with escaping sequence taking into account. Note 'delim' must not contain 'esc', or if it does, 'esc' inside 'delim' will be treated as regular bytes.

func ByteLenOfRunes added in v0.0.7

func ByteLenOfRunes(rs []rune) int

ByteLenOfRunes returns byte length of a rune slice.

func ByteSplitWithEsc added in v0.0.6

func ByteSplitWithEsc(s, delim, esc []byte, cap int) [][]byte

ByteSplitWithEsc is similar to SplitWithEsc but operating on []byte. 'cap' is just an indicator to the function that what the initial cap the returned split slice should be pre-allocated.

func ByteUnescape added in v0.0.8

func ByteUnescape(b, esc []byte, inPlace bool) []byte

ByteUnescape unescapes a []byte sequence with an escape []byte sequence. If 'inPlace' is true, the unescaping modification is taking place inside the original 'b' and 'b' will be returned with length properly adjusted. If 'inPlace' is false, the unescaping is taking place inside a new []byte, the new []byte will be returned and the original 'b' is untouched.

func CopySlice

func CopySlice(src []string) []string

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

func CopyStrPtr(sp *string) *string

CopyStrPtr copies a string pointer and its underlying string value, if set, into a new string pointer.

func FirstNonBlank

func FirstNonBlank(strs ...string) string

FirstNonBlank returns the first non-blank string value of the input strings, if any; or "" is returned.

func HasDup

func HasDup(src []string) bool

HasDup detects whether there are duplicates existing in the src slice.

func IndexWithEsc

func IndexWithEsc(s, delim string, esc string) int

IndexWithEsc searches for 'delim' inside 's' with escaping sequence taking into account. Note 'delim' must not contain 'esc', or if it does, 'esc' inside 'delim' will be treated as regular string.

func IsStrNonBlank

func IsStrNonBlank(s string) bool

IsStrNonBlank checks if a string is blank or not.

func IsStrPtrNonBlank

func IsStrPtrNonBlank(sp *string) bool

IsStrPtrNonBlank checks if the value represented by a string pointer is blank or not.

func LastNameletOfFQDN

func LastNameletOfFQDN(fqdn string) string

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

func LastNameletOfFQDN2(delimiter, fqdn string) string

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 LastNameletOfFQDNWithEsc added in v0.0.14

func LastNameletOfFQDNWithEsc(fqdn string) string

LastNameletOfFQDNWithEsc returns the last namelet of an FQDN delimited by default delimiter, with escaping considered. If there is no delimiter in the FQDN, then the FQDN itself is returned. Note this function isn't optimized for alloc/perf.

func MapSlice

func MapSlice(src []string, f func(string) (string, error)) ([]string, error)

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

func MergeSlices(a, b []string) []string

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

func NoErrMapSlice(src []string, f func(string) string) []string

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 RunePtr

func RunePtr(r rune) *rune

RunePtr returns a pointer to a rune.

func SplitWithEsc

func SplitWithEsc(s, delim string, esc string) []string

SplitWithEsc is similar to strings.Split but taking escape sequence into consideration. For example, SplitWithEsc("abc%|efg|xyz", "|", "%") would return []string{"abc%|efg", "xyz"}.

func StrPtr

func StrPtr(s string) *string

StrPtr returns string pointer that points to a given string value.

func StrPtrOrElse

func StrPtrOrElse(sp *string, orElse string) string

StrPtrOrElse returns the string value of the string pointer if non-nil, or the default string value.

func Unescape

func Unescape(s, esc string) string

Unescape unescapes a string with escape sequence. For example, SplitWithEsc("abc%|efg", "%") would return "abc|efg".

Types

type KeyMapper

type KeyMapper func(s string, index int) (advance int, key uint64)

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

func NewRuneTrie(mappers ...KeyMapper) *RuneTrie

NewRuneTrie creates a new RuneTrie.

func (*RuneTrie) Add

func (t *RuneTrie) Add(s string, value interface{}) bool

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

func (t *RuneTrie) Get(s string) (interface{}, bool)

Get looks up a string in RuneTrie and returns its associated value if found.

func (*RuneTrie) MarshalJSON

func (t *RuneTrie) MarshalJSON() ([]byte, error)

MarshalJSON json marshals a RuneTrie. Should only be used in tests.

func (*RuneTrie) NodeCount

func (t *RuneTrie) NodeCount() int

NodeCount returns the total number of nodes in the trie.

Jump to

Keyboard shortcuts

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