@@ -51,31 +51,31 @@ declare_lint_pass!(NonCamelCaseTypes => [NON_CAMEL_CASE_TYPES]);
5151/// be upper cased or lower cased. For the purposes of the lint suggestion, we care about being able
5252/// to change the char's case.
5353fn char_has_case ( c : char ) -> bool {
54- let mut l = c. to_lowercase ( ) ;
55- let mut u = c. to_uppercase ( ) ;
56- while let Some ( l) = l. next ( ) {
57- match u. next ( ) {
58- Some ( u) if l != u => return true ,
59- _ => { }
54+ c. to_lowercase ( ) . eq ( c. to_uppercase ( ) )
55+ }
56+
57+ // contains a capitalisable character followed by, or preceded by, an underscore
58+ fn has_underscore_case ( s : & str ) -> bool {
59+ let mut last = '\0' ;
60+ s. chars ( ) . any ( |c| {
61+ match ( std:: mem:: replace ( & mut last, c) , c) {
62+ ( '_' , cs) | ( cs, '_' ) => char_has_case ( cs) ,
63+ _ => false ,
6064 }
61- }
62- u. next ( ) . is_some ( )
65+ } )
6366}
6467
6568fn is_camel_case ( name : & str ) -> bool {
6669 let name = name. trim_matches ( '_' ) ;
67- if name. is_empty ( ) {
70+ let Some ( first ) = name. chars ( ) . next ( ) else
6871 return true ;
69- }
72+ } ;
7073
71- // start with a non-lowercase letter rather than non- uppercase
74+ // start with a non-lowercase letter rather than uppercase
7275 // ones (some scripts don't have a concept of upper/lowercase)
73- !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( )
74- && !name. contains ( "__" )
75- && !name. chars ( ) . collect :: < Vec < _ > > ( ) . array_windows ( ) . any ( |& [ fst, snd] | {
76- // contains a capitalisable character followed by, or preceded by, an underscore
77- char_has_case ( fst) && snd == '_' || char_has_case ( snd) && fst == '_'
78- } )
76+ !( first. is_lowercase ( )
77+ || name. contains ( "__" )
78+ || has_underscore_case ( name) )
7979}
8080
8181fn to_camel_case ( s : & str ) -> String {
0 commit comments