Documentation ¶
Index ¶
- type StrArray
- func (a *StrArray) Append(value ...string) *StrArray
- func (a *StrArray) Chunk(size int) [][]string
- func (a *StrArray) Clear() *StrArray
- func (a *StrArray) Clone() (newArray *StrArray)
- func (a *StrArray) Contains(value string) bool
- func (a *StrArray) ContainsI(value string) bool
- func (a *StrArray) CountValues() map[string]int
- func (a *StrArray) Fill(startIndex int, num int, value string) error
- func (a *StrArray) FilterEmpty() *StrArray
- func (a *StrArray) Get(index int) (value string, found bool)
- func (a *StrArray) InsertAfter(index int, value string) error
- func (a *StrArray) InsertBefore(index int, value string) error
- func (a *StrArray) Interfaces() []interface{}
- func (a *StrArray) IsEmpty() bool
- func (a *StrArray) Iterator(f func(k int, v string) bool)
- func (a *StrArray) IteratorAsc(f func(k int, v string) bool)
- func (a *StrArray) IteratorDesc(f func(k int, v string) bool)
- func (a *StrArray) Join(glue string) string
- func (a *StrArray) Len() int
- func (a *StrArray) LockFunc(f func(array []string)) *StrArray
- func (a StrArray) MarshalJSON() ([]byte, error)
- func (a *StrArray) Merge(array []string) *StrArray
- func (a *StrArray) Pad(size int, value string) *StrArray
- func (a *StrArray) PopLeft() (value string, found bool)
- func (a *StrArray) PopLefts(size int) []string
- func (a *StrArray) PopRand() (value string, found bool)
- func (a *StrArray) PopRands(size int) []string
- func (a *StrArray) PopRight() (value string, found bool)
- func (a *StrArray) PopRights(size int) []string
- func (a *StrArray) PushLeft(value ...string) *StrArray
- func (a *StrArray) PushRight(value ...string) *StrArray
- func (a *StrArray) RLockFunc(f func(array []string)) *StrArray
- func (a *StrArray) Rand() (value string, found bool)
- func (a *StrArray) Rands(size int) []string
- func (a *StrArray) Range(start int, end ...int) []string
- func (a *StrArray) Remove(index int) (value string, found bool)
- func (a *StrArray) RemoveValue(value string) bool
- func (a *StrArray) Replace(array []string) *StrArray
- func (a *StrArray) Reverse() *StrArray
- func (a *StrArray) Search(value string) int
- func (a *StrArray) Set(index int, value string) error
- func (a *StrArray) SetArray(array []string) *StrArray
- func (a *StrArray) Shuffle() *StrArray
- func (a *StrArray) Slice() []string
- func (a *StrArray) Sort(reverse ...bool) *StrArray
- func (a *StrArray) SortFunc(less func(v1, v2 string) bool) *StrArray
- func (a *StrArray) SubSlice(offset int, length ...int) []string
- func (a *StrArray) Sum() (sum int)
- func (a *StrArray) Unique() *StrArray
- func (a *StrArray) UnmarshalJSON(b []byte) error
- func (a *StrArray) Walk(f func(value string) string) *StrArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StrArray ¶
type StrArray struct {
// contains filtered or unexported fields
}
StrArray is a golang string array with rich features.
func NewStrArray ¶
NewStrArray creates and returns an empty array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArrayFrom ¶
NewStrArrayFrom creates and returns an array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArrayFromCopy ¶
NewStrArrayFromCopy creates and returns an array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArraySize ¶
NewStrArraySize create and returns an array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*StrArray) Chunk ¶
Chunk splits an array into multiple arrays, the size of each array is determined by <size>. The last chunk may contain less than size elements.
func (*StrArray) ContainsI ¶
ContainsI checks whether a value exists in the array with case-insensitively. Note that it internally iterates the whole array to do the comparison with case-insensitively.
func (*StrArray) CountValues ¶
CountValues counts the number of occurrences of all values in the array.
func (*StrArray) Fill ¶
Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.
func (*StrArray) FilterEmpty ¶
FilterEmpty removes all empty string value of the array.
func (*StrArray) Get ¶
Get returns the value by the specified index. If the given <index> is out of range of the array, the <found> is false.
func (*StrArray) InsertAfter ¶
InsertAfter inserts the <value> to the back of <index>.
func (*StrArray) InsertBefore ¶
InsertBefore inserts the <value> to the front of <index>.
func (*StrArray) Interfaces ¶
func (a *StrArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*StrArray) IteratorAsc ¶
IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*StrArray) IteratorDesc ¶
IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (StrArray) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
func (*StrArray) Merge ¶
Merge merges <array> into current array. The parameter <array> can be any garray or slice type. The difference between Merge and Append is Append supports only specified slice type, but Merge supports more parameter types.
func (*StrArray) Pad ¶
Pad pads array to the specified length with <value>. If size is positive then the array is padded on the right, or negative on the left. If the absolute value of <size> is less than or equal to the length of the array then no padding takes place.
func (*StrArray) PopLeft ¶
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopLefts ¶
PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) PopRand ¶
PopRand randomly pops and return an item out of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopRands ¶
PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) PopRight ¶
PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopRights ¶
PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) PushRight ¶
PushRight pushes one or multiple items to the end of array. It equals to Append.
func (*StrArray) Range ¶
Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*StrArray) Remove ¶
Remove removes an item by index. If the given <index> is out of range of the array, the <found> is false.
func (*StrArray) RemoveValue ¶
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*StrArray) Replace ¶
Replace replaces the array items by given <array> from the beginning of array.
func (*StrArray) Search ¶
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*StrArray) Slice ¶
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*StrArray) Sort ¶
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order
func (*StrArray) SubSlice ¶
SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*StrArray) Unique ¶
Unique uniques the array, clear repeated items. Example: [1,1,2,3,2] -> [1,2,3]
func (*StrArray) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.