You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
574 B
34 lines
574 B
package util |
|
|
|
// CamelCase convert to Camel-Case |
|
func CamelCase(name string) string { |
|
if len(name) == 0 { |
|
return name |
|
} |
|
if name[0] == '_' { |
|
return name |
|
} |
|
input := []byte(name) |
|
ret := make([]byte, 0, len(input)) |
|
toUpper := func(c byte) byte { |
|
if 'a' <= c && c <= 'z' { |
|
c -= 32 |
|
} |
|
return c |
|
} |
|
ret = append(ret, toUpper(input[0])) |
|
underline := false |
|
for _, c := range input[1:] { |
|
switch { |
|
case c == '_': |
|
underline = true |
|
default: |
|
if underline { |
|
c = toUpper(c) |
|
} |
|
ret = append(ret, c) |
|
underline = false |
|
} |
|
} |
|
return string(ret) |
|
}
|
|
|