@@ -61,9 +61,9 @@ impl Keyword {
6161 keywords. insert ( "createfile" . to_string ( ) , TokenType :: CreateFile ) ;
6262 keywords. insert ( "deletefile" . to_string ( ) , TokenType :: DeleteFile ) ;
6363 if num != 0 {
64- for ( key, value) in keywords. clone ( ) . iter ( ) {
64+ for ( key, value) in & keywords. clone ( ) {
6565 keywords. remove ( key) ;
66- keywords. insert ( toggle_case ( key. to_string ( ) , num) , value. clone ( ) ) ;
66+ keywords. insert ( toggle_case ( key, num) , value. clone ( ) ) ;
6767 }
6868 }
6969 Self { keywords }
@@ -83,22 +83,19 @@ impl Default for Keyword {
8383 }
8484}
8585
86- fn toggle_case ( string : String , num : i32 ) -> String {
86+ fn toggle_case ( string : & str , num : i32 ) -> String {
8787 println ! ( "{}" , string. len( ) + num as usize % 10 ) ;
88- let mut num = match string. len ( ) as i32 - num {
89- nums if nums <= 0 => num,
90- nums => nums,
88+ let num: usize = match string. len ( ) as i32 - num {
89+ nums if nums <= 0 => num as usize % 50 ,
90+ nums => nums as usize % 50 ,
9191 } ;
92- num = num % 50 ;
9392 let mut new_string = String :: new ( ) ;
94- let mut count = 0 ;
95- for c in string. chars ( ) {
93+ for ( count, c) in string. chars ( ) . enumerate ( ) {
9694 if count % num == 0 {
9795 new_string. push ( c. to_uppercase ( ) . next ( ) . unwrap ( ) ) ;
9896 } else {
9997 new_string. push ( c) ;
10098 }
101- count += 1 ;
10299 }
103100 new_string
104101}
0 commit comments