File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ use rustc::hir::intravisit::FnKind;
2424use regex:: Regex ;
2525
2626lazy_static ! {
27- static ref ALPHABETIC_UNDERSCORE : Regex = Regex :: new( "([[:alpha:]])_([[:alpha:]])" ) . unwrap( ) ;
27+ static ref ALPHABETIC_UNDERSCORE : Regex =
28+ Regex :: new( "([[:alpha:]])_+|_+([[:alpha:]])" ) . unwrap( ) ;
2829}
2930
3031#[ derive( PartialEq ) ]
@@ -69,11 +70,12 @@ impl NonCamelCaseTypes {
6970 // start with a non-lowercase letter rather than non-uppercase
7071 // ones (some scripts don't have a concept of upper/lowercase)
7172 !name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) &&
72- !ALPHABETIC_UNDERSCORE . is_match ( name)
73+ !name . contains ( "__" ) && ! ALPHABETIC_UNDERSCORE . is_match ( name)
7374 }
7475
7576 fn to_camel_case ( s : & str ) -> String {
76- let s = s. split ( '_' )
77+ let s = s. trim_matches ( '_' )
78+ . split ( '_' )
7779 . map ( |word| {
7880 word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
7981 c. to_uppercase ( ) . collect :: < String > ( )
@@ -83,6 +85,7 @@ impl NonCamelCaseTypes {
8385 . collect :: < Vec < _ > > ( )
8486 . concat ( )
8587 } )
88+ . filter ( |x| !x. is_empty ( ) )
8689 . collect :: < Vec < _ > > ( )
8790 . join ( "_" ) ;
8891 ALPHABETIC_UNDERSCORE . replace_all ( s. as_str ( ) , "$1$2" ) . to_string ( )
You can’t perform that action at this time.
0 commit comments