Add commands function to separate strings

This commit is contained in:
Yannick Reiß 2025-09-03 00:36:27 +02:00
parent c7ed3ac13e
commit d129dc76ac
1 changed files with 34 additions and 0 deletions

34
src/tcl.rs Normal file
View File

@ -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;
}