Compare commits
2 Commits
2a05453f8e
...
20330f746f
Author | SHA1 | Date |
---|---|---|
|
20330f746f | |
|
47bf17cb0b |
23
src/tcl.rs
23
src/tcl.rs
|
@ -67,3 +67,26 @@ pub fn words(command: &str) -> Vec<String> {
|
|||
|
||||
return words;
|
||||
}
|
||||
|
||||
// @name comments
|
||||
// @return String
|
||||
// @brief Remove all comments.
|
||||
// @param tcl_script: &str
|
||||
pub fn comments(tcl_script: &str) -> String {
|
||||
let mut toggle_comment: bool = false;
|
||||
let mut cleaned_tcl_script: String = String::new();
|
||||
for character in tcl_script.chars() {
|
||||
if toggle_comment {
|
||||
if character == '\n' {
|
||||
toggle_comment = false;
|
||||
}
|
||||
} else {
|
||||
cleaned_tcl_script.push(character);
|
||||
if character == ';' || character == '\n' {
|
||||
toggle_comment = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cleaned_tcl_script;
|
||||
}
|
||||
|
|
15
src/tests.rs
15
src/tests.rs
|
@ -1,5 +1,5 @@
|
|||
#[cfg(test)]
|
||||
use crate::tcl::{commands, words};
|
||||
use crate::tcl::{commands, comments, words};
|
||||
|
||||
#[test]
|
||||
fn test_commands_working() {
|
||||
|
@ -66,3 +66,16 @@ fn test_words_quoted() {
|
|||
let case: Vec<String> = words(testcase);
|
||||
assert_eq!(case, verify);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_comments() {
|
||||
let testcase_1: &str = "test#noreplacement";
|
||||
let testcase_2: &str = ";#replace_this\n";
|
||||
let verify_1: &str = "test#noreplacement";
|
||||
let verify_2: &str = ";";
|
||||
let case_1: String = comments(testcase_1);
|
||||
let case_2: String = comments(testcase_2);
|
||||
|
||||
assert_eq!(verify_1, case_1.as_str());
|
||||
assert_eq!(verify_2, case_2.as_str());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue