Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Index your code
hub
/
github.com/huandu/xstrings
/ functions
Functions
78 in github.com/huandu/xstrings
⨍
Functions
78
◇
Types & classes
8
↓ 130 callers
Function
sep
(strs ...string)
util_test.go:27
↓ 29 callers
Function
runTestCases
(t *testing.T, converter func(string) string, cases map[string]string)
util_test.go:17
↓ 9 callers
Function
nextValidRune
(str string, prev rune)
convert.go:400
↓ 8 callers
Function
isAlphabet
Checks r is a letter but not CJK character.
count.go:52
↓ 8 callers
Function
isConnector
(r rune)
convert.go:234
↓ 7 callers
Function
Len
Len returns str's utf8 rune length.
count.go:12
↓ 7 callers
Function
toLower
(buf *stringBuilder, wt wordType, str string, connector rune)
convert.go:418
↓ 5 callers
Function
nextWord
(str string)
convert.go:250
↓ 4 callers
Function
NewTranslator
NewTranslator creates new Translator through a from/to pattern pair.
translate.go:37
↓ 4 callers
Method
addRune
(from, to rune, singleRunes []rune)
translate.go:174
↓ 4 callers
Function
nextRuneRange
(str string, last rune)
translate.go:228
↓ 4 callers
Function
writePadString
(output *stringBuilder, pad string, padLen, remains int)
format.go:154
↓ 3 callers
Function
RuneWidth
RuneWidth returns character width in monotype font. Multi-byte characters are usually twice the width of single byte characters. Algorithm comes from
count.go:101
↓ 3 callers
Function
Slice
Slice a string by rune. Start must satisfy 0 <= start <= rune length. End can be positive, zero or negative. If end >= 0, start and end must satisfy
manipulate.go:38
↓ 3 callers
Method
TranslateRune
TranslateRune return translated rune and true if r matches the from pattern. If r doesn't match the pattern, original r is returned and translated is
translate.go:332
↓ 3 callers
Method
addRuneRange
(fromLo, fromHi, toLo, toHi rune, singleRunes []rune)
translate.go:193
↓ 3 callers
Function
allocBuffer
Lazy initialize a buffer.
common.go:9
↓ 3 callers
Function
split
(str string)
util_test.go:31
↓ 2 callers
Method
Translate
Translate str with a from/to pattern pair. See comment in Translate function for usage and samples.
translate.go:294
↓ 2 callers
Function
camelCaseToLowerCase
(str string, connector rune)
convert.go:151
↓ 2 callers
Function
toCamelCase
(str string, isBig bool)
convert.go:40
↓ 1 callers
Function
Center
Center returns a string with pad string at both side if str's rune length is smaller than length. If str's rune length is larger than length, str itse
format.go:136
↓ 1 callers
Function
Count
Count how many runes in str match the pattern. Pattern is defined in Translate function. Samples: Count("hello", "aeiou") => 3 Count("hello", "a-k
translate.go:471
↓ 1 callers
Function
Delete
Delete runes in str matching the pattern. Pattern is defined in Translate function. Samples: Delete("hello", "aeiou") => "hll" Delete("hello", "a-
translate.go:458
↓ 1 callers
Function
ExpandTabs
ExpandTabs can expand tabs ('\t') rune in str to one or more spaces dpending on current column and tabSize. The column number is reset to zero after e
format.go:24
↓ 1 callers
Function
Insert
Insert src into dst at given rune index. Index is counted by runes instead of bytes. If index is out of range of dst, panic with out of range.
manipulate.go:130
↓ 1 callers
Function
LastPartition
LastPartition splits a string by last instance of sep into three parts. The return value is a slice of strings with head, match and tail. If str cont
manipulate.go:112
↓ 1 callers
Function
LeftJustify
LeftJustify returns a string with pad string at right side if str's rune length is smaller than length. If str's rune length is larger than length, st
format.go:82
↓ 1 callers
Function
Partition
Partition splits a string by sep into three parts. The return value is a slice of strings with head, match and tail. If str contains sep, for example
manipulate.go:88
↓ 1 callers
Function
RightJustify
RightJustify returns a string with pad string at left side if str's rune length is smaller than length. If str's rune length is larger than length, st
format.go:109
↓ 1 callers
Function
Scrub
Scrub scrubs invalid utf8 bytes with repl string. Adjacent invalid bytes are replaced only once.
manipulate.go:136
↓ 1 callers
Function
Shuffle
Shuffle randomizes runes in a string and returns the result. It uses default random source in `math/rand`.
convert.go:505
↓ 1 callers
Function
ShuffleSource
ShuffleSource randomizes runes in a string with given random source.
convert.go:525
↓ 1 callers
Function
Squeeze
Squeeze deletes adjacent repeated runes in str. If pattern is not empty, only runes matching the pattern will be squeezed. Samples: Squeeze("hello"
translate.go:503
↓ 1 callers
Function
Translate
Translate str with the characters defined in from replaced by characters defined in to. From and to are patterns representing a set of characters. Pa
translate.go:445
↓ 1 callers
Function
Width
Width returns string width in monotype font. Multi-byte characters are usually twice the width of single byte characters. Algorithm comes from `mb_st
count.go:83
↓ 1 callers
Function
WordCount
WordCount returns number of words in a string. Word is defined as a locale dependent string containing alphabetic characters, which may also contain
count.go:20
↓ 1 callers
Function
WordSplit
WordSplit splits a string into words. Returns a slice of words. If there is no word in a string, return nil. Word is defined as a locale dependent st
manipulate.go:182
Function
FirstRuneToLower
FirstRuneToLower converts first rune to lower case if necessary.
convert.go:486
Function
FirstRuneToUpper
FirstRuneToUpper converts first rune to upper case if necessary.
convert.go:468
Method
HasPattern
HasPattern returns true if Translator has one pattern at least.
translate.go:411
Method
Int63
()
convert_test.go:196
Function
Reverse
Reverse a utf8 encoded string.
manipulate.go:12
Method
Seed
(int64)
convert_test.go:202
Function
Successor
Successor returns the successor to string. If there is one alphanumeric rune is found in string, increase the rune by 1. If increment generates a "ca
convert.go:567
Function
SwapCase
SwapCase will swap characters case from upper to lower or lower to upper.
convert.go:441
Function
TestCenter
(t *testing.T)
format_test.go:81
Function
TestCount
(t *testing.T)
translate_test.go:62
Function
TestDelete
(t *testing.T)
translate_test.go:47
Function
TestExpandTabs
(t *testing.T)
format_test.go:12
Function
TestFirstRuneToLower
(t *testing.T)
convert_test.go:120
Function
TestFirstRuneToUpper
(t *testing.T)
convert_test.go:109
Function
TestInsert
(t *testing.T)
manipulate_test.go:92
Function
TestLastPartition
(t *testing.T)
manipulate_test.go:72
Function
TestLeftJustify
(t *testing.T)
format_test.go:39
Function
TestLen
(t *testing.T)
count_test.go:11
Function
TestPartition
(t *testing.T)
manipulate_test.go:52
Function
TestReverse
(t *testing.T)
manipulate_test.go:12
Function
TestRightJustify
(t *testing.T)
format_test.go:60
Function
TestRuneWidth
(t *testing.T)
count_test.go:52
Function
TestScrub
(t *testing.T)
manipulate_test.go:118
Function
TestShuffle
(t *testing.T)
convert_test.go:132
Function
TestShuffleSource
(t *testing.T)
convert_test.go:204
Function
TestSlice
(t *testing.T)
manipulate_test.go:20
Function
TestSqueeze
(t *testing.T)
translate_test.go:77
Function
TestSuccessor
(t *testing.T)
convert_test.go:218
Function
TestSwapCase
(t *testing.T)
convert_test.go:99
Function
TestToCamelCase
(t *testing.T)
convert_test.go:61
Function
TestToPascalCase
(t *testing.T)
convert_test.go:80
Function
TestToSnakeCaseAndToKebabCase
(t *testing.T)
convert_test.go:12
Function
TestTranslate
(t *testing.T)
translate_test.go:12
Function
TestWidth
(t *testing.T)
count_test.go:40
Function
TestWordCount
(t *testing.T)
count_test.go:24
Function
TestWordSplit
(t *testing.T)
manipulate_test.go:131
Function
ToCamelCase
ToCamelCase is to convert words separated by space, underscore and hyphen to camel case. Some samples. "some_words" => "someWords" "http_serv
convert.go:22
Function
ToKebabCase
ToKebabCase can convert all upper case characters in a string to kebab case format. Some samples. "FirstName" => "first-name" "HTTPServer" =>
convert.go:147
Function
ToPascalCase
ToPascalCase is to convert words separated by space, underscore and hyphen to pascal case. Some samples. "some_words" => "SomeWords" "http_se
convert.go:36
Function
ToSnakeCase
ToSnakeCase can convert all upper case characters in a string to snake case format. Some samples. "FirstName" => "first_name" "HTTPServer" =>
convert.go:128