From d955f4ee71189401e20cad8828934ec0faba674c Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Thu, 23 Apr 2020 06:50:38 +0100 Subject: [PATCH] fix ending from string (allow "END " in dialogue, and multi-line dialogues) --- src/ending.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/ending.rs b/src/ending.rs index 06867a3..b66a7dd 100644 --- a/src/ending.rs +++ b/src/ending.rs @@ -7,17 +7,9 @@ pub struct Ending { impl From for Ending { fn from(string: String) -> Ending { - let string = string.replace("END ", ""); - // todo this is wrong - we shouldn't be splitting on lines - let id_dialogue: Vec<&str> = string.lines().collect(); - let id = id_dialogue[0].to_string(); - - let dialogue = if id_dialogue.len() > 1 { - id_dialogue[1] - } else { - "" - } - .to_string(); + let lines: Vec<&str> = string.lines().collect(); + let id = lines[0].replace("END ", "").to_string(); + let dialogue = lines[1..].join(""); Ending { id, dialogue } }