@@ -154,16 +154,21 @@ function jsonToGo(json, typename)
154
154
155
155
function toProperCase ( str )
156
156
{
157
- if ( str . length == 0 )
158
- return "" ;
159
-
160
- str = str . charAt ( 0 ) . toUpperCase ( ) + str . substr ( 1 ) ;
161
-
162
- return str . replace ( / [ \s _ - ] [ a - z ] + / g, function ( txt )
157
+ // see github.com/golang/lint/lint.go
158
+ var commonInitialisms = [
159
+ "API" , "ASCII" , "CPU" , "CSS" , "DNS" , "EOF" , "GUID" , "HTML" , "HTTP" ,
160
+ "HTTPS" , "ID" , "IP" , "JSON" , "LHS" , "QPS" , "RAM" , "RHS" , "RPC" , "SLA" ,
161
+ "SMTP" , "SSH" , "TCP" , "TLS" , "TTL" , "UDP" , "UI" , "UID" , "UUID" , "URI" ,
162
+ "URL" , "UTF8" , "VM" , "XML" , "XSRF" , "XSS"
163
+ ] ;
164
+
165
+ return str . replace ( / ( ^ | [ \s _ - ] ) ( [ a - z ] + ) / g, function ( unused , sep , frag )
163
166
{
164
- return txt . charAt ( 0 )
165
- + txt . charAt ( 1 ) . toUpperCase ( )
166
- + txt . substr ( 2 ) . toLowerCase ( ) ;
167
+ if ( commonInitialisms . indexOf ( frag . toUpperCase ( ) ) >= 0 ) {
168
+ return sep + frag . toUpperCase ( ) ;
169
+ } else {
170
+ return sep + frag [ 0 ] . toUpperCase ( ) + frag . substr ( 1 ) . toLowerCase ( ) ;
171
+ }
167
172
} ) ;
168
173
}
169
- }
174
+ }
0 commit comments