File tree 1 file changed +6
-3
lines changed
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;
24
24
use regex:: Regex ;
25
25
26
26
lazy_static ! {
27
- static ref ALPHABETIC_UNDERSCORE : Regex = Regex :: new( "([[:alpha:]])_([[:alpha:]])" ) . unwrap( ) ;
27
+ static ref ALPHABETIC_UNDERSCORE : Regex =
28
+ Regex :: new( "([[:alpha:]])_+|_+([[:alpha:]])" ) . unwrap( ) ;
28
29
}
29
30
30
31
#[ derive( PartialEq ) ]
@@ -69,11 +70,12 @@ impl NonCamelCaseTypes {
69
70
// start with a non-lowercase letter rather than non-uppercase
70
71
// ones (some scripts don't have a concept of upper/lowercase)
71
72
!name. is_empty ( ) && !name. chars ( ) . next ( ) . unwrap ( ) . is_lowercase ( ) &&
72
- !ALPHABETIC_UNDERSCORE . is_match ( name)
73
+ !name . contains ( "__" ) && ! ALPHABETIC_UNDERSCORE . is_match ( name)
73
74
}
74
75
75
76
fn to_camel_case ( s : & str ) -> String {
76
- let s = s. split ( '_' )
77
+ let s = s. trim_matches ( '_' )
78
+ . split ( '_' )
77
79
. map ( |word| {
78
80
word. chars ( ) . enumerate ( ) . map ( |( i, c) | if i == 0 {
79
81
c. to_uppercase ( ) . collect :: < String > ( )
@@ -83,6 +85,7 @@ impl NonCamelCaseTypes {
83
85
. collect :: < Vec < _ > > ( )
84
86
. concat ( )
85
87
} )
88
+ . filter ( |x| !x. is_empty ( ) )
86
89
. collect :: < Vec < _ > > ( )
87
90
. join ( "_" ) ;
88
91
ALPHABETIC_UNDERSCORE . replace_all ( s. as_str ( ) , "$1$2" ) . to_string ( )
You can’t perform that action at this time.
0 commit comments