From 188f5ebedcb37feb761971bdfb6315f9b9e4f0f9 Mon Sep 17 00:00:00 2001 From: Luca Osti Date: Fri, 22 Mar 2019 11:37:02 +0100 Subject: [PATCH] Add title-lower transform --- README.md | 5 +++-- stringer.go | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccd9920..75eb42d 100644 --- a/README.md +++ b/README.md @@ -136,9 +136,10 @@ name := MyTypeValue.String() // name => "my_type_value" - snake-upper - kebab - kebab-upper -- lower (Lowercase) -- upper (Uppercase) +- lower (lowercase) +- upper (UPPERCASE) - title (TitleCase) +- title-lower (titleCase) - first (Use first character of string) - first-lower (same as first only lower case) - first-upper (same as first only upper case) diff --git a/stringer.go b/stringer.go index 62a7725..a16670b 100644 --- a/stringer.go +++ b/stringer.go @@ -27,6 +27,7 @@ import ( "path/filepath" "sort" "strings" + "unicode" "unicode/utf8" "github.com/pascaldekloe/name" @@ -272,6 +273,12 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string) fn = func(s string) string { 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": fn = func(s string) string { r, _ := utf8.DecodeRuneInString(s)