mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-12 11:36:29 +00:00
75513575be
* store dependency's in git * since we vendor ... rm tech-depts * aad make target 'vendor' to update vendor folder (manual task)
33 lines
915 B
Go
33 lines
915 B
Go
package meddler
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// MapperFunc signature. Argument is field name, return value is database column.
|
|
type MapperFunc func(in string) string
|
|
|
|
// Mapper defines the function to transform struct field names into database columns.
|
|
// Default is strings.TrimSpace, basically a no-op
|
|
var Mapper MapperFunc = strings.TrimSpace
|
|
|
|
// LowerCase returns a lowercased version of the input string
|
|
func LowerCase(in string) string {
|
|
return strings.ToLower(in)
|
|
}
|
|
|
|
// SnakeCase returns a snake_cased version of the input string
|
|
func SnakeCase(in string) string {
|
|
runes := []rune(in)
|
|
|
|
var out []rune
|
|
for i := 0; i < len(runes); i++ {
|
|
if i > 0 && (unicode.IsUpper(runes[i]) || unicode.IsNumber(runes[i])) && ((i+1 < len(runes) && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {
|
|
out = append(out, '_')
|
|
}
|
|
out = append(out, unicode.ToLower(runes[i]))
|
|
}
|
|
|
|
return string(out)
|
|
}
|