From a552f86af0f01a69540bfc78b3be06961fd1291f Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Sun, 31 May 2020 00:39:28 -0400 Subject: Fixed bug in gemini_to_canon_str --- gemini/mimeTextGemini.ml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'gemini') diff --git a/gemini/mimeTextGemini.ml b/gemini/mimeTextGemini.ml index ea370fd..e73be65 100644 --- a/gemini/mimeTextGemini.ml +++ b/gemini/mimeTextGemini.ml @@ -82,19 +82,20 @@ struct List.fold_right (fun l -> fun r -> (gemini_line_to_str l) ^ "\n" ^ r) g "" let gemini_to_canon_str g = - let in_pre = ref false in - let f l r = - match (l, !in_pre) with - | Pre s, true -> s ^ "\r\n" ^ r + let eol = "\r\n" in + let f (l : gemini_line) ((in_pre, r) : bool * string) = + match l, in_pre with | Pre s, false -> - let () = in_pre := true in - "```\r\n" ^ s ^ "\r\n" ^ r + (true, s ^ eol ^ "```" ^ eol ^ r) + | Pre s, true -> + (true, s ^ eol ^ r) | _, true -> - let () = in_pre := false in - "```\r\n" ^ (gemini_line_to_canon_str l) ^ "\r\n" ^ r - | _, false -> (gemini_line_to_canon_str l) ^ "\r\n" ^ r - in - List.fold_right f g "\r\n" + (false, (gemini_line_to_canon_str l) ^ eol ^ "```" ^ eol ^ r) + | _, false -> + (false, (gemini_line_to_canon_str l) ^ eol ^ r) in + let (_, s) = List.fold_right f g (false, "") in + s + let parse_string p s = match Angstrom.parse_string ~consume:All (p >>= return) s with -- cgit v1.2.3