diff --git a/src/parser/preparser/insert_semicolons.rs b/src/parser/preparser/insert_semicolons.rs index 1d171b8..da835b8 100644 --- a/src/parser/preparser/insert_semicolons.rs +++ b/src/parser/preparser/insert_semicolons.rs @@ -1,5 +1,9 @@ +use crate::utils::str_safe_split; + // Takes space normalised source code and adds semicolons where needed // May not work properly if string isn't space normalised beforehand pub fn insert_semicolons(raw: &str) -> String { + let _splits = str_safe_split(raw, vec![' ','\t']); + "".to_owned() } \ No newline at end of file diff --git a/src/utils.rs b/src/utils.rs index 7bbaded..325ba22 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ /// String safe splitting /// Strings in this case being literal strings in JavaScript source code -pub fn str_safe_split(to_split: &str, split_char: char) -> Vec { +pub fn str_safe_split(to_split: &str, split_chars: Vec) -> Vec { let mut current_str = String::new(); let mut matches = vec![]; @@ -52,7 +52,7 @@ pub fn str_safe_split(to_split: &str, split_char: char) -> Vec { if in_string { current_str.push(c.clone()); } else { - if c == split_char { + if split_chars.contains(&c) { matches.push(current_str); current_str = String::new(); } else { @@ -67,24 +67,24 @@ pub fn str_safe_split(to_split: &str, split_char: char) -> Vec { #[test] fn test_str_safe_split_1() { - let res = str_safe_split("this is a test", ' '); + let res = str_safe_split("this is a test", vec![' ']); assert_eq!(res, vec!["this","is","a","test"]); } #[test] fn test_str_safe_split_2() { - let res = str_safe_split("Quote \"test one\"", ' '); + let res = str_safe_split("Quote \"test one\"", vec![' ']); assert_eq!(res, vec!["Quote", "\"test one\""]); } #[test] fn test_str_safe_split_3() { - let res = str_safe_split("Quote \"test one\" with 'more quotes' and '`even quotes` in quotes'", ' '); + let res = str_safe_split("Quote \"test one\" with 'more quotes' and '`even quotes` in quotes'", vec![' ']); assert_eq!(res, vec!["Quote", "\"test one\"", "with", "'more quotes'", "and", "'`even quotes` in quotes'"]); } #[test] fn test_str_safe_split_4() { - let res = str_safe_split("Unfinished 'quote", ' '); + let res = str_safe_split("Unfinished 'quote", vec![' ']); assert_eq!(res, vec!["Unfinished", "'quote"]); } \ No newline at end of file