mirror of
https://github.com/therootcompany/golib.git
synced 2026-08-09 22:10:24 +00:00
fix(jsontypes): handle hyphenated JSON keys in PascalCase conversion
snakeToPascal now splits on both underscores and hyphens, producing valid Go identifiers like GenerationI, RubySapphire, BlackWhite instead of invalid ones like Generation-i, Ruby-sapphire, Black-white.
This commit is contained in:
parent
e7c6d25bed
commit
f2045c7831
@ -365,7 +365,9 @@ func isUbiquitousField(name string) bool {
|
||||
|
||||
// snakeToPascal converts snake_case or camelCase to PascalCase.
|
||||
func snakeToPascal(s string) string {
|
||||
parts := strings.Split(s, "_")
|
||||
parts := strings.FieldsFunc(s, func(r rune) bool {
|
||||
return r == '_' || r == '-'
|
||||
})
|
||||
for i, p := range parts {
|
||||
parts[i] = capitalize(p)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user