Documentation
¶
Index ¶
- func CamelCase(s string) string
- func Case(s string, mode CaseMode) string
- func MD5(vs ...string) string
- func PascalCase(s string) string
- func RandomBytes(length int) []byte
- func RandomString(t RandomStringType, length int) string
- func RegisterRandomStringType(t RandomStringType, chars string) bool
- func SHA224(vs ...string) string
- func SHA256(vs ...string) string
- func Sha1(vs ...string) string
- func Sha224(vs ...string) string
- func Sha256(vs ...string) string
- func Sha384(vs ...string) string
- func Sha512(vs ...string) string
- func SnakeCase(s string) string
- func Unbracketed(name string, brackets ...rune) (string, bool)
- func Unfold(tags, separator, delimiter string, cast func(string) string) map[string]string
- func Unquote(name string, quotes ...byte) (id string, ok bool, found byte)
- func UnquoteRune(name string, quotes ...rune) (id string, ok bool, found rune)
- func UpperCase(s string) string
- type CaseMode
- type IgnoreCase
- func (s IgnoreCase) Contains(substring string) bool
- func (s IgnoreCase) ContainsAny(chars string) bool
- func (s IgnoreCase) ContainsRune(r rune) bool
- func (s IgnoreCase) Count(substr string) int
- func (s IgnoreCase) Cut(sep string) (before, after string, found bool)
- func (s IgnoreCase) CutPrefix(prefix string) (after string, found bool)
- func (s IgnoreCase) CutSuffix(suffix string) (before string, found bool)
- func (s IgnoreCase) Equal(t string) bool
- func (s IgnoreCase) HasPrefix(prefix string) bool
- func (s IgnoreCase) HasSuffix(suffix string) bool
- func (s IgnoreCase) Index(substring string) int
- func (s IgnoreCase) IndexAny(chars string) int
- func (s IgnoreCase) IndexRune(r rune) int
- func (s IgnoreCase) LastIndex(substring string) int
- func (s IgnoreCase) LastIndexAny(chars string) int
- func (s IgnoreCase) LastIndexRune(r rune) int
- func (s IgnoreCase) MemoryUsage() (sum int64)
- func (s IgnoreCase) Replace(old, new string, count int) string
- func (s IgnoreCase) ReplaceAll(old, new string) string
- func (s IgnoreCase) Split(sep string) []string
- func (s IgnoreCase) SplitAfter(sep string) []string
- func (s IgnoreCase) SplitAfterN(sep string, n int) []string
- func (s IgnoreCase) SplitN(sep string, n int) []string
- func (s IgnoreCase) ToLower() string
- func (s IgnoreCase) ToUpper() string
- func (s IgnoreCase) TrimPrefix(prefix string) string
- func (s IgnoreCase) TrimSuffix(suffix string) string
- type RandomStringType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCase ¶
CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercase names, it's extremely unlikely to have two fields with different capitalization. For example, _my_field_name_2 => MyFieldName2, idUser => idUser, IdAccount => idAccount,idUser3 => idUser3
返回字符串的小驼峰样式,例如 _my_field_name_2 => MyFieldName2, idUser => idUser, IdAccount => idAccount,idUser3 => idUser3
Example ¶
fmt.Println(CamelCase("primary_key"))
Output: primaryKey
func MD5 ¶
MD5 is a shortcut of md5.Sum, it'll return a hex string
返回一组字符串联接以后的 MD5 值,将返回 32 位的十六进制字符串
func PascalCase ¶
PascalCase returns the CamelCased name with the first character capitalized.
返回单词的大驼峰样式(将大写字母作为单词分隔符),例如 idUser => IdUser,IdAccount => IdAccount,idUser3 => IdUser3
Example ¶
fmt.Println(PascalCase("primary_key"))
Output: PrimaryKey
func RandomBytes ¶ added in v0.1.2
RandomBytes to generate a random bytes, length < 0 returns nil
生成指定位数的随机字节,length < 0 时返回 nil
func RandomString ¶ added in v0.1.2
func RandomString(t RandomStringType, length int) string
RandomString to generate a random string, length < 0 returns empty, notice only works for ASCII string
生成指定位数的安全随机字符串,length < 0 时返回空字符串,注意仅适用于生成 ASCII 字符串
Example ¶
for i := Printable; i < Base64; i++ {
fmt.Printf(string(RandomString(i, 50)))
}
Output: 0123456789 0123456789
func RegisterRandomStringType ¶ added in v0.1.2
func RegisterRandomStringType(t RandomStringType, chars string) bool
RegisterRandomStringType to register a random string type
注册一个随机字符串类型
func Sha1 ¶
Sha1 is a shortcut of sha1.Sum, it'll return a hex string
返回一组字符串联接以后的字符串的 SHA1 值,将返回 32 位的十六进制字符串
func SnakeCase ¶
SnakeCase 返回单词的蛇形样式(将大写字母作为单词分隔符,前加 _ 并转为小写,首字符除外),其它字符不作额外的处理, 例如 idUser => id_user,IdAccount => id_account
Example ¶
fmt.Println(SnakeCase("primaryKey"))
Output: primary_key
func Unbracketed ¶
Unbracketed attempt to remove the brackets from the name.
Unbracketed("/regexp/", '/') // output: regexp
Unbracketed("<div>", '<', '>') // output: div
去括号,参数 brackets 为括号字符,提供一个字符时,此字符同时作为首尾括号;提供两个字符时,分别作为首尾括号,更多的字符则被忽略
Example ¶
fmt.Println(Unbracketed("<primaryKey>", '<', '>'))
fmt.Println(Unbracketed("/regular expression/", '/'))
Output: primaryKey true regular expression true
func Unfold ¶
Unfold to split the tags string into a map[string]string using "separator" and "delimiter" as delimiters
使用 separator 和 delimiter 作为分隔符对 tags 字符串进行两次拆分,转换为 map[string]string,注意,未考虑字符转义的情况。
Example ¶
r1 := Unfold("primaryKey;uniqueIndex:idx;size:20", ";", ":", nil)
r2 := Unfold("primaryKey;uniqueIndex:idx;size:20", ";", ":", SnakeCase)
r3 := Unfold("primaryKey;uniqueIndex:idx;size:20", ";", ":", UpperCase)
r4 := Unfold("primaryKey;uniqueIndex:idx;size:20", ";", ":", CamelCase)
r5 := Unfold("primaryKey;uniqueIndex:idx;size:20", ";", ":", PascalCase)
fmt.Println(r1)
fmt.Println(r2)
fmt.Println(r3)
fmt.Println(r4)
fmt.Println(r5)
Output: map[primaryKey: size:20 uniqueIndex:idx] map[primary_key: size:20 unique_index:idx] map[PRIMARY_KEY: SIZE:20 UNIQUE_INDEX:idx] map[primaryKey: size:20 uniqueIndex:idx] map[PrimaryKey: Size:20 UniqueIndex:idx]
func Unquote ¶
Unquote attempt to remove the quotes from the name.
尝试去除名字前后的任意字符(一般用于反撇号,单引号,双引号等), 当名字前后指定字符非成对时,视为不正确,ok 返回 false。 指定多个时依次尝试,但仅执行一次。 found 返回找到的引号字符值,0 为未找到。
Example ¶
fmt.Println(Unquote("'primaryKey'", '\''))
fmt.Println(Unquote("`tag`", '`'))
Output: primaryKey true 39 tag true 96
func UnquoteRune ¶
UnquoteRune 尝试去除名字前后的任意字符对(一般用于反撇号,单引号,双引号等), 当名字前后指定字符非成对时,视为不正确,ok 返回 false。 指定多个时依次尝试,但仅执行一次。 found 返回找到的引号字符值,utf8.RuneError 为未找到。
Example ¶
fmt.Println(UnquoteRune("'primaryKey'", '\''))
fmt.Println(UnquoteRune("\"primaryKey\"", '"'))
Output: primaryKey true 39 primaryKey true 34
Types ¶
type CaseMode ¶
type CaseMode = int
const ( Ignored CaseMode = iota // ignore case style SnakeCaseMode // snake case style, 蛇形,形如:id_user, id_account UpperCaseMode // upper snake case style, 大蛇形,形如:ID_USER,ID_ACCOUNT CamelCaseMode // camel case style, 驼峰,形如:idUser,idAccount PascalCaseMode // upper camel case style, 大驼峰/Pascal,形如:IdUser,IdAccount )
type IgnoreCase ¶
type IgnoreCase string
IgnoreCase is case-insensitive string.
func (IgnoreCase) Contains ¶
func (s IgnoreCase) Contains(substring string) bool
func (IgnoreCase) ContainsAny ¶
func (s IgnoreCase) ContainsAny(chars string) bool
func (IgnoreCase) ContainsRune ¶
func (s IgnoreCase) ContainsRune(r rune) bool
func (IgnoreCase) Count ¶
func (s IgnoreCase) Count(substr string) int
func (IgnoreCase) CutPrefix ¶
func (s IgnoreCase) CutPrefix(prefix string) (after string, found bool)
func (IgnoreCase) CutSuffix ¶
func (s IgnoreCase) CutSuffix(suffix string) (before string, found bool)
func (IgnoreCase) Equal ¶
func (s IgnoreCase) Equal(t string) bool
func (IgnoreCase) HasPrefix ¶
func (s IgnoreCase) HasPrefix(prefix string) bool
func (IgnoreCase) HasSuffix ¶
func (s IgnoreCase) HasSuffix(suffix string) bool
func (IgnoreCase) Index ¶
func (s IgnoreCase) Index(substring string) int
func (IgnoreCase) IndexAny ¶
func (s IgnoreCase) IndexAny(chars string) int
func (IgnoreCase) IndexRune ¶
func (s IgnoreCase) IndexRune(r rune) int
func (IgnoreCase) LastIndex ¶
func (s IgnoreCase) LastIndex(substring string) int
func (IgnoreCase) LastIndexAny ¶
func (s IgnoreCase) LastIndexAny(chars string) int
func (IgnoreCase) LastIndexRune ¶
func (s IgnoreCase) LastIndexRune(r rune) int
func (IgnoreCase) MemoryUsage ¶
func (s IgnoreCase) MemoryUsage() (sum int64)
MemoryUsage return the memory usage of IgnoreCase
func (IgnoreCase) ReplaceAll ¶
func (s IgnoreCase) ReplaceAll(old, new string) string
func (IgnoreCase) Split ¶
func (s IgnoreCase) Split(sep string) []string
func (IgnoreCase) SplitAfter ¶
func (s IgnoreCase) SplitAfter(sep string) []string
func (IgnoreCase) SplitAfterN ¶
func (s IgnoreCase) SplitAfterN(sep string, n int) []string
func (IgnoreCase) ToLower ¶
func (s IgnoreCase) ToLower() string
func (IgnoreCase) ToUpper ¶
func (s IgnoreCase) ToUpper() string
func (IgnoreCase) TrimPrefix ¶
func (s IgnoreCase) TrimPrefix(prefix string) string
func (IgnoreCase) TrimSuffix ¶
func (s IgnoreCase) TrimSuffix(suffix string) string
type RandomStringType ¶ added in v0.1.2
type RandomStringType int
const ( Printable RandomStringType = iota Graphical NoQuote Digits AlphabetNumeric Alphabet AlphabetLowercase AlphabetUppercase Hex HexLower HexUpper Base64 )