Documentation ¶
Overview ¶
Package gstr provides functions for string handling.
Index ¶
- func AddSlashes(str string) string
- func CamelCase(s string) string
- func CamelLowerCase(s string) string
- func Chr(ascii int) string
- func ChunkSplit(body string, chunkLen int, end string) string
- func Compare(a, b string) int
- func CompareVersion(a, b string) int
- func Contains(str, substr string) bool
- func ContainsAny(s, chars string) bool
- func ContainsI(str, substr string) bool
- func Count(s, substr string) int
- func CountChars(str string, noSpace ...bool) map[string]int
- func CountI(s, substr string) int
- func CountWords(str string) map[string]int
- func DelimitedCase(s string, del uint8) string
- func DelimitedScreamingCase(s string, del uint8, screaming bool) string
- func Equal(a, b string) bool
- func Explode(delimiter, str string) []string
- func Fields(str string) []string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func HideStr(str string, percent int, hide string) string
- func Implode(glue string, pieces []string) string
- func InArray(a []string, s string) bool
- func IsLetterLower(b byte) bool
- func IsLetterUpper(b byte) bool
- func IsNumeric(s string) bool
- func IsSubDomain(subDomain string, mainDomain string) bool
- func Join(array []string, sep string) string
- func JoinAny(array interface{}, sep string) string
- func KebabCase(s string) string
- func KebabScreamingCase(s string) string
- func LcFirst(s string) string
- func LenRune(str string) int
- func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int
- func Nl2Br(str string, isXhtml ...bool) string
- func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string
- func OctStr(str string) string
- func Ord(char string) int
- func Parse(s string) (result map[string]interface{}, err error)
- func Pos(haystack, needle string, startOffset ...int) int
- func PosI(haystack, needle string, startOffset ...int) int
- func PosIRune(haystack, needle string, startOffset ...int) int
- func PosR(haystack, needle string, startOffset ...int) int
- func PosRI(haystack, needle string, startOffset ...int) int
- func PosRIRune(haystack, needle string, startOffset ...int) int
- func PosRRune(haystack, needle string, startOffset ...int) int
- func PosRune(haystack, needle string, startOffset ...int) int
- func QuoteMeta(str string, chars ...string) string
- func Repeat(input string, multiplier int) string
- func Replace(origin, search, replace string, count ...int) string
- func ReplaceByArray(origin string, array []string) string
- func ReplaceByMap(origin string, replaces map[string]string) string
- func ReplaceI(origin, search, replace string, count ...int) string
- func ReplaceIByArray(origin string, array []string) string
- func ReplaceIByMap(origin string, replaces map[string]string) string
- func Reverse(str string) string
- func RuneLen(str string) int
- func SearchArray(a []string, s string) int
- func Shuffle(str string) string
- func SimilarText(first, second string, percent *float64) int
- func SnakeCase(s string) string
- func SnakeScreamingCase(s string) string
- func Soundex(str string) string
- func Split(str, delimiter string) []string
- func SplitAndTrim(str, delimiter string, characterMask ...string) []string
- func SplitAndTrimSpace(str, delimiter string) []string
- func Str(haystack string, needle string) string
- func StrLimit(str string, length int, suffix ...string) string
- func StrLimitRune(str string, length int, suffix ...string) string
- func StripSlashes(str string) string
- func SubStr(str string, start int, length ...int) (substr string)
- func SubStrRune(str string, start int, length ...int) (substr string)
- func ToLower(s string) string
- func ToUpper(s string) string
- func Trim(str string, characterMask ...string) string
- func TrimLeft(str string, characterMask ...string) string
- func TrimLeftStr(str string, cut string) string
- func TrimRight(str string, characterMask ...string) string
- func TrimRightStr(str string, cut string) string
- func TrimStr(str string, cut string) string
- func UcFirst(s string) string
- func UcWords(str string) string
- func WordWrap(str string, width int, br string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelLowerCase ¶
CamelLowerCase converts a string to lowerCamelCase.
func ChunkSplit ¶
ChunkSplit splits a string into smaller chunks. Can be used to split a string into smaller chunks which is useful for e.g. converting BASE64 string output to match RFC 2045 semantics. It inserts end every chunkLen characters. It considers parameter <body> and <end> as unicode string.
func Compare ¶
Compare returns an integer comparing two strings lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func CompareVersion ¶
CompareVersion compares <a> and <b> as standard golang version. Golang standard version is as: 1.0.0, v1.0.1, v2.10.8, 10.2.0 etc.
func ContainsAny ¶
ContainsAny reports whether any Unicode code points in <chars> are within <s>.
func Count ¶
Count counts the number of <substr> appears in <s>. It returns 0 if no <substr> found in <s>.
func CountChars ¶
CountChars returns information about chars' count used in a string. It considers parameter <str> as unicode string.
func CountI ¶
CountI counts the number of <substr> appears in <s>, case-insensitively. It returns 0 if no <substr> found in <s>.
func CountWords ¶
CountWords returns information about words' count used in a string. It considers parameter <str> as unicode string.
func DelimitedCase ¶
DelimitedCase converts a string to snake.case.delimited.
func DelimitedScreamingCase ¶
DelimitedScreamingCase converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case.
func Equal ¶
Equal reports whether <a> and <b>, interpreted as UTF-8 strings, are equal under Unicode case-folding, case-insensitively.
func Explode ¶
Explode splits string <str> by a string <delimiter>, to an array. See http://php.net/manual/en/function.explode.php.
func HideStr ¶
HideStr replaces part of the the string <str> to <hide> by <percentage> from the <middle>. It considers parameter <str> as unicode string.
func Implode ¶
Implode joins array elements <pieces> with a string <glue>. http://php.net/manual/en/function.implode.php
func IsLetterLower ¶
IsLetterLower tests whether the given byte b is in lower case.
func IsLetterUpper ¶
IsLetterUpper tests whether the given byte b is in upper case.
func IsSubDomain ¶ added in v1.9.3
IsSubDomain checks whether <subDomain> is sub-domain of mainDomain. It supports '*' in <mainDomain>.
func Join ¶
Join concatenates the elements of <array> to create a single string. The separator string <sep> is placed between elements in the resulting string.
func JoinAny ¶
JoinAny concatenates the elements of <array> to create a single string. The separator string <sep> is placed between elements in the resulting string.
The parameter <array> can be any type of slice, which be converted to string array.
func KebabScreamingCase ¶
KebabScreamingCase converts a string to KEBAB-CASE-SCREAMING.
func LcFirst ¶
LcFirst returns a copy of the string s with the first letter mapped to its lower case.
func Levenshtein ¶
Levenshtein calculates Levenshtein distance between two strings. costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion. See http://php.net/manual/en/function.levenshtein.php.
func Nl2Br ¶
Nl2Br inserts HTML line breaks(<br>|<br />) before all newlines in a string: \n\r, \r\n, \r, \n. It considers parameter <str> as unicode string.
func NumberFormat ¶
NumberFormat formats a number with grouped thousands. <decimals>: Sets the number of decimal points. <decPoint>: Sets the separator for the decimal point. <thousandsSep>: Sets the thousands separator. See http://php.net/manual/en/function.number-format.php.
func OctStr ¶ added in v1.11.5
OctStr converts string container octal string to its original string, for example, to Chinese string. Eg: `\346\200\241` -> 怡
func Parse ¶
Parse parses the string into map[string]interface{}.
v1=m&v2=n -> map[v1:m v2:n] v[a]=m&v[b]=n -> map[v:map[a:m b:n]] v[a][a]=m&v[a][b]=n -> map[v:map[a:map[a:m b:n]]] v[]=m&v[]=n -> map[v:[m n]] v[a][]=m&v[a][]=n -> map[v:map[a:[m n]]] v[][]=m&v[][]=n -> map[v:[map[]]] // Currently does not support nested slice. v=m&v[a]=n -> error a .[[b=c -> map[a___[b:c]
func Pos ¶
Pos returns the position of the first occurrence of <needle> in <haystack> from <startOffset>, case-sensitively. It returns -1, if not found.
func PosI ¶
PosI returns the position of the first occurrence of <needle> in <haystack> from <startOffset>, case-insensitively. It returns -1, if not found.
func PosIRune ¶ added in v1.12.2
PosIRune acts like function PosI but considers <haystack> and <needle> as unicode string.
func PosR ¶
PosR returns the position of the last occurrence of <needle> in <haystack> from <startOffset>, case-sensitively. It returns -1, if not found.
func PosRI ¶
PosRI returns the position of the last occurrence of <needle> in <haystack> from <startOffset>, case-insensitively. It returns -1, if not found.
func PosRIRune ¶ added in v1.12.2
PosRIRune acts like function PosRI but considers <haystack> and <needle> as unicode string.
func PosRRune ¶ added in v1.12.2
PosRRune acts like function PosR but considers <haystack> and <needle> as unicode string.
func PosRune ¶ added in v1.12.2
PosRune acts like function Pos but considers <haystack> and <needle> as unicode string.
func QuoteMeta ¶
QuoteMeta returns a version of str with a backslash character (\) before every character that is among: .\+*?[^]($)
func Replace ¶
Replace returns a copy of the string <origin> in which string <search> replaced by <replace> case-sensitively.
func ReplaceByArray ¶
ReplaceByArray returns a copy of <origin>, which is replaced by a slice in order, case-sensitively.
func ReplaceByMap ¶
ReplaceByMap returns a copy of <origin>, which is replaced by a map in unordered way, case-sensitively.
func ReplaceI ¶
Replace returns a copy of the string <origin> in which string <search> replaced by <replace> case-insensitively.
func ReplaceIByArray ¶
ReplaceIByArray returns a copy of <origin>, which is replaced by a slice in order, case-insensitively.
func ReplaceIByMap ¶
ReplaceIByMap returns a copy of <origin>, which is replaced by a map in unordered way, case-insensitively.
func SearchArray ¶
SearchArray searches string <s> in string slice <a> case-sensitively, returns its index in <a>. If <s> is not found in <a>, it returns -1.
func SimilarText ¶
SimilarText calculates the similarity between two strings. See http://php.net/manual/en/function.similar-text.php.
func SnakeScreamingCase ¶
SnakeScreamingCase converts a string to SNAKE_CASE_SCREAMING.
func Soundex ¶
Soundex calculates the soundex key of a string. See http://php.net/manual/en/function.soundex.php.
func SplitAndTrim ¶
SplitAndTrim splits string <str> by a string <delimiter> to an array, and calls Trim to every element of this array. It ignores the elements which are empty after Trim.
func SplitAndTrimSpace ¶
SplitAndTrimSpace splits string <str> by a string <delimiter> to an array, and calls TrimSpace to every element of this array. Deprecated.
func Str ¶
Str returns part of <haystack> string starting from and including the first occurrence of <needle> to the end of <haystack>. See http://php.net/manual/en/function.strstr.php.
func StrLimit ¶
StrLimit returns a portion of string <str> specified by <length> parameters, if the length of <str> is greater than <length>, then the <suffix> will be appended to the result string.
func StrLimitRune ¶ added in v1.12.2
StrLimitRune returns a portion of string <str> specified by <length> parameters, if the length of <str> is greater than <length>, then the <suffix> will be appended to the result string. StrLimitRune considers parameter <str> as unicode string.
func StripSlashes ¶
StripSlashes un-quotes a quoted string by AddSlashes.
func SubStr ¶
SubStr returns a portion of string <str> specified by the <start> and <length> parameters.
func SubStrRune ¶ added in v1.12.2
SubStrRune returns a portion of string <str> specified by the <start> and <length> parameters. SubStrRune considers parameter <str> as unicode string.
func ToLower ¶
ToLower returns a copy of the string s with all Unicode letters mapped to their lower case.
func ToUpper ¶
ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case.
func Trim ¶
Trim strips whitespace (or other characters) from the beginning and end of a string. The optional parameter <characterMask> specifies the additional stripped characters.
func TrimLeftStr ¶
TrimLeftStr strips all of the given <cut> string from the beginning of a string. Note that it does not strips the whitespaces of its beginning.
func TrimRightStr ¶
TrimRightStr strips all of the given <cut> string from the end of a string. Note that it does not strips the whitespaces of its end.
func TrimStr ¶ added in v1.9.10
TrimStr strips all of the given <cut> string from the beginning and end of a string. Note that it does not strips the whitespaces of its beginning or end.
func UcFirst ¶
UcFirst returns a copy of the string s with the first letter mapped to its upper case.
Types ¶
This section is empty.