Commit c4fe393 1 parent 0dcdbe4 commit c4fe393 Copy full SHA for c4fe393
File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -112,8 +112,15 @@ func SnakeCase(in string) string {
112
112
113
113
var out []rune
114
114
for i := 0 ; i < length ; i ++ {
115
- if i > 0 && unicode .IsUpper (runes [i ]) && ((i + 1 < length && unicode .IsLower (runes [i + 1 ])) || unicode .IsLower (runes [i - 1 ])) {
116
- out = append (out , '_' )
115
+ if i > 0 && unicode .IsUpper (runes [i ]) {
116
+ prevLower := unicode .IsLower (runes [i - 1 ])
117
+ nextLower := i + 1 < length && unicode .IsLower (runes [i + 1 ])
118
+ // Special case for plural acronyms
119
+ nextPlural := i + 1 < length && runes [i + 1 ] == 's'
120
+
121
+ if prevLower || (nextLower && ! nextPlural ) {
122
+ out = append (out , '_' )
123
+ }
117
124
}
118
125
out = append (out , unicode .ToLower (runes [i ]))
119
126
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ var tests = []SnakeTest{
34
34
{"LinuxMOTD" , "linux_motd" },
35
35
{"OMGWTFBBQ" , "omgwtfbbq" },
36
36
{"omg_wtf_bbq" , "omg_wtf_bbq" },
37
+ {"ConsumedLCUs" , "consumed_lcus" },
37
38
}
38
39
39
40
func TestSnakeCase (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments