init - add project files
This commit is contained in:
107
vendor/github.com/go-jet/jet/v2/internal/utils/dbidentifier/dbidentifier.go
generated
vendored
Normal file
107
vendor/github.com/go-jet/jet/v2/internal/utils/dbidentifier/dbidentifier.go
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
package dbidentifier
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/internal/3rdparty/snaker"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// ToGoIdentifier converts database identifier to Go identifier.
|
||||
func ToGoIdentifier(databaseIdentifier string) string {
|
||||
return snaker.SnakeToCamel(replaceInvalidChars(databaseIdentifier))
|
||||
}
|
||||
|
||||
// ToGoFileName converts database identifier to Go file name.
|
||||
func ToGoFileName(databaseIdentifier string) string {
|
||||
return strings.ToLower(replaceInvalidChars(databaseIdentifier))
|
||||
}
|
||||
|
||||
func replaceInvalidChars(identifier string) string {
|
||||
increase, needs := needsCharReplacement(identifier)
|
||||
|
||||
if !needs {
|
||||
return identifier
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
|
||||
b.Grow(len(identifier) + increase)
|
||||
|
||||
for _, c := range identifier {
|
||||
switch {
|
||||
case unicode.IsSpace(c):
|
||||
b.WriteByte('_')
|
||||
case unicode.IsControl(c):
|
||||
continue
|
||||
default:
|
||||
replacement, ok := asciiCharacterReplacement[c]
|
||||
|
||||
if ok {
|
||||
b.WriteByte('_')
|
||||
b.WriteString(replacement)
|
||||
b.WriteByte('_')
|
||||
} else {
|
||||
b.WriteRune(c)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func needsCharReplacement(identifier string) (increase int, needs bool) {
|
||||
for _, c := range identifier {
|
||||
switch {
|
||||
case unicode.IsSpace(c):
|
||||
needs = true
|
||||
case unicode.IsControl(c):
|
||||
increase += -1
|
||||
needs = true
|
||||
continue
|
||||
default:
|
||||
replacement, ok := asciiCharacterReplacement[c]
|
||||
|
||||
if ok {
|
||||
increase += len(replacement) + 1
|
||||
needs = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return increase, needs
|
||||
}
|
||||
|
||||
var asciiCharacterReplacement = map[rune]string{
|
||||
'!': "exclamation",
|
||||
'"': "quotation",
|
||||
'#': "number",
|
||||
'$': "dollar",
|
||||
'%': "percent",
|
||||
'&': "ampersand",
|
||||
'\'': "apostrophe",
|
||||
'(': "opening_parentheses",
|
||||
')': "closing_parentheses",
|
||||
'*': "asterisk",
|
||||
'+': "plus",
|
||||
',': "comma",
|
||||
'-': "_",
|
||||
'.': "_",
|
||||
'/': "slash",
|
||||
':': "colon",
|
||||
';': "semicolon",
|
||||
'<': "less",
|
||||
'=': "equal",
|
||||
'>': "greater",
|
||||
'?': "question",
|
||||
'@': "at",
|
||||
'[': "opening_bracket",
|
||||
'\\': "backslash",
|
||||
']': "closing_bracket",
|
||||
'^': "caret",
|
||||
'`': "accent",
|
||||
'{': "opening_braces",
|
||||
'|': "vertical_bar",
|
||||
'}': "closing_braces",
|
||||
'~': "tilde",
|
||||
}
|
||||
8
vendor/github.com/go-jet/jet/v2/internal/utils/is/is.go
generated
vendored
Normal file
8
vendor/github.com/go-jet/jet/v2/internal/utils/is/is.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
package is
|
||||
|
||||
import "reflect"
|
||||
|
||||
// Nil check if v is nil
|
||||
func Nil(v interface{}) bool {
|
||||
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
|
||||
}
|
||||
9
vendor/github.com/go-jet/jet/v2/internal/utils/min/min.go
generated
vendored
Normal file
9
vendor/github.com/go-jet/jet/v2/internal/utils/min/min.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package min
|
||||
|
||||
// Int returns minimum of two int values
|
||||
func Int(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
41
vendor/github.com/go-jet/jet/v2/internal/utils/must/must.go
generated
vendored
Normal file
41
vendor/github.com/go-jet/jet/v2/internal/utils/must/must.go
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package must
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/internal/utils/is"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// BeTrue panics when condition is false
|
||||
func BeTrue(condition bool, errorStr string) {
|
||||
if !condition {
|
||||
panic(errorStr)
|
||||
}
|
||||
}
|
||||
|
||||
// BeTypeKind panics with errorStr error, if v interface is not of reflect kind
|
||||
func BeTypeKind(v interface{}, kind reflect.Kind, errorStr string) {
|
||||
if reflect.TypeOf(v).Kind() != kind {
|
||||
panic(errorStr)
|
||||
}
|
||||
}
|
||||
|
||||
// ValueBeOfTypeKind panics with errorStr error, if v value is not of reflect kind
|
||||
func ValueBeOfTypeKind(v reflect.Value, kind reflect.Kind, errorStr string) {
|
||||
if v.Kind() != kind {
|
||||
panic(errorStr)
|
||||
}
|
||||
}
|
||||
|
||||
// TypeBeOfKind panics with errorStr error, if v type is not of reflect kind
|
||||
func TypeBeOfKind(v reflect.Type, kind reflect.Kind, errorStr string) {
|
||||
if v.Kind() != kind {
|
||||
panic(errorStr)
|
||||
}
|
||||
}
|
||||
|
||||
// BeInitializedPtr panics with errorStr if val interface is nil
|
||||
func BeInitializedPtr(val interface{}, errorStr string) {
|
||||
if is.Nil(val) {
|
||||
panic(errorStr)
|
||||
}
|
||||
}
|
||||
12
vendor/github.com/go-jet/jet/v2/internal/utils/strslice/strslice.go
generated
vendored
Normal file
12
vendor/github.com/go-jet/jet/v2/internal/utils/strslice/strslice.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package strslice
|
||||
|
||||
// Contains checks if slice of strings contains a string
|
||||
func Contains(strings []string, contains string) bool {
|
||||
for _, str := range strings {
|
||||
if str == contains {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user