@@ -250,11 +250,10 @@ impl ToSanitizedCase for str {
250
250
self . into ( )
251
251
} ;
252
252
253
- match s. chars ( ) . next ( ) . unwrap_or ( '\0' ) {
254
- '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
255
- Cow :: from ( format ! ( "_{}" , Case :: Pascal . to_case( & s) ) )
256
- }
257
- _ => Case :: Pascal . cow_to_case ( s) ,
253
+ if s. as_bytes ( ) . get ( 0 ) . unwrap_or ( & 0 ) . is_ascii_digit ( ) {
254
+ Cow :: from ( format ! ( "_{}" , Case :: Pascal . to_case( & s) ) )
255
+ } else {
256
+ Case :: Pascal . cow_to_case ( s)
258
257
}
259
258
}
260
259
fn to_sanitized_constant_case ( & self ) -> Cow < str > {
@@ -264,11 +263,10 @@ impl ToSanitizedCase for str {
264
263
self . into ( )
265
264
} ;
266
265
267
- match s. chars ( ) . next ( ) . unwrap_or ( '\0' ) {
268
- '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
269
- Cow :: from ( format ! ( "_{}" , Case :: Constant . to_case( & s) ) )
270
- }
271
- _ => Case :: Constant . cow_to_case ( s) ,
266
+ if s. as_bytes ( ) . get ( 0 ) . unwrap_or ( & 0 ) . is_ascii_digit ( ) {
267
+ Cow :: from ( format ! ( "_{}" , Case :: Constant . to_case( & s) ) )
268
+ } else {
269
+ Case :: Constant . cow_to_case ( s)
272
270
}
273
271
}
274
272
fn to_sanitized_not_keyword_snake_case ( & self ) -> Cow < str > {
@@ -279,17 +277,14 @@ impl ToSanitizedCase for str {
279
277
} else {
280
278
self . into ( )
281
279
} ;
282
- match s. chars ( ) . next ( ) . unwrap_or ( '\0' ) {
283
- '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
284
- format ! ( "_{}" , Case :: Snake . to_case( & s) ) . into ( )
285
- }
286
- _ => {
287
- let s = Case :: Snake . cow_to_case ( s) ;
288
- if INTERNALS . contains ( & s. as_ref ( ) ) {
289
- s + "_"
290
- } else {
291
- s
292
- }
280
+ if s. as_bytes ( ) . get ( 0 ) . unwrap_or ( & 0 ) . is_ascii_digit ( ) {
281
+ format ! ( "_{}" , Case :: Snake . to_case( & s) ) . into ( )
282
+ } else {
283
+ let s = Case :: Snake . cow_to_case ( s) ;
284
+ if INTERNALS . contains ( & s. as_ref ( ) ) {
285
+ s + "_"
286
+ } else {
287
+ s
293
288
}
294
289
}
295
290
}
0 commit comments