cmd/schemagen: refactoring
- Replace log.Faltal with error wrapping in schemagen func - Simplify tests, use temp dir and ioutil functions, remove boilerplate code - In test use schemagen keyspace to avoid name conflict with examples - Change template
This commit is contained in:
committed by
Michal Jan Matczuk
parent
39bf42f122
commit
8477485a45
43
cmd/schemagen/camelize.go
Normal file
43
cmd/schemagen/camelize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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++ {
|
||||
if !(allowedBindRune(buf[i]) || buf[i] == '_') {
|
||||
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')
|
||||
}
|
||||
Reference in New Issue
Block a user