MCPcopy Create free account
hub / github.com/Shelnutt2/db2struct / lintFieldName

Function lintFieldName

utils.go:125–199  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

123}
124
125func lintFieldName(name string) string {
126 // Fast path for simple cases: "_" and all lowercase.
127 if name == "_" {
128 return name
129 }
130
131 for len(name) > 0 && name[0] == '_' {
132 name = name[1:]
133 }
134
135 allLower := true
136 for _, r := range name {
137 if !unicode.IsLower(r) {
138 allLower = false
139 break
140 }
141 }
142 if allLower {
143 runes := []rune(name)
144 if u := strings.ToUpper(name); commonInitialisms[u] {
145 copy(runes[0:], []rune(u))
146 } else {
147 runes[0] = unicode.ToUpper(runes[0])
148 }
149 return string(runes)
150 }
151
152 // Split camelCase at any lower->upper transition, and split on underscores.
153 // Check each word for common initialisms.
154 runes := []rune(name)
155 w, i := 0, 0 // index of start of word, scan
156 for i+1 <= len(runes) {
157 eow := false // whether we hit the end of a word
158
159 if i+1 == len(runes) {
160 eow = true
161 } else if runes[i+1] == '_' {
162 // underscore; shift the remainder forward over any run of underscores
163 eow = true
164 n := 1
165 for i+n+1 < len(runes) && runes[i+n+1] == '_' {
166 n++
167 }
168
169 // Leave at most one underscore if the underscore is between two digits
170 if i+n+1 < len(runes) && unicode.IsDigit(runes[i]) && unicode.IsDigit(runes[i+n+1]) {
171 n--
172 }
173
174 copy(runes[i+1:], runes[i+n+1:])
175 runes = runes[:len(runes)-n]
176 } else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
177 // lower->non-lower
178 eow = true
179 }
180 i++
181 if !eow {
182 continue

Callers 2

TestLintFieldNameFunction · 0.85
fmtFieldNameFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestLintFieldNameFunction · 0.68