no good reason to commit this. the code makes hello world into hellworld and i think that's funny.
This commit is contained in:
parent
315d97b358
commit
f16073b955
1 changed files with 20 additions and 8 deletions
28
src/lib.rs
28
src/lib.rs
|
@ -33,6 +33,8 @@ pub fn parse_args(input: &str, mode: u8) -> Vec<String> {
|
|||
let mut double_quote_end: Vec<usize> = 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<String> = vec![];
|
||||
for (i, c) in input.iter().enumerate() {
|
||||
let c = *c;
|
||||
|
||||
|
@ -50,6 +52,8 @@ pub fn parse_args(input: &str, mode: u8) -> Vec<String> {
|
|||
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<String> {
|
|||
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 => {
|
||||
|
|
Loading…
Reference in a new issue