diff --git a/src/tcl.rs b/src/tcl.rs new file mode 100644 index 0000000..71d97fe --- /dev/null +++ b/src/tcl.rs @@ -0,0 +1,34 @@ +// @name commands +// @return Vec +// @brief Extract commands by semicolon and newline +// @param tcl: &str +pub fn commands(tcl: &str) -> Vec { + let mut commands: Vec = 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; +}