stringsutil

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 8 Imported by: 2

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 CommonInitialismsMap

func CommonInitialismsMap() map[string]bool

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

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 CondenseStringSimple

func CondenseStringSimple(s string) string

CondenseStringSimple removes extra spaces.

func Dedupe

func Dedupe(vals []string) []string

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

func DigitsOnly added in v1.1.0

func DigitsOnly(input string) string

func Equal added in v1.1.0

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

func FormatString

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

func InterfaceToSliceString

func InterfaceToSliceString(s interface{}) []string

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 added in v1.0.2

func Quote(str, beg, end string) string

func RemoveSpaces

func RemoveSpaces(input string) string

RemoveSpaces eliminates all spaces in a string.

func Slice2FilterLinesHaveIndex

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

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, trimSpace, toLower bool, matchType MatchType) int

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

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

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(lines []string, condense bool) []string

SliceTrimSpace removes leading and trailing spaces per string and optionally removes empty strings.

func SplitCondenseSpace

func SplitCondenseSpace(s, sep string) []string

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

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 ToBool

func ToBool(v string) bool

ToBool converts a string to a boolean value looking for the string "true" in any case.

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 TrimSpaceWithDefault added in v1.3.0

func TrimSpaceWithDefault(str string, defaultValue string) string

TrimSpaceWithDefault 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 added in v1.0.2

type Quoter struct {
	Beg string
	End string
}

func (Quoter) Quote added in v1.0.2

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 added in v1.3.0

type StringSlice []string

func (StringSlice) Exists added in v1.3.0

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