diff --git a/src/lib.rs b/src/lib.rs index d600349..52c6dac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,8 @@ pub fn parse_args(input: &str, mode: u8) -> Vec { let mut double_quote_end: Vec = vec![]; // List of ending double quotation marks. let mut is_double_quoted: bool = false; // boolean showing if the current contents are quoted. + let mut parameter_index: usize = 0; + let mut arguments: Vec = vec![]; for (i, c) in input.iter().enumerate() { let c = *c; @@ -50,6 +52,8 @@ pub fn parse_args(input: &str, mode: u8) -> Vec { single_quote_begin.push(i); is_single_quoted = true; } + } else { + arguments.insert(parameter_index, c.to_string()); } }, '\"' => { // Double quoted stuff works kind of like graves do in JavaScript. See the bash manualĀ§3.1.2.3. @@ -61,18 +65,26 @@ pub fn parse_args(input: &str, mode: u8) -> Vec { double_quote_begin.push(i); is_double_quoted = true; } + } else { + arguments.insert(parameter_index, c.to_string()); } } - _ => {} + ' ' => { + if !escaped || !is_single_quoted || !is_double_quoted { + parameter_index += 1; + } else { + + } + } + _ => { + let __: &String = &String::new(); + let mut arg = arguments.get(parameter_index).unwrap_or(__).to_owned(); + arg.push(c); + arguments.insert(parameter_index, arg.clone()); + } } } - if single_quote_begin.len() != single_quote_end.len() { - panic!("Hanging single quotation mark: {}", single_quote_begin.get(single_quote_begin.len()).unwrap_or(&0)); - } - if double_quote_begin.len() != double_quote_end.len() { - panic!("Hanging double quotation mark: {}", double_quote_begin.get(double_quote_begin.len()).unwrap_or(&0)); - } - vec![] + arguments }, /// 0x10 => {