BufPool TitleCase and CamelCase
This commit is contained in:
parent
ddb3aff125
commit
d7e5bf1ef7
1 changed files with 16 additions and 11 deletions
|
@ -143,18 +143,21 @@ func Singular(name string) string {
|
||||||
// titleCase also fully uppercases "ID" components of names, for example
|
// titleCase also fully uppercases "ID" components of names, for example
|
||||||
// "column_name_id" to "ColumnNameID".
|
// "column_name_id" to "ColumnNameID".
|
||||||
func TitleCase(name string) string {
|
func TitleCase(name string) string {
|
||||||
|
buf := GetBuffer()
|
||||||
|
defer PutBuffer(buf)
|
||||||
|
|
||||||
splits := strings.Split(name, "_")
|
splits := strings.Split(name, "_")
|
||||||
|
|
||||||
for i, split := range splits {
|
for _, split := range splits {
|
||||||
if uppercaseWords.MatchString(split) {
|
if uppercaseWords.MatchString(split) {
|
||||||
splits[i] = strings.ToUpper(split)
|
buf.WriteString(strings.ToUpper(split))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
splits[i] = strings.Title(split)
|
buf.WriteString(strings.Title(split))
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(splits, "")
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CamelCase takes a variable name in the format of "var_name" and converts
|
// CamelCase takes a variable name in the format of "var_name" and converts
|
||||||
|
@ -162,24 +165,26 @@ func TitleCase(name string) string {
|
||||||
// camelCase also fully uppercases "ID" components of names, for example
|
// camelCase also fully uppercases "ID" components of names, for example
|
||||||
// "var_name_id" to "varNameID".
|
// "var_name_id" to "varNameID".
|
||||||
func CamelCase(name string) string {
|
func CamelCase(name string) string {
|
||||||
|
buf := GetBuffer()
|
||||||
|
defer PutBuffer(buf)
|
||||||
|
|
||||||
splits := strings.Split(name, "_")
|
splits := strings.Split(name, "_")
|
||||||
|
|
||||||
for i, split := range splits {
|
for i, split := range splits {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
buf.WriteString(split)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 {
|
|
||||||
if uppercaseWords.MatchString(split) {
|
if uppercaseWords.MatchString(split) {
|
||||||
splits[i] = strings.ToUpper(split)
|
buf.WriteString(strings.ToUpper(split))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf.WriteString(strings.Title(split))
|
||||||
}
|
}
|
||||||
|
|
||||||
splits[i] = strings.Title(split)
|
return buf.String()
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(splits, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeStringMap converts a map[string]string into the format:
|
// MakeStringMap converts a map[string]string into the format:
|
||||||
|
|
Loading…
Add table
Reference in a new issue