Rule words to generate words from a command
All checks were successful
Run the tests for a working verification of xtcl. / build (ubuntu-20.04) (push) Successful in 45s
All checks were successful
Run the tests for a working verification of xtcl. / build (ubuntu-20.04) (push) Successful in 45s
This commit is contained in:
29
src/tcl.rs
29
src/tcl.rs
@@ -38,5 +38,32 @@ pub fn commands(tcl: &str) -> Vec<String> {
|
|||||||
// @brief Split command into words.
|
// @brief Split command into words.
|
||||||
// @param command: &str
|
// @param command: &str
|
||||||
pub fn words(command: &str) -> Vec<String> {
|
pub fn words(command: &str) -> Vec<String> {
|
||||||
vec![]
|
let mut words: Vec<String> = 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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user