From 2a05453f8ea08a9ba6d9032b819ec48da3ac9d2f Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Wed, 3 Sep 2025 06:06:33 +0200 Subject: [PATCH] Rule words to generate words from a command --- src/tcl.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/tcl.rs b/src/tcl.rs index 79a4eda..7d9fcf5 100644 --- a/src/tcl.rs +++ b/src/tcl.rs @@ -38,5 +38,32 @@ pub fn commands(tcl: &str) -> Vec { // @brief Split command into words. // @param command: &str pub fn words(command: &str) -> Vec { - vec![] + let mut words: Vec = vec![]; + let mut new_word: String = String::new(); + let mut quote: bool = false; + + for character in command.chars() { + if quote { + new_word.push(character); + if character == '"' { + quote = false; + } + } else { + match character { + ' ' => { + words.push(new_word.clone()); + new_word = String::new(); + } + '"' => { + new_word.push(character); + quote = true; + } + _ => new_word.push(character), + } + } + } + + words.push(new_word.clone()); + + return words; }