@@ -65,7 +65,7 @@ impl Commands {
65
65
info ! ( "Adding command {}" , & command) ;
66
66
let mut state = 0 ;
67
67
68
- let mut opt_lambda_state = None ;
68
+ let mut reused_space_state = None ;
69
69
let mut opt_final_states = vec ! [ ] ;
70
70
71
71
let handler = Arc :: new ( Command {
@@ -78,28 +78,32 @@ impl Commands {
78
78
. filter ( |segment| segment. len ( ) > 0 )
79
79
. enumerate ( )
80
80
. for_each ( |( i, segment) | {
81
- if let Some ( kv_pair) = key_value_pair ( segment) {
82
- if let Some ( lambda) = opt_lambda_state {
83
- state = match kv_pair {
84
- KeyValuePair :: Quoted ( name) => self . add_quoted_key_value ( name, lambda) ,
85
- KeyValuePair :: Unquoted ( name) => self . add_key_value ( name, lambda) ,
86
- } ;
81
+ if let Some ( name) = key_value_pair ( segment) {
82
+ if let Some ( lambda) = reused_space_state {
83
+ state = self . add_key_value ( name, lambda) ;
84
+ self . state_machine . add_next_state ( state, lambda) ;
85
+ opt_final_states. push ( state) ;
86
+
87
+ state = self . add_quoted_key_value ( name, lambda) ;
87
88
self . state_machine . add_next_state ( state, lambda) ;
88
89
opt_final_states. push ( state) ;
89
90
} else {
90
91
opt_final_states. push ( state) ;
91
92
state = self . add_space ( state, i) ;
92
- opt_lambda_state = Some ( state) ;
93
- state = match kv_pair {
94
- KeyValuePair :: Quoted ( name) => self . add_quoted_key_value ( name, state) ,
95
- KeyValuePair :: Unquoted ( name) => self . add_key_value ( name, state) ,
96
- } ;
93
+ reused_space_state = Some ( state) ;
94
+
95
+ state = self . add_key_value ( name, state) ;
97
96
self . state_machine
98
- . add_next_state ( state, opt_lambda_state. unwrap ( ) ) ;
97
+ . add_next_state ( state, reused_space_state. unwrap ( ) ) ;
98
+ opt_final_states. push ( state) ;
99
+
100
+ state = self . add_quoted_key_value ( name, reused_space_state. unwrap ( ) ) ;
101
+ self . state_machine
102
+ . add_next_state ( state, reused_space_state. unwrap ( ) ) ;
99
103
opt_final_states. push ( state) ;
100
104
}
101
105
} else {
102
- opt_lambda_state = None ;
106
+ reused_space_state = None ;
103
107
opt_final_states. truncate ( 0 ) ;
104
108
let last_state = state;
105
109
state = self . add_space ( state, i) ;
@@ -128,7 +132,7 @@ impl Commands {
128
132
}
129
133
} ) ;
130
134
131
- if opt_lambda_state . is_some ( ) {
135
+ if reused_space_state . is_some ( ) {
132
136
opt_final_states. iter ( ) . for_each ( |state| {
133
137
self . state_machine . set_final_state ( * state) ;
134
138
self . state_machine . set_handler ( * state, handler. clone ( ) ) ;
@@ -328,7 +332,7 @@ impl Commands {
328
332
state = self . state_machine . add ( state, CharacterSet :: from_char ( '=' ) ) ;
329
333
330
334
let mut char_set = CharacterSet :: any ( ) ;
331
- char_set. remove ( & [ ' ' , '\n' ] ) ;
335
+ char_set. remove ( & [ ' ' , '\n' , '"' ] ) ;
332
336
state = self . state_machine . add ( state, char_set) ;
333
337
self . state_machine . add_next_state ( state, state) ;
334
338
self . state_machine . start_parse ( state, name) ;
@@ -344,7 +348,9 @@ impl Commands {
344
348
state = self . state_machine . add ( state, CharacterSet :: from_char ( '=' ) ) ;
345
349
state = self . state_machine . add ( state, CharacterSet :: from_char ( '"' ) ) ;
346
350
347
- state = self . state_machine . add ( state, CharacterSet :: any ( ) ) ;
351
+ let mut char_set = CharacterSet :: any ( ) ;
352
+ char_set. remove ( & [ '"' ] ) ;
353
+ state = self . state_machine . add ( state, char_set) ;
348
354
self . state_machine . add_next_state ( state, state) ;
349
355
self . state_machine . start_parse ( state, name) ;
350
356
self . state_machine . end_parse ( state) ;
@@ -355,26 +361,16 @@ impl Commands {
355
361
}
356
362
}
357
363
358
- enum KeyValuePair {
359
- Quoted ( & ' static str ) ,
360
- Unquoted ( & ' static str ) ,
361
- }
362
-
363
- fn key_value_pair ( s : & ' static str ) -> Option < KeyValuePair > {
364
- let len = s. len ( ) ;
365
-
366
- if len <= 3 {
367
- return None ;
368
- }
369
-
370
- let delim = & s[ len - 3 ..] ;
371
- let key = & s[ ..len - 3 ] ;
372
-
373
- if delim == "={}" {
374
- Some ( KeyValuePair :: Unquoted ( key) )
375
- } else if delim == "=[]" {
376
- Some ( KeyValuePair :: Quoted ( key) )
377
- } else {
378
- None
379
- }
364
+ fn key_value_pair ( s : & ' static str ) -> Option < & ' static str > {
365
+ s. match_indices ( "={}" )
366
+ . next ( )
367
+ . map ( |pair| {
368
+ let name = & s[ 0 ..pair. 0 ] ;
369
+ if name. len ( ) > 0 {
370
+ Some ( name)
371
+ } else {
372
+ None
373
+ }
374
+ } )
375
+ . flatten ( )
380
376
}
0 commit comments