stringsutil

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 6 Imported by: 482

README

stringsutil

The package contains various helpers to interact with strings

Documentation

Index

Constants

This section is empty.

Variables

Functions

func After

func After(value string, a string) (string, error)

After extracts the string after a from value returns value as is and error if a is not found

func Before

func Before(value string, a string) (string, error)

Before extracts the string before a from value returns value as is and error if a is not found

func Between

func Between(value string, a string, b string) (string, error)

Between extracts the string between a and b returns value as is and error if a or b are not found

func ContainsAny

func ContainsAny(s string, ss ...string) bool

ContainsAny returns true if s contains any specified substring.

func ContainsAnyI added in v0.0.17

func ContainsAnyI(s string, ss ...string) bool

ContainsAnyI returns true if s contains any specified substring (case-insensitive).

func EqualFoldAny

func EqualFoldAny(s string, ss ...string) bool

EqualFoldAny returns true if s is equal to any specified substring

func HasPrefixAny

func HasPrefixAny(s string, prefixes ...string) bool

HasPrefixAny checks if the string starts with any specified prefix

func HasPrefixAnyI added in v0.0.52

func HasPrefixAnyI(s string, prefixes ...string) bool

HasPrefixAnyI is case insensitive HasPrefixAny

func HasPrefixI

func HasPrefixI(s, prefix string) bool

HasPrefixI is case insensitive HasPrefix

func HasSuffixAny

func HasSuffixAny(s string, suffixes ...string) bool

HasSuffixAny checks if the string ends with any specified suffix

func HasSuffixI

func HasSuffixI(s, suffix string) bool

HasSuffixI is case insensitive HasSuffix

func IndexAny added in v0.0.22

func IndexAny(s string, seps ...string) (int, string)

IndexAny returns the index of the first instance of any of the specified substrings in s, or -1 if s does not contain any of the substrings.

func IndexAt

func IndexAt(s, sep string, n int) int

IndexAt look for a substring starting at position x

func IsCTRLC added in v0.0.17

func IsCTRLC(s string) bool

IsCTRLC checks if the string is CTRL+C

func IsPrintable added in v0.0.17

func IsPrintable(s string) bool

IsPrintable checks if the strings is made only of printable characters

func Join

func Join(elems []interface{}, sep string) string

Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.

func Normalize

func Normalize(data string) string

func NormalizeWithOptions

func NormalizeWithOptions(data string, options NormalizeOptions) string

func ReplaceAll

func ReplaceAll(s, new string, olds ...string) string

ReplaceAll returns a copy of the string s with all instances of old incrementally replaced by new.

func Reverse

func Reverse(s string) string

Reverse the string

func SlideWithLength

func SlideWithLength(s string, l int) chan string

SlideWithLength returns all the strings of the specified length while moving forward the extraction window

func SplitAny

func SplitAny(s string, seps ...string) []string

SplitAny string by a list of separators

func TrimPrefixAny

func TrimPrefixAny(s string, prefixes ...string) string

TrimPrefixAny trims all prefixes from string in order

func TrimSuffixAny

func TrimSuffixAny(s string, suffixes ...string) string

TrimSuffixAny trims all suffixes from string in order

func Truncate added in v0.0.10

func Truncate(data string, maxSize int) string

Truncate a string to max length

Types

type EncodingType

type EncodingType uint8
const (
	Unknown EncodingType = iota
	UTF8
	UTF16BE
	UTF16LE
	UTF32BE
	UTF32LE
	ISO85591
	ISO88592
	ISO88595
	ISO88596
	ISO88597
	ISO88598
	Windows1251
	Windows1256
	KOI8R
	ShiftJIS
	GB18030
	EUCJP
	EUCKR
	Big5
	ISO2022JP
	ISO2022KR
	ISO2022CN
	IBM424rtl
	IBM424ltr
	IBM420rtl
	IBM420ltr
)

func DetectEncodingType

func DetectEncodingType(data interface{}) (EncodingType, error)

type LongestSequence added in v0.0.4

type LongestSequence struct {
	Sequence string
	Count    int
}

func LongestRepeatingSequence added in v0.0.4

func LongestRepeatingSequence(s string) LongestSequence

LongestRepeatingSequence finds the longest repeating non-overlapping sequence in a string

type NormalizeOptions

type NormalizeOptions struct {
	TrimSpaces bool
	StripHTML  bool
	Lowercase  bool
	Uppercase  bool
}
var DefaultNormalizeOptions NormalizeOptions = NormalizeOptions{
	TrimSpaces: true,
	StripHTML:  true,
}

Jump to

Keyboard shortcuts

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