gstr

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gstr provides functions for string handling.

Index

Constants

View Source
const (
	// NotFoundIndex is the position index for string not found in searching functions.
	NotFoundIndex = -1
)

Variables

This section is empty.

Functions

func AddSlashes

func AddSlashes(str string) string

AddSlashes quotes chars('"\) with slashes.

func CaseCamel added in v0.9.8

func CaseCamel(s string) string

CaseCamel converts a string to CamelCase.

func CaseCamelLower added in v0.9.8

func CaseCamelLower(s string) string

CaseCamelLower converts a string to lowerCamelCase.

func CaseDelimited added in v0.9.8

func CaseDelimited(s string, del byte) string

CaseDelimited converts a string to snake.case.delimited.

func CaseDelimitedScreaming added in v0.9.8

func CaseDelimitedScreaming(s string, del uint8, screaming bool) string

CaseDelimitedScreaming converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case.

func CaseKebab added in v0.9.8

func CaseKebab(s string) string

CaseKebab converts a string to kebab-case

func CaseKebabScreaming added in v0.9.8

func CaseKebabScreaming(s string) string

CaseKebabScreaming converts a string to KEBAB-CASE-SCREAMING.

func CaseSnake added in v0.9.8

func CaseSnake(s string) string

CaseSnake converts a string to snake_case.

func CaseSnakeFirstUpper added in v0.9.8

func CaseSnakeFirstUpper(word string, underscore ...string) string

CaseSnakeFirstUpper converts a string like "RGBCodeMd5" to "rgb_code_md5". TODO for efficiency should change regexp to traversing string in future.

func CaseSnakeScreaming added in v0.9.8

func CaseSnakeScreaming(s string) string

CaseSnakeScreaming converts a string to SNAKE_CASE_SCREAMING.

func Contains

func Contains(str, substr string) bool

Contains reports whether `substr` is within `str`, case-sensitively.

func ContainsAny

func ContainsAny(s, chars string) bool

ContainsAny reports whether any Unicode code points in `chars` are within `s`.

func ContainsI

func ContainsI(str, substr string) bool

ContainsI reports whether substr is within str, case-insensitively.

func HasPrefix

func HasPrefix(s, prefix string) bool

HasPrefix tests whether the string s begins with prefix.

func HasSuffix

func HasSuffix(s, suffix string) bool

HasSuffix tests whether the string s ends with suffix.

func IsLetterLower added in v0.9.8

func IsLetterLower(b byte) bool

IsLetterLower checks whether the given byte b is in lower case.

func IsLetterUpper added in v0.9.8

func IsLetterUpper(b byte) bool

IsLetterUpper checks whether the given byte b is in upper case.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric tests whether the given string s is numeric.

func LcFirst added in v0.9.8

func LcFirst(s string) string

LcFirst returns a copy of the string s with the first letter mapped to its lower case.

func Pos

func Pos(haystack, needle string, startOffset ...int) int

Pos returns the position of the first occurrence of `needle` in `haystack` from `startOffset`, case-sensitively. It returns -1, if not found.

func PosI

func PosI(haystack, needle string, startOffset ...int) int

PosI returns the position of the first occurrence of `needle` in `haystack` from `startOffset`, case-insensitively. It returns -1, if not found.

func PosIRune

func PosIRune(haystack, needle string, startOffset ...int) int

PosIRune acts like function PosI but considers `haystack` and `needle` as unicode string.

func PosR

func PosR(haystack, needle string, startOffset ...int) int

PosR returns the position of the last occurrence of `needle` in `haystack` from `startOffset`, case-sensitively. It returns -1, if not found.

func PosRI

func PosRI(haystack, needle string, startOffset ...int) int

PosRI returns the position of the last occurrence of `needle` in `haystack` from `startOffset`, case-insensitively. It returns -1, if not found.

func PosRIRune

func PosRIRune(haystack, needle string, startOffset ...int) int

PosRIRune acts like function PosRI but considers `haystack` and `needle` as unicode string.

func PosRRune

func PosRRune(haystack, needle string, startOffset ...int) int

PosRRune acts like function PosR but considers `haystack` and `needle` as unicode string.

func PosRune

func PosRune(haystack, needle string, startOffset ...int) int

PosRune acts like function Pos but considers `haystack` and `needle` as unicode string.

func QuoteMeta

func QuoteMeta(str string, chars ...string) string

QuoteMeta returns a version of str with a backslash character (\) before every character that is among: .\+*?[^]($)

func Replace

func Replace(origin, search, replace string, count ...int) string

Replace returns a copy of the string `origin` in which string `search` replaced by `replace` case-sensitively.

func ReplaceByArray

func ReplaceByArray(origin string, array []string) string

ReplaceByArray returns a copy of `origin`, which is replaced by a slice in order, case-sensitively.

func ReplaceByMap

func ReplaceByMap(origin string, replaces map[string]string) string

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

func ReplaceI

func ReplaceI(origin, search, replace string, count ...int) string

ReplaceI returns a copy of the string `origin` in which string `search` replaced by `replace` case-insensitively.

func ReplaceIByArray

func ReplaceIByArray(origin string, array []string) string

ReplaceIByArray returns a copy of `origin`, which is replaced by a slice in order, case-insensitively.

func ReplaceIByMap

func ReplaceIByMap(origin string, replaces map[string]string) string

ReplaceIByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-insensitively.

func StripSlashes

func StripSlashes(str string) string

StripSlashes un-quotes a quoted string by AddSlashes.

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 TrimAll

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

TrimAll trims all characters in string `str`.

func TrimLeft

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

TrimLeft strips whitespace (or other characters) from the beginning of a string.

func TrimLeftStr

func TrimLeftStr(str string, cut string, count ...int) string

TrimLeftStr strips all the given `cut` string from the beginning of a string. Note that it does not strip the whitespaces of its beginning.

func TrimRight

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

TrimRight strips whitespace (or other characters) from the end of a string.

func TrimRightStr

func TrimRightStr(str string, cut string, count ...int) string

TrimRightStr strips all the given `cut` string from the end of a string. Note that it does not strip the whitespaces of its end.

func TrimStr

func TrimStr(str string, cut string, count ...int) string

TrimStr strips all the given `cut` string from the beginning and end of a string. Note that it does not strip the whitespaces of its beginning or end.

func UcFirst added in v0.9.8

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

Types

This section is empty.

Jump to

Keyboard shortcuts

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