strslices

package
v0.70.13 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 10 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BySplitLength added in v0.68.7

func BySplitLength(s []string, sep string) map[int][]string

dBySplitLength returns lines by split length. This is useful for analyzing what types of data exist with different lengths.

func ChooseOnePreferredLowerTrimSpace added in v0.68.7

func ChooseOnePreferredLowerTrimSpace(options, preferenceOrder []string) string

func Compare added in v0.68.7

func Compare(sliceA, sliceB []string) ([]string, []string, []string)

Compare returns 3 slices given 2 slices which represent intersection sets. The first set is present in slice A but not B, second for both and third present in slice B but not A.

func CondenseAndQuote added in v0.68.7

func CondenseAndQuote(s []string, trimLeft, trimRight, quoteLeft, quoteRight string) []string

func CondenseAndQuoteSpace added in v0.68.7

func CondenseAndQuoteSpace(s []string, quoteLeft, quoteRight string) []string

func CondensePunctuation added in v0.68.7

func CondensePunctuation(s []string) []string

func CondenseRegexps added in v0.68.7

func CondenseRegexps(s []string, regexps []*regexp.Regexp, replacement string) []string

func CondenseSpace added in v0.68.7

func CondenseSpace(elems []string, dedupeResults, sortResults bool) []string

CondenseSpace trims space from lines and removes empty lines. `unique` dedupes lines and `sort` preforms a sort on the results.

func Contains

func Contains(s []string, v string) int

Contains checks a slice of string to validate if individual string elements contain the supplied match string. A `1` is returned if all slice strings match, a `-1` is returned if no slices strings match, and a `0` is returned if more than one, but less than all slice strings match. An empty slice returns a `-1` as there are no members to match.

func ContainsIndex

func ContainsIndex(s []string, substr string) int

ContainsIndex returns the index of the first match using `strings.Contains()`. Returns -1 if not found.

func ElementHasIndex

func ElementHasIndex(haystack []string, needle string, wantIndex int) bool

func Index

func Index(haystack []string, needle string, equalFold bool, caser *cases.Caser) int

Index returns the index of the first match using `=`. Returns -1 if not found. if `equalFold` is selected and `caser` is `nil`, the default caser will be used.

func IndexMore

func IndexMore(haystack []string, needle string, trimSpace, toLower bool, matchType stringsutil.MatchType) int

IndexMore returns the index of an element in a string slice. Returns -1 if not found.

func IndexMulti

func IndexMulti(s string, substr ...string) int

IndexMulti returns the earliest match.

func IndexValueOrDefault

func IndexValueOrDefault(s []string, index int, def string) string

IndexValueOrDefault returns the element at the index provided or the default string.

func Intersection added in v0.68.7

func Intersection(list1, list2 []string) []string

func IntersectionCondenseSpace added in v0.68.7

func IntersectionCondenseSpace(slice1, slice2 []string) []string

func IsEmpty added in v0.68.7

func IsEmpty(s []string, skipEmptyStrings bool) bool

IsEmpty checks to see if a slice is empty. If `skipEmptyStrings` it will also return empty if all elements are empty strings or only contain spaces.

func JoinFunc added in v0.68.7

func JoinFunc(s []string, sep string, f func(string) string) string

JoinFunc joins a slice passing each elemen through the supplied function `f`.

func Map added in v0.68.7

func Map(s []string, fn func(s string) string) []string

func MatchAny added in v0.68.7

func MatchAny(s1, s2 []string, caseInsensive, trimSpace bool) bool

func OrderExplicit added in v0.68.7

func OrderExplicit(s, order []string, inclUnordered bool) ([]string, []int)

OrderExplicit reoders the values of a slice using a requested input order where the output is ordered by the requested order, minus missing requests, and followed by non-ordered items. In addition to the output slide, an output slice of index locations is also provided.

func SoSFilterLinesHaveIndex

func SoSFilterLinesHaveIndex(groups [][]string, needle string, wantIndex int) [][]string

func SplitLengthStats added in v0.68.7

func SplitLengthStats(s []string, sep string) map[int]int

SplitLengthStats returns a `map[int]int` indicating how many strings of which length are present.

func Subtract added in v0.68.7

func Subtract(real, filter []string) []string

Subtract uses Set math to remove elements of filter from real.

func ToDoc added in v0.68.7

func ToDoc(s []string, cfg map[string]int, trimSpace, inclEmpty bool) map[string]string

ToDoc converts a slice to a map, trimming the values if desired. The `cfg` keys are the document property names or keys and the values are the index location of the slice.

func ToLower added in v0.68.7

func ToLower(s []string) []string

func ToMap added in v0.68.7

func ToMap(s []string) map[string]int

ToMap returns the slide where the slice elements are the keys of the map, and the value is the number of times it appears.

func ToSingleIntOrNeg added in v0.68.7

func ToSingleIntOrNeg(s []string) int

ToSingleIntOrNeg converts a single element slice with a string to an integer or `-1`

func ToUpper added in v0.68.7

func ToUpper(s []string) []string

func Trim added in v0.68.7

func Trim(elems []string, cutstr string, condense bool) []string

Trim trims each line in a slice of lines using a provided cut string.

func TrimSpace added in v0.68.7

func TrimSpace(elems []string, condense bool) []string

TrimSpace removes leading and trailing spaces per string. If condense is used, empty strings are removed.

Types

type Strings added in v0.68.7

type Strings []string

func (Strings) FilterIndexes added in v0.68.7

func (strs Strings) FilterIndexes(indexes []int) (Strings, error)

Jump to

Keyboard shortcuts

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