Commit 87214f7b authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-05-10 21:50:48 by cvscast] Fixed bug UTF-8

Original author: cvscast
Date: 2003-05-10 21:50:48+00:00
parent fadfc73d
......@@ -36,17 +36,17 @@ struct
| '\000'..'\127' as c ->
Char.code c, i + 1
| '\192'..'\223' as c ->
((Char.code c - 192) lsl 6) lor
((Char.code s.[i+1] - 128)), i + 2
((Char.code c land 0b11111) lsl 6) lor
((Char.code s.[i+1] land 0b111111)), i + 2
| '\224'..'\239' as c ->
((Char.code c - 192) lsl 12) lor
((Char.code s.[i+1] - 128) lsl 6) lor
((Char.code s.[i+2] - 128)), i + 3
((Char.code c land 0b1111) lsl 12) lor
((Char.code s.[i+1] land 0b111111) lsl 6) lor
((Char.code s.[i+2] land 0b111111)), i + 3
| '\240'..'\248' as c ->
((Char.code c - 192) lsl 18) lor
((Char.code s.[i+1] - 128) lsl 12) lor
((Char.code s.[i+2] - 128) lsl 6) lor
((Char.code s.[i+3] - 128)), i + 4
((Char.code c land 0b111) lsl 18) lor
((Char.code s.[i+1] land 0b111111) lsl 12) lor
((Char.code s.[i+2] land 0b111111) lsl 6) lor
((Char.code s.[i+3] land 0b111111)), i + 4
| _ -> failwith "Malformed UTF-8 bufffer"
let advance s i =
......@@ -78,7 +78,7 @@ struct
else if p <= 0xffff then (
(* Refuse writing surrogate pairs, and fffe, ffff *)
if (p >= 0xd800 & p < 0xe000) or (p >= 0xfffe) then
failwith "Encodings.Utf8.store";
failwith "Encodings.Utf8.store";
Buffer.add_char b (Char.chr (0xe0 lor (p lsr 12)));
Buffer.add_char b (Char.chr (0x80 lor ((p lsr 6) land 0x3f)));
Buffer.add_char b (Char.chr (0x80 lor (p land 0x3f)))
......
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