Compare commits
No commits in common. "2a05453f8ea08a9ba6d9032b819ec48da3ac9d2f" and "ac23fedf24b777a8f01d85313c39fb66c293bde2" have entirely different histories.
2a05453f8e
...
ac23fedf24
29
src/tcl.rs
29
src/tcl.rs
|
@ -38,32 +38,5 @@ 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> {
|
||||||
let mut words: Vec<String> = 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;
|
|
||||||
}
|
}
|
||||||
|
|
14
src/tests.rs
14
src/tests.rs
|
@ -52,17 +52,3 @@ fn test_words_simple() {
|
||||||
let case: Vec<String> = words(testcase);
|
let case: Vec<String> = words(testcase);
|
||||||
assert_eq!(case, verify);
|
assert_eq!(case, verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_words_quoted() {
|
|
||||||
let testcase: &str = "routine \"argument with spaces\" 1234 0x543";
|
|
||||||
let verify: Vec<String> = vec![
|
|
||||||
String::from("routine"),
|
|
||||||
String::from("\"argument with spaces\""),
|
|
||||||
String::from("1234"),
|
|
||||||
String::from("0x543"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let case: Vec<String> = words(testcase);
|
|
||||||
assert_eq!(case, verify);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue