strings

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2020 License: MPL-2.0, MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src []string) (dst []string)

Copy returns a copy of the source slice.

func SliceOfSlice

func SliceOfSlice(slices ...[]string) (sos [][]string)

func SortReverseStable

func SortReverseStable(s []string)

func SortStable

func SortStable(s []string)

func StringKeyPtr

func StringKeyPtr(m *map[string]string, targetKey string) (*string, func(), error)

StringMapPtr returns string pointer which can be used to update a map[string]string value, working around the lack of support for syntax like Fn(&myMap[key]) which leads to the error "cannot take the address of myMap[key]".

The function it returns must be called in order to save each update. An error is returned if the target key is not found in the map.

func TruncateAppendHint

func TruncateAppendHint(s string, max int, hint string) string

Truncate returns the string with a maximum length enforced and optional appended hint (e.g. "...").

The truncate string and hint will fit inside the maximum length if possible.

func TruncatePrependHint

func TruncatePrependHint(s string, max int, hint string) string

Truncate returns the string with a maximum length enforced and optional prepended hint (e.g. "...").

The truncate string and hint will fit inside the maximum length if possible.

Types

type Replace

type Replace struct {
	Limit int
	New   string
	Old   string
}

Replace defines strings.Replace parameters.

type ReplaceSet

type ReplaceSet map[string]Replace

ReplaceSet holds replacement definitons indexed by Replace.Old values.

func (*ReplaceSet) Add

func (s *ReplaceSet) Add(old, new string, limit int) *ReplaceSet

Add creates or overwrites a replacement definiton for the given old/target string.

func (*ReplaceSet) InByte

func (s *ReplaceSet) InByte(subject []byte) []byte

InByte returns the subject byte slice with all replacements performed in length-descending order of Replace.Old values.

func (*ReplaceSet) InString

func (s *ReplaceSet) InString(subject string) string

InString returns the subject string with all replacements performed in length-descending order of Replace.Old values.

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSet

func NewSet() *Set

NewSet returns an initialized Set.

It returns a pointer to support use as a map's value type and avoid the "cannot call pointer method" error.

func (*Set) Add

func (s *Set) Add(el string) bool

func (*Set) AddSet

func (s *Set) AddSet(sets ...*Set) *Set

func (*Set) AddSlice

func (s *Set) AddSlice(slices ...[]string) *Set

func (*Set) Clear

func (s *Set) Clear()

func (*Set) Contains

func (s *Set) Contains(el string) bool

func (*Set) Copy

func (s *Set) Copy() *Set

func (*Set) Diff

func (s *Set) Diff(other *Set) *Set

Diff returns the strings found in this Set but not in the other Set.

func (*Set) Equals

func (s *Set) Equals(other *Set) bool

func (*Set) Len

func (s *Set) Len() int

func (*Set) Remove

func (s *Set) Remove(el string) bool

func (*Set) Slice

func (s *Set) Slice() []string

func (*Set) SortedReverseSlice

func (s *Set) SortedReverseSlice() []string

func (*Set) SortedSlice

func (s *Set) SortedSlice() []string

type Stack added in v0.1.1

type Stack struct {
	// contains filtered or unexported fields
}

func NewStack added in v0.1.1

func NewStack() *Stack

NewStack returns an initialized Stack.

func (*Stack) Contains added in v0.1.1

func (s *Stack) Contains(query string) bool

Contains returns true if the query is present.

func (*Stack) Items added in v0.1.1

func (s *Stack) Items() (items []string)

Items returns the current contents.

func (*Stack) Pop added in v0.1.1

func (s *Stack) Pop() *string

Pop removes the most recently pushed item, if it exists, and returns it. If it does not exist, it returns nil.

func (*Stack) Push added in v0.1.1

func (s *Stack) Push(items ...string)

Push appends one or more items.

Jump to

Keyboard shortcuts

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