strutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTrimChars are the characters which are stripped by Trim* functions in default.
	DefaultTrimChars = string([]byte{
		'\t',
		'\v',
		'\n',
		'\r',
		'\f',
		' ',
		0x00,
		0x85,
		0xA0,
	})
)

Functions

func After

func After(s, char string) string

After returns the substring after the first occurrence of a specified string in the source string.

func AfterLast

func AfterLast(s, char string) string

AfterLast returns the substring after the last occurrence of a specified string in the source string.

func Before

func Before(s, char string) string

Before returns the substring of the source string up to the first occurrence of the specified string.

func BeforeLast

func BeforeLast(s, char string) string

BeforeLast returns the substring of the source string up to the last occurrence of the specified string.

func BytesToString

func BytesToString(bytes []byte) string

BytesToString converts a byte slice to string without a memory allocation.

func CamelCase

func CamelCase(s string) string

CamelCase coverts string to camelCase string. Non letters and numbers will be ignored.

func Capitalize

func Capitalize(s string) string

Capitalize converts the first character of a string to upper case and the remaining to lower case.

func ContainsAll

func ContainsAll(str string, substrs []string) bool

ContainsAll return true if target string contains all the substrs.

func ContainsAny

func ContainsAny(str string, substrs []string) bool

ContainsAny return true if target string contains any one of the substrs.

func HasPrefixAny

func HasPrefixAny(str string, prefixes []string) bool

HasPrefixAny check if a string starts with any of a slice of specified strings.

func HasSuffixAny

func HasSuffixAny(str string, suffixes []string) bool

HasSuffixAny check if a string ends with any of a slice of specified strings.

func HideString

func HideString(origin string, start, end int, replaceChar string) string

HideString hide some chars in source string with param `replaceChar`. replace range is origin[start : end]. [start, end)

func IndexOffset

func IndexOffset(str string, substr string, idxFrom int) int

IndexOffset returns the index of the first instance of substr in string after offsetting the string by `idxFrom`, or -1 if substr is not present in string.

func IsBlank

func IsBlank(str string) bool

IsBlank checks if a string is whitespace, empty.

func IsEmpty

func IsEmpty(val string) bool

func IsString

func IsString(v any) bool

IsString check if the value data type is string or not.

func KebabCase

func KebabCase(s string) string

KebabCase coverts string to kebab-case, non letters and numbers will be ignored.

func LowerFirst

func LowerFirst(s string) string

LowerFirst converts the first character of string to lower case.

func Pad

func Pad(source string, size int, padStr string) string

Pad pads string on the left and right side if it's shorter than size. Padding characters are truncated if they exceed size.

func PadEnd

func PadEnd(source string, size int, padStr string) string

PadEnd pads string on the right side if it's shorter than size. Padding characters are truncated if they exceed size.

func PadStart

func PadStart(source string, size int, padStr string) string

PadStart pads string on the left side if it's shorter than size. Padding characters are truncated if they exceed size.

func RemoveNonPrintable

func RemoveNonPrintable(str string) string

RemoveNonPrintable remove non-printable characters from a string.

func RemovePrefix

func RemovePrefix(s string, prefix string) string

func RemoveSuffix

func RemoveSuffix(s string, suffix string) string

func RemoveWhiteSpace

func RemoveWhiteSpace(str string, repalceAll bool) string

RemoveWhiteSpace remove whitespace characters from a string. when set repalceAll is true removes all whitespace, false only replaces consecutive whitespace characters with one space.

func ReplaceWithMap

func ReplaceWithMap(str string, replaces map[string]string) string

ReplaceWithMap returns a copy of `str`, which is replaced by a map in unordered way, case-sensitively.

func Reverse

func Reverse(s string) string

Reverse returns string whose char order is reversed to the given string.

func SetPrefix

func SetPrefix(s string, prefix string) string

func SetSuffix

func SetSuffix(s string, suffix string) string

func SnakeCase

func SnakeCase(s string) string

SnakeCase coverts string to snake_case, non letters and numbers will be ignored

func SplitAndTrim

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim splits string `str` by a string `delimiter` to a slice, and calls Trim to every element of this slice. It ignores the elements which are empty after Trim.

func SplitEx

func SplitEx(s, sep string, removeEmptyString bool) []string

SplitEx split a given string which can control the result slice contains empty string or not.

func SplitWords

func SplitWords(s string) []string

SplitWords splits a string into words, word only contains alphabetic characters.

func StringToBytes

func StringToBytes(str string) (b []byte)

StringToBytes converts a string to byte slice without a memory allocation.

func Substring

func Substring(s string, offset int, length uint) string

Substring returns a substring of the specified length starting at the specified offset position.

func Trim

func Trim(str string, characterMask ...string) string

Trim strips whitespace (or other characters) from the beginning and end of a string. The optional parameter `characterMask` specifies the additional stripped characters.

func Unwrap

func Unwrap(str string, wrapToken string) string

Unwrap a given string from anther string. will change source string.

func UpperFirst

func UpperFirst(s string) string

UpperFirst converts the first character of string to upper case.

func UpperKebabCase

func UpperKebabCase(s string) string

UpperKebabCase coverts string to upper KEBAB-CASE, non letters and numbers will be ignored

func UpperSnakeCase

func UpperSnakeCase(s string) string

UpperSnakeCase coverts string to upper SNAKE_CASE, non letters and numbers will be ignored

func Utf8StringLength

func Utf8StringLength(str string) int

func Utf8TruncateText

func Utf8TruncateText(text string, max int, omission string) string

func WordCount

func WordCount(s string) int

WordCount return the number of meaningful word, word only contains alphabetic characters.

func Wrap

func Wrap(str string, wrapWith string) string

Wrap a string with given string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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