Commit ddb464e 1 parent 2319aec commit ddb464e Copy full SHA for ddb464e
File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ package generator
2
2
3
3
import (
4
4
"strings"
5
+
6
+ "golang.org/x/text/cases"
7
+ "golang.org/x/text/language"
5
8
)
6
9
7
10
func Title (s string ) string {
@@ -21,11 +24,11 @@ func Title(s string) string {
21
24
lower := strings .ToLower (s )
22
25
switch {
23
26
case strings .HasSuffix (lower , "id" ):
24
- return strings . Title (strings .TrimSuffix (lower , "id" )) + "ID"
27
+ return stringsTitle (strings .TrimSuffix (lower , "id" )) + "ID"
25
28
case strings .HasSuffix (lower , "ids" ):
26
- return strings . Title (strings .TrimSuffix (lower , "ids" )) + "IDs"
29
+ return stringsTitle (strings .TrimSuffix (lower , "ids" )) + "IDs"
27
30
}
28
- return strings . Title (strings .ToLower (s ))
31
+ return stringsTitle (strings .ToLower (s ))
29
32
}
30
33
31
34
func PrivateFieldName (name string ) string {
@@ -34,3 +37,9 @@ func PrivateFieldName(name string) string {
34
37
}
35
38
return strings .ToLower (name [:1 ]) + name [1 :]
36
39
}
40
+
41
+ var undCaser = cases .Title (language .Und )
42
+
43
+ func stringsTitle (s string ) string {
44
+ return undCaser .String (s )
45
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ require (
7
7
github.com/ghodss/yaml v1.0.0
8
8
github.com/stretchr/testify v1.7.0
9
9
golang.org/x/exp v0.0.0-20240707233637-46b078467d37
10
+ golang.org/x/text v0.16.0
10
11
golang.org/x/tools v0.23.0
11
12
)
12
13
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
30
30
golang.org/x/mod v0.19.0 /go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c =
31
31
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M =
32
32
golang.org/x/sync v0.7.0 /go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk =
33
+ golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4 =
34
+ golang.org/x/text v0.16.0 /go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI =
33
35
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg =
34
36
golang.org/x/tools v0.23.0 /go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI =
35
37
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
You can’t perform that action at this time.
0 commit comments