Add commands function to separate strings
This commit is contained in:
parent
c7ed3ac13e
commit
d129dc76ac
|
@ -0,0 +1,34 @@
|
||||||
|
// @name commands
|
||||||
|
// @return Vec<String>
|
||||||
|
// @brief Extract commands by semicolon and newline
|
||||||
|
// @param tcl: &str
|
||||||
|
pub fn commands(tcl: &str) -> Vec<String> {
|
||||||
|
let mut commands: Vec<String> = vec![];
|
||||||
|
let mut quote: bool = false;
|
||||||
|
let mut new_command: String = String::new();
|
||||||
|
|
||||||
|
for character in tcl.chars() {
|
||||||
|
if quote {
|
||||||
|
new_command.push(character);
|
||||||
|
if character == '"' {
|
||||||
|
quote = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match character {
|
||||||
|
'\n' | ';' => {
|
||||||
|
commands.push(new_command.clone());
|
||||||
|
new_command = String::new();
|
||||||
|
}
|
||||||
|
'"' => {
|
||||||
|
new_command.push(character);
|
||||||
|
quote = true;
|
||||||
|
}
|
||||||
|
_ => new_command.push(character),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.push(new_command);
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
Loading…
Reference in New Issue