2021-11-17 11:49:42 +01:00
|
|
|
// Copyright (C) 2017 ScyllaDB
|
|
|
|
|
// Use of this source code is governed by a ALv2-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"unicode"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func camelize(s string) string {
|
|
|
|
|
buf := []byte(s)
|
|
|
|
|
out := make([]byte, 0, len(buf))
|
|
|
|
|
underscoreSeen := false
|
|
|
|
|
|
|
|
|
|
l := len(buf)
|
|
|
|
|
for i := 0; i < l; i++ {
|
2025-10-28 14:52:22 -04:00
|
|
|
if !allowedBindRune(buf[i]) && buf[i] != '_' {
|
2021-11-17 11:49:42 +01:00
|
|
|
panic(fmt.Sprint("not allowed name ", s))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b := rune(buf[i])
|
|
|
|
|
|
|
|
|
|
if b == '_' {
|
|
|
|
|
underscoreSeen = true
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 0 || underscoreSeen) && unicode.IsLower(b) {
|
|
|
|
|
b = unicode.ToUpper(b)
|
|
|
|
|
underscoreSeen = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out = append(out, byte(b))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string(out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func allowedBindRune(b byte) bool {
|
|
|
|
|
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
|
|
|
|
|
}
|