summaryrefslogtreecommitdiff
path: root/gemini
diff options
context:
space:
mode:
authorRyan Kavanagh <rak@rak.ac>2020-05-31 00:39:28 -0400
committerRyan Kavanagh <rak@rak.ac>2020-05-31 00:39:28 -0400
commita552f86af0f01a69540bfc78b3be06961fd1291f (patch)
tree80ffed24bb36842bf76850bf48dc007e0e7d0495 /gemini
parentFixed compilation errors in bin (diff)
Fixed bug in gemini_to_canon_str
Diffstat (limited to 'gemini')
-rw-r--r--gemini/mimeTextGemini.ml23
1 files changed, 12 insertions, 11 deletions
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