strings

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: MPL-2.0 Imports: 3 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 shallow 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 {
	// 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

Jump to

Keyboard shortcuts

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