Some checks failed
Run the tests for a working verification of xtcl. / build (ubuntu-20.04) (push) Failing after 50s
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
// @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;
|
|
}
|
|
|
|
// @name words
|
|
// @return Vec<String>
|
|
// @brief Split command into words.
|
|
// @param command: &str
|
|
pub fn words(command: &str) -> Vec<String> {
|
|
vec![]
|
|
}
|