Add title-lower transform

This commit is contained in:
Luca Osti 2019-03-22 11:37:02 +01:00
parent d806ebd41f
commit 188f5ebedc
2 changed files with 10 additions and 2 deletions

View File

@ -136,9 +136,10 @@ name := MyTypeValue.String() // name => "my_type_value"
- snake-upper - snake-upper
- kebab - kebab
- kebab-upper - kebab-upper
- lower (Lowercase) - lower (lowercase)
- upper (Uppercase) - upper (UPPERCASE)
- title (TitleCase) - title (TitleCase)
- title-lower (titleCase)
- first (Use first character of string) - first (Use first character of string)
- first-lower (same as first only lower case) - first-lower (same as first only lower case)
- first-upper (same as first only upper case) - first-upper (same as first only upper case)

View File

@ -27,6 +27,7 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"unicode"
"unicode/utf8" "unicode/utf8"
"github.com/pascaldekloe/name" "github.com/pascaldekloe/name"
@ -272,6 +273,12 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string)
fn = func(s string) string { fn = func(s string) string {
return strings.Title(s) return strings.Title(s)
} }
case "title-lower":
fn = func(s string) string {
title := []rune(strings.Title(s))
title[0] = unicode.ToLower(title[0])
return string(title)
}
case "first": case "first":
fn = func(s string) string { fn = func(s string) string {
r, _ := utf8.DecodeRuneInString(s) r, _ := utf8.DecodeRuneInString(s)