xstring

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecodeChar error occurred on char decoding
	ErrDecodeChar = errors.New("error occurred on char decoding")
)

Functions

func Abbreviate

func Abbreviate(str, abbrevMarker string, offset, maxWidth int) (string, error)

Abbreviate abbreviates a string using ellipses or another given string.

func CommonPrefix

func CommonPrefix(strings ...string) string

CommonPrefix returns common prefix.

func Contains

func Contains(s string, searchChar string) bool

Contains reports whether substr is within s.

func ContainsAnySubstrings

func ContainsAnySubstrings(s string, subs []string) bool

ContainsAnySubstrings returns whether s contains any of substring in slice.

func ContainsIgnoreCase

func ContainsIgnoreCase(str, searchStr string) bool

ContainsIgnoreCase checks if string contains a search string irrespective of case.

func DefaultIfBlank

func DefaultIfBlank(str, defaultStr string) string

DefaultIfBlank returns default String if str is blank.

func DefaultIfEmpty

func DefaultIfEmpty(str, defaultStr string) string

DefaultIfEmpty returns default String if str is empty.

func DeleteWhitespace

func DeleteWhitespace(str string) string

DeleteWhitespace deletes whitespace.

func Difference

func Difference(a, b string) string

Difference Compares two Strings, and returns the portion where they differ. More precisely, return the remainder of the second String, starting from where it's different from the first. This means that the difference between "abc" and "ab" is the empty String and not "c".

func EndsWith

func EndsWith(str, suffix string, ignoreCase bool) bool

EndsWith returns true if the str

func EndsWithAny

func EndsWithAny(sequence string, searchStrings ...string) bool

EndsWithAny check if a sequence ends with any of an array of specified strings.

func EndsWithCase

func EndsWithCase(str, suffix string) bool

EndsWithCase case-insensitive check if a str ends with a specified suffix.

func EndsWithIgnoreCase

func EndsWithIgnoreCase(str, suffix string) bool

EndsWithIgnoreCase case-insensitive check if a str ends with a specified suffix.

func EqualsAny

func EqualsAny(str1 string, strings ...string) bool

EqualsAny returns ture if str exists in strings.

func EqualsIgnoreCase added in v0.1.2

func EqualsIgnoreCase(str1, str2 string) bool

EqualsIgnoreCase returns true if the two strings are equal ignoring case.

func Index

func Index(s, substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

func IndexAny

func IndexAny(s, chars string) int

IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func IndexOfDifference

func IndexOfDifference(strings ...string) int

IndexOfDifference compares all strings in an array and returns the index at which the

string begin to differ.

func IndexOfDifferenceWithTwoStr

func IndexOfDifferenceWithTwoStr(a, b string) int

IndexOfDifferenceWithTwoStr Compares two string, and returns the index at which the string begin to differ.

func IsAlpha

func IsAlpha(s string) bool

IsAlpha checks if the string contains only unicode letters.

func IsAlphanumeric

func IsAlphanumeric(s string) bool

IsAlphanumeric checks if the string contains only Unicode letters or digits.

func IsAnyBlank

func IsAnyBlank(strings ...string) bool

IsAnyBlank returns true if there is a blank string in strings.

func IsAnyEmpty

func IsAnyEmpty(strings ...string) bool

IsAnyEmpty returns ture if strings exist empty of string.

func IsBlank

func IsBlank(s string) bool

IsBlank returns ture if the string is empty or has a length of 0 or consists of whitespace.

func IsEmpty

func IsEmpty(s string) bool

IsEmpty returns ture if s is empty.

func IsNoneBlank

func IsNoneBlank(strings ...string) bool

IsNoneBlank returns true if there is no blank string in strings.

func IsNoneEmpty

func IsNoneEmpty(strings ...string) bool

IsNoneEmpty returns false if strings exist empty of string.

func IsNotBlank

func IsNotBlank(s string) bool

IsNotBlank returns false if the string is empty or has a length of 0 or consists of whitespace.

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty returns ture if s isn't empty.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks if the string contains only digits. A decimal point is not a digit and returns false.

func IsNumerical

func IsNumerical(s string) bool

IsNumerical returns ture if a numerical.

func Left

func Left(s string, end int) string

Left returns substring from specified string avoiding panics with start. start, end are based on unicode(utf8) count.

func Len

func Len(str string) int

Len returns str length.

func MustReverse

func MustReverse(s string) string

MustReverse reverses a string, panics when error happens.

func PadCenterChar

func PadCenterChar(s string, size int, ch Char) string

PadCenterChar center pad a string with a specified character in a larger string(specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func PadCenterSpace

func PadCenterSpace(s string, size int) string

PadCenterSpace center pad a string with space character(' ') in a larger string(specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func PadLeftChar

func PadLeftChar(s string, size int, ch Char) string

PadLeftChar left pad a string with a specified character in a larger string (specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func PadLeftSpace

func PadLeftSpace(s string, size int) string

PadLeftSpace left pad a string with space character(' ') in a larger string(specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func PadRightChar

func PadRightChar(s string, size int, ch Char) string

PadRightChar right pad a string with a specified character in a larger string(specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func PadRightSpace

func PadRightSpace(s string, size int) string

PadRightSpace right pad a string with space character(' ') in a large string(specified size). if the size is less than the param string, the param string is returned. NOTE: size is unicode size.

func RegionMatches

func RegionMatches(str string, ignoreCase bool, thisStart int, substr string, start int, length int) bool

RegionMatches Green implementation of regionMatches.

func RemoveChar

func RemoveChar(s string, rmVal Char) string

RemoveChar removes all occurrences of a specified character from the string.

func RemoveString

func RemoveString(s, rmStr string) string

RemoveString removes all occurrences of a substring from the string.

func RepeatChar

func RepeatChar(ch Char, repeat int) string

RepeatChar returns padding using the specified delimiter repeated to a given length.

func Reverse

func Reverse(s string) (string, error)

Reverse reverses a string with error status returned.

func Right(s string, start int) string

Right returns substring from specified string avoiding panics with end. start, end are based on unicode(utf8) count.

func Rotate

func Rotate(s string, shift int) string

Rotate rotates(circular shift) a string of shift characters.

func Shuffle

func Shuffle(s string) string

Shuffle shuffles runes in a string and returns.

func Sub

func Sub(s string, start, end int) string

Sub returns substring from specified string avoiding panics with index start and end. start, end are based on unicode(utf8) count.

func Trim

func Trim(s string, cutSet string) string

Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutSet removed.

func TrimLeft

func TrimLeft(str string, stripStr string) string

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

To remove a prefix, use TrimPrefix instead.

func TrimRight

func TrimRight(str string, stripStr string) string

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

To remove a suffix, use TrimSuffix instead.

func TrimSpace

func TrimSpace(s string) string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

Types

type Char

type Char = rune

Char is rune Alias.

type Joiner added in v0.1.3

type Joiner struct {
	// contains filtered or unexported fields
}

Joiner is used to construct a sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.

func NewJoiner added in v0.1.3

func NewJoiner(opts ...JoinerOption) *Joiner

NewJoiner returns a Joiner.

func (*Joiner) Cap added in v0.1.3

func (j *Joiner) Cap() int

Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.

func (*Joiner) Grow added in v0.1.3

func (j *Joiner) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*Joiner) Len added in v0.1.3

func (j *Joiner) Len() int

Len returns the len of accumulated string.

func (*Joiner) Reset added in v0.1.3

func (j *Joiner) Reset()

Reset resets the Builder to be empty.

func (*Joiner) String added in v0.1.3

func (j *Joiner) String() string

String returns the accumulated string.

func (*Joiner) Write added in v0.1.3

func (j *Joiner) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*Joiner) WriteByte added in v0.1.3

func (j *Joiner) WriteByte(b byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*Joiner) WriteRune added in v0.1.3

func (j *Joiner) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*Joiner) WriteString added in v0.1.3

func (j *Joiner) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

type JoinerOption added in v0.1.3

type JoinerOption func(*joinerOptions)

JoinerOption option function of Joiner.

func WithJoiner added in v0.1.3

func WithJoiner(prefix, step, suffix string) JoinerOption

WithJoiner returns a JoinerOption with prefix, step and suffix settings.

func WithJoinerPrefix added in v0.1.3

func WithJoinerPrefix(prefix string) JoinerOption

WithJoinerPrefix returns a JoinerOption with prefix settings.

func WithJoinerStep added in v0.1.3

func WithJoinerStep(step string) JoinerOption

WithJoinerStep returns a JoinerOption with step settings.

func WithJoinerSuffix added in v0.1.3

func WithJoinerSuffix(suffix string) JoinerOption

WithJoinerSuffix returns a JoinerOption with suffix settings.

Jump to

Keyboard shortcuts

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