woodpecker/vendor/github.com/russross/meddler/mapper.go
6543 75513575be
Use go's vendoring (#284)
* store dependency's in git

* since we vendor ... rm tech-depts

* aad make target 'vendor' to update vendor folder (manual task)
2021-08-30 19:14:04 +02:00

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)
}