allow variables to have a default value of ""

This commit is contained in:
Max Bradbury 2020-04-26 20:44:44 +01:00
parent b2911dbe1b
commit 0133731e97
1 changed files with 7 additions and 2 deletions

View File

@ -6,9 +6,14 @@ pub struct Variable {
impl From<String> for Variable { impl From<String> for Variable {
fn from(string: String) -> Variable { fn from(string: String) -> Variable {
let id_value: Vec<&str> = string.split('\n').collect(); let id_value: Vec<&str> = string.lines().collect();
let id = id_value[0].replace("VAR ", "").to_string(); let id = id_value[0].replace("VAR ", "").to_string();
let initial_value = id_value[1].to_string();
let initial_value = if id_value.len() == 1 {
"".to_string()
} else {
id_value[1..].join("")
};
Variable { id, initial_value } Variable { id, initial_value }
} }