Commit ab031336 authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Fix an off-by-one error when translating XML string from utf-8 to iso/ascii

(fixes a bug in print_xml).
parent 29dbd1be
Pipeline #145 passed with stages
in 6 minutes and 47 seconds
......@@ -17,15 +17,15 @@ let convert ~(in_enc : [ `Enc_utf8 ]) ~(out_enc : [ `Enc_iso88591|`Enc_ascii ])
let buff = Buffer.create (range_len lsl 2) in
let open Encodings in
let in_s = Utf8.mk s in
let ulen = Utf8.mk_idx range_len in
let rec loop idx =
if idx >= ulen then Buffer.contents buff else
let last = Utf8.mk_idx (range_pos + range_len) in
let rec loop idx =
if idx >= last then Buffer.contents buff else
let code_point, nidx = Utf8.next in_s idx in
let () =
if code_point > 127 then Buffer.add_string buff (subst code_point)
else
Buffer.add_char buff (Char.unsafe_chr code_point)
in loop nidx
in loop nidx
in
loop (Utf8.mk_idx range_pos)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment