Documentation ¶
Overview ¶
Package gostringlist - an object to make managing lists of strings more convenient. In some cases, convenient frontends for functionality defined in other packages are provided
©2020 Jon Yoder <jsyoder@mailfence.com> Released under the MIT License
Index ¶
- type StringList
- func (list *StringList) Append(str string)
- func (list StringList) Contains(str string) bool
- func (list StringList) Copy() StringList
- func (list StringList) Filter(op func(int, []string) (bool, string)) StringList
- func (list StringList) IndexOf(str string) int
- func (list *StringList) Insert(str string, index int) error
- func (list StringList) IsEmpty() bool
- func (list StringList) IsEqual(list2 StringList) bool
- func (list StringList) Join(sep string) string
- func (list StringList) MatchFilter(pattern string) (StringList, error)
- func (list *StringList) Remove(str string)
- func (list *StringList) RemoveUnordered(str string)
- func (list StringList) ReplaceAllFilter(pattern string, repl string) (StringList, error)
- func (list *StringList) Sort()
- func (list StringList) ToString() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StringList ¶
type StringList struct {
Items []string
}
StringList - a class for managing and manipulating lists of strings. It stores the items internally as a slice, so memory management caveats apply.
func (*StringList) Append ¶
func (list *StringList) Append(str string)
Append appends a string to the list
func (StringList) Contains ¶
func (list StringList) Contains(str string) bool
Contains returns true if the list contains an exact match of the specified string
func (StringList) Copy ¶
func (list StringList) Copy() StringList
Copy creates a duplicate of the existing object
func (StringList) Filter ¶
func (list StringList) Filter(op func(int, []string) (bool, string)) StringList
Filter is a generic interface to creating new StringLists from the original, similar to Python's list comprehensions. It takes a pointer to a filter function. The filter function is passed an index to the current item and the slice of strings to be used as the source. It is expected to return a boolean and a string. The boolean value specifies whether the returned string is to be added to the filtered list.
func (StringList) IndexOf ¶
func (list StringList) IndexOf(str string) int
IndexOf returns the index of item if the list contains an exact match of the specified string or -1 if not found
func (*StringList) Insert ¶
func (list *StringList) Insert(str string, index int) error
Insert inserts the specified string into the list at the specified index. Like Remove(), this method performs some memory reallocations and copying as needed in order to provide convenience. As such, it is expensive, and if you need to do a lot of insertions, a task-specific implementation will perform better.
func (StringList) IsEmpty ¶
func (list StringList) IsEmpty() bool
IsEmpty returns true if the object contains no items.
func (StringList) IsEqual ¶
func (list StringList) IsEqual(list2 StringList) bool
IsEqual returns true if the current object's items match exactly those of the passed StringList.
func (StringList) Join ¶
func (list StringList) Join(sep string) string
Join - convenience function to return all items joined by the specified character
func (StringList) MatchFilter ¶
func (list StringList) MatchFilter(pattern string) (StringList, error)
MatchFilter returns a new StringList containing all the items in the list which match the supplied regular expression
func (*StringList) Remove ¶
func (list *StringList) Remove(str string)
Remove deletes the string from the list. This method removes the item by copying each element after the one deleted to the slot before it, which is the method recommended from The Go Programming Language. Speed is sacrificed for the sake of convenience. If you intend to do a lot of removal, you are better off implementing a task-specific version.
func (*StringList) RemoveUnordered ¶
func (list *StringList) RemoveUnordered(str string)
RemoveUnordered deletes the string from the list like Remove(), but it rearranges the items for the sake of speed. If the order of the list items doesn't matter, this method should be preferred over Remove()
func (StringList) ReplaceAllFilter ¶
func (list StringList) ReplaceAllFilter(pattern string, repl string) (StringList, error)
ReplaceAllFilter returns a new StringList containing all the items in the list which match the supplied regular expression
func (*StringList) Sort ¶
func (list *StringList) Sort()
Sort - sorts the list in ascending alphabetical order
func (StringList) ToString ¶
func (list StringList) ToString() string
ToString converts the list to a string conveying its contents