@@ -56,86 +56,38 @@ pub trait ToSanitizedSnakeCase {
5656
5757impl  ToSanitizedSnakeCase  for  str  { 
5858    fn  to_sanitized_not_keyword_snake_case ( & self )  -> Cow < str >  { 
59+         const  INTERNALS :  [ & str ;  4 ]  = [ "set_bit" ,  "clear_bit" ,  "bit" ,  "bits" ] ; 
60+ 
5961        let  s = self . replace ( BLACKLIST_CHARS ,  "" ) ; 
6062        match  s. chars ( ) . next ( ) . unwrap_or ( '\0' )  { 
6163            '0'  | '1'  | '2'  | '3'  | '4'  | '5'  | '6'  | '7'  | '8'  | '9'  => { 
62-                 Cow :: from ( format ! ( "_{}" ,  s. to_snake_case( ) ) ) 
64+                 format ! ( "_{}" ,  s. to_snake_case( ) ) . into ( ) 
65+             } 
66+             _ => { 
67+                 let  s = Cow :: from ( s. to_snake_case ( ) ) ; 
68+                 if  INTERNALS . contains ( & s. as_ref ( ) )  { 
69+                     s + "_" 
70+                 }  else  { 
71+                     s
72+                 } 
6373            } 
64-             _ => Cow :: from ( s. to_snake_case ( ) ) , 
6574        } 
6675    } 
6776} 
6877
69- pub  fn  sanitize_keyword < ' a > ( s :  Cow < ' a ,  str > )  -> Cow < ' a ,  str >  { 
70-     macro_rules!  keywords { 
71-         ( $s: expr,  $( $kw: ident) ,+, )  => { 
72-             Cow :: from( match  & $s. to_lowercase( ) [ ..]  { 
73-                 $( stringify!( $kw)  => concat!( stringify!( $kw) ,  "_" ) ) ,+, 
74-                 _ => return  s, 
75-             } ) 
76-         } 
77-     } 
78- 
79-     keywords !  { 
80-         s, 
81-         abstract, 
82-         alignof, 
83-         as , 
84-         async , 
85-         await , 
86-         become, 
87-         box, 
88-         break , 
89-         const , 
90-         continue , 
91-         crate , 
92-         do, 
93-         else, 
94-         enum , 
95-         extern, 
96-         false , 
97-         final, 
98-         fn , 
99-         for , 
100-         if , 
101-         impl , 
102-         in, 
103-         let , 
104-         loop , 
105-         macro, 
106-         match , 
107-         mod , 
108-         move, 
109-         mut , 
110-         offsetof, 
111-         override, 
112-         priv, 
113-         proc, 
114-         pub , 
115-         pure, 
116-         ref, 
117-         return , 
118-         self , 
119-         sizeof, 
120-         static , 
121-         struct , 
122-         super , 
123-         trait , 
124-         true , 
125-         try, 
126-         type , 
127-         typeof, 
128-         unsafe , 
129-         unsized, 
130-         use , 
131-         virtual, 
132-         where , 
133-         while , 
134-         yield, 
135-         set_bit, 
136-         clear_bit, 
137-         bit, 
138-         bits, 
78+ pub  fn  sanitize_keyword ( sc :  Cow < str > )  -> Cow < str >  { 
79+     const  KEYWORDS :  [ & str ;  54 ]  = [ 
80+         "abstract" ,  "alignof" ,  "as" ,  "async" ,  "await" ,  "become" ,  "box" ,  "break" ,  "const" , 
81+         "continue" ,  "crate" ,  "do" ,  "else" ,  "enum" ,  "extern" ,  "false" ,  "final" ,  "fn" ,  "for" ,  "if" , 
82+         "impl" ,  "in" ,  "let" ,  "loop" ,  "macro" ,  "match" ,  "mod" ,  "move" ,  "mut" ,  "offsetof" , 
83+         "override" ,  "priv" ,  "proc" ,  "pub" ,  "pure" ,  "ref" ,  "return" ,  "self" ,  "sizeof" ,  "static" , 
84+         "struct" ,  "super" ,  "trait" ,  "true" ,  "try" ,  "type" ,  "typeof" ,  "unsafe" ,  "unsized" ,  "use" , 
85+         "virtual" ,  "where" ,  "while" ,  "yield" , 
86+     ] ; 
87+     if  KEYWORDS . contains ( & sc. as_ref ( ) )  { 
88+         sc + "_" 
89+     }  else  { 
90+         sc
13991    } 
14092} 
14193
0 commit comments