stringsutil

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringToLower     = "StringToLower"
	SpaceToHyphen     = "SpaceToHyphen"
	SpaceToUnderscore = "SpaceToUnderscore"
)
View Source
const CommonInitialisms = "" /* 160-byte string literal not displayed */

CommonInitialisms is the listed by Go Lint.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s1 string) string

Capitalize returns a string with the first character capitalized and the rest lower cased.

func CheckSuffix added in v0.0.5

func CheckSuffix(input, wantSuffix string) (fullstring, prefix, suffix string)

func CommonInitialismsMap

func CommonInitialismsMap() map[string]bool

CommonInitialismsMap returns map[string]bool of upper case initialisms.

func CondenseSpace added in v0.0.18

func CondenseSpace(s string) string

CondenseSpace removes extra spaces.

func CondenseString

func CondenseString(content string, join_lines bool) string

CondenseString trims whitespace at the ends of the string as well as in between.

func Dedupe

func Dedupe(vals []string) []string

Dedupe returns a string slice with duplicate values removed. First observance is kept.

func DigitsOnly

func DigitsOnly(input string) string

func EndsWith added in v0.0.11

func EndsWith(s string, substrs ...string) bool

func Equal

func Equal(str1, str2 string, trim, lower bool) bool

func FirstNonEmpty added in v0.28.1

func FirstNonEmpty(vals ...string) string

func FirstNotEmptyTrimSpace added in v0.0.19

func FirstNotEmptyTrimSpace(candidates ...string) string

FirstNotEmptyTrimSpace returns the first non-empty string after applying `strings.TrimSpace()`.`

func FormatString

func FormatString(s string, options []string) string

func IfBoolString added in v0.0.10

func IfBoolString(boolVal bool, valueA, valueB string) string

func InterfaceToSliceString

func InterfaceToSliceString(s interface{}) []string

func IsInteger added in v0.27.0

func IsInteger(input string) bool

func JoinInterface

func JoinInterface(arr []interface{}, sep string, stripRepeatedSep bool, stripEmbeddedSep bool, altSep string) string

JoinInterface joins an interface and returns a string. It takes a join separator, boolean to replace the join separator in the string parts and a separator alternate. `stripEmbeddedSep` strips separator string found within parts. `stripRepeatedSep` strips repeating separators. This flexibility is designed to support joining data for both CSVs and paths.

func JoinLiterary

func JoinLiterary(slice []string, sep, joinWord string) string

func JoinLiteraryQuote

func JoinLiteraryQuote(slice []string, leftQuote, rightQuote, sep, joinWord string) string

func JoinStringsTrimSpaceToLowerSort

func JoinStringsTrimSpaceToLowerSort(strs []string, sep string) string

func JoinTrimSpace

func JoinTrimSpace(strs []string) string

func Match

func Match(s string, matchInfo MatchInfo) (bool, error)

Match provides an canonical way to match strings using multiple approaches

func NewlineToLinux

func NewlineToLinux(input string) string

func PadLeft

func PadLeft(str string, pad string, length int) string

PadLeft prepends a string to a base string until the string length is greater or equal to the desired length.

func PadRight

func PadRight(str string, pad string, length int) string

PadRight appends a string to a base string until the string length is greater or equal to the desired length.

func Quote

func Quote(str, beg, end string) string

func RemoveSpaces

func RemoveSpaces(input string) string

RemoveSpaces eliminates all spaces in a string.

func Reverse added in v0.30.7

func Reverse(s string) string

Reverse reverses string using strings.Builder. It's about 3 times faster than the one with using a string concatenation

func ReverseIndex added in v0.30.7

func ReverseIndex(s, substr string) int

ReverseIndex returns the `Index` after reversing the supplied string and substring.

func Slice2FilterLinesHaveIndex

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

func SliceBySplitLength added in v0.32.0

func SliceBySplitLength(slice []string, sep string) map[int][]string

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

func SliceChooseOnePreferredLowerTrimSpace

func SliceChooseOnePreferredLowerTrimSpace(options, preferenceOrder []string) string

func SliceCondenseAndQuote

func SliceCondenseAndQuote(items []string, trimLeft, trimRight, quoteLeft, quoteRight string) []string

func SliceCondenseAndQuoteSpace

func SliceCondenseAndQuoteSpace(items []string, quoteLeft, quoteRight string) []string

func SliceCondensePunctuation

func SliceCondensePunctuation(texts []string) []string

func SliceCondenseRegexps

func SliceCondenseRegexps(texts []string, regexps []*regexp.Regexp, replacement string) []string

func SliceCondenseSpace

func SliceCondenseSpace(lines []string, dedupeResults, sortResults bool) []string

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

func SliceIndex

func SliceIndex(haystack []string, needle string) int

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

func SliceIndexMore added in v0.30.10

func SliceIndexMore(haystack []string, needle string, trimSpace, toLower bool, matchType MatchType) int

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

func SliceIndexOrEmpty

func SliceIndexOrEmpty(s []string, index uint64) string

SliceIndexOrEmpty returns the element at the index provided or an empty string.

func SliceIntersection

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

func SliceIntersectionCondenseSpace

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

func SliceIsEmpty added in v0.0.21

func SliceIsEmpty(slice []string, skipEmptyStrings bool) bool

SliceIsEmpty 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 SliceLineHasIndex

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

func SliceSplitLengthStats added in v0.32.0

func SliceSplitLengthStats(slice []string, sep string) map[int]int

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

func SliceSubtract

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

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

func SliceToMap

func SliceToMap(strs []string) map[string]int

func SliceToSingleIntOrNeg

func SliceToSingleIntOrNeg(vals []string) int

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

func SliceTrim

func SliceTrim(lines []string, cutstr string, condense bool) []string

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

func SliceTrimSpace

func SliceTrimSpace(s []string) []string

SliceTrimSpace removes leading and trailing spaces per string.

func SlicesCompare added in v0.26.5

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

SlicesCompare 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 SplitCondenseSpace

func SplitCondenseSpace(s, sep string) []string

SplitCondenseSpace splits a string and trims spaces on remaining elements, removing empty elements.

func SplitLines added in v0.0.11

func SplitLines(s string) []string

func SplitTextLines

func SplitTextLines(text string) []string

SplitTextLines splits a string on the regxp `(\r\n|\r|\n)`.

func SplitTrimSpace

func SplitTrimSpace(s, sep string) []string

SplitTrimSpace splits a string and trims spaces on remaining elements.

func StringToConstant

func StringToConstant(s string) string

StringToConstant is used to generate constant names for code generation. It uses the commonInitialisms in Go Lint.

func StripControl

func StripControl(s string) string

func SubstringIsSuffix

func SubstringIsSuffix(s1, s2 string) bool

func SuffixMap added in v0.0.5

func SuffixMap(inputs, suffixes []string) (prefixes []string, matches map[string]string, nonmatches []string)

func ToBool

func ToBool(v string) bool

ToBool converts a string to a boolean value converting "f", "false", "0" and the empty string to false with everything else being true.

func ToLineFeeds added in v0.0.11

func ToLineFeeds(s string) string

func ToLowerFirst

func ToLowerFirst(s1 string) string

ToLowerFirst lower cases the first letter in the string

func ToOpposite

func ToOpposite(s string) string

func ToUpperFirst

func ToUpperFirst(s1 string, lowerRest bool) string

ToUpperFirst upper cases the first letter in the string

func TrimSentenceLength

func TrimSentenceLength(sentenceInput string, maxLength int) string

TrimSentenceLength trims a string by a max length at word boundaries.

func TrimSpaceOrDefault added in v0.0.4

func TrimSpaceOrDefault(str, defaultValue string) string

TrimSpaceOrDefault trims spaces and replaces default value if result is empty string.

func Unshift

func Unshift(a []string, x string) []string

Unshift adds an element at the first position of the slice.

func UrlToMarkdownLinkHostname

func UrlToMarkdownLinkHostname(url string) string

Types

type MatchInfo

type MatchInfo struct {
	MatchType  MatchType
	String     string
	Regexp     *regexp.Regexp
	TimeLayout string
	TimeMin    time.Time
	TimeMax    time.Time
}

type MatchType

type MatchType int
const (
	MatchExact MatchType = iota
	MatchTrimSpace
	MatchTrimSpaceLower
	MatchRegexp
	MatchTimeGT
	MatchTimeGTE
	MatchTimeLT
	MatchTimeLTE
	MatchHasSuffix
	MatchHasPrefix
)

type Quoter

type Quoter struct {
	Beg string
	End string
}

func (Quoter) Quote

func (qtr Quoter) Quote(input string) string

type StrUtil

type StrUtil struct {
	RxSpaceBeg   *regexp.Regexp
	RxSpaceEnd   *regexp.Regexp
	RxSpacePunct *regexp.Regexp
	RxDash       *regexp.Regexp
}

func NewStrUtil

func NewStrUtil() StrUtil

func (*StrUtil) Trim

func (str *StrUtil) Trim(bytes []byte) []byte

type StringSlice

type StringSlice []string

func (StringSlice) Exists

func (sx StringSlice) Exists(s string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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