toPascalCase converts a string to PascalCase. The string may contain underscores and dashes, which will be treated as word separators.
(s string)
| 130 | // toPascalCase converts a string to PascalCase. |
| 131 | // The string may contain underscores and dashes, which will be treated as word separators. |
| 132 | func toPascalCase(s string) string { |
| 133 | if s == "" { |
| 134 | return s |
| 135 | } |
| 136 | |
| 137 | words := strings.FieldsFunc(s, func(r rune) bool { |
| 138 | return r == '_' || r == '-' || r == ' ' |
| 139 | }) |
| 140 | |
| 141 | for i, word := range words { |
| 142 | if word != "" { |
| 143 | words[i] = string(unicode.ToUpper(rune(word[0]))) + word[1:] |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return strings.Join(words, "") |
| 148 | } |
no outgoing calls