parser : ajout fonction parse_backslash

This commit is contained in:
Ahurac 2024-04-15 13:14:36 +02:00
parent ed6aa02ce4
commit 8d3241ecdc

View file

@ -16,6 +16,16 @@ fn parse_quote(characters: &mut Vec<char>) -> String {
quoted quoted
} }
fn parse_backslash(characters: &mut Vec<char>) -> Option<char> {
let mut escaped_char: Option<char> = None;
if !characters.is_empty() {
escaped_char = Some(characters.pop().unwrap());
}
escaped_char
}
fn parse_main(characters: &mut Vec<char>, current_arg: &mut String) -> Vec<String> { fn parse_main(characters: &mut Vec<char>, current_arg: &mut String) -> Vec<String> {
if characters.is_empty() { if characters.is_empty() {
vec![] vec![]
@ -32,7 +42,12 @@ fn parse_main(characters: &mut Vec<char>, current_arg: &mut String) -> Vec<Strin
parse_main(characters, current_arg) parse_main(characters, current_arg)
} }
} else if current_char == '\\' { } else if current_char == '\\' {
current_arg.push(characters.pop().unwrap()); let escaped_char = parse_backslash(characters);
if escaped_char.is_some() {
current_arg.push(escaped_char.unwrap());
}
parse_main(characters, current_arg) parse_main(characters, current_arg)
} else if current_char == '\'' { } else if current_char == '\'' {
current_arg.push_str(parse_quote(characters).as_str()); current_arg.push_str(parse_quote(characters).as_str());