File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ var customInitialisms = map[string][2]string{
158158
159159// TitleFirstWord upper case the first letter of a string.
160160func TitleFirstWord (s string ) string {
161- if len ( s ) == 0 {
161+ if s == "" {
162162 return s
163163 }
164164
@@ -168,6 +168,24 @@ func TitleFirstWord(s string) string {
168168 return string (r )
169169}
170170
171+ // UntitleFirstWord lower case the first letter of a string.
172+ func UntitleFirstWord (s string ) string {
173+ if s == "" {
174+ return s
175+ }
176+
177+ r := []rune (s )
178+
179+ firstWord := strings .Split (s , " " )[0 ]
180+ _ , isCommonInitialism := commonInitialisms [firstWord ]
181+ _ , isCustomInitialism := customInitialisms [firstWord ]
182+ if ! isCommonInitialism && ! isCustomInitialism {
183+ r [0 ] = unicode .ToLower (r [0 ])
184+ }
185+
186+ return string (r )
187+ }
188+
171189// lowerCaseFirstLetterOrAcronyms lower case the first letter of a string.
172190func lowerCaseFirstLetterOrAcronyms (s string ) string {
173191 r := []rune (s )
Original file line number Diff line number Diff line change @@ -46,3 +46,21 @@ func TestTitleFirstWord(t *testing.T) {
4646 }
4747 }
4848}
49+
50+ func Test_UntitleFirstWord (t * testing.T ) {
51+ cases := [][]string {
52+ {"" , "" },
53+ {"T" , "t" },
54+ {"UUID" , "UUID" },
55+ {"UUI" , "uUI" },
56+ {"TEST CASE" , "tEST CASE" },
57+ }
58+ for _ , i := range cases {
59+ in := i [0 ]
60+ out := i [1 ]
61+ result := UntitleFirstWord (in )
62+ if result != out {
63+ t .Error ("'" + result + "' != '" + out + "'" )
64+ }
65+ }
66+ }
You can’t perform that action at this time.
0 commit comments