123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106includeUchar(*
(*
include Uchar
*)
type t = int
let min = 0
let max = 0x10FFFF
let lo_bound = 0xD7FF
let hi_bound = 0xE000
let succ u =
if u = lo_bound then
hi_bound
else if u = max then
invalid_arg "Uchar.succ"
else
succ u
let pred u =
if u = hi_bound then
lo_bound
else if u = min then
invalid_arg "Uchar.pred"
else
pred u
let is_valid i =
min <= i && i <= lo_bound || hi_bound <= i && i <= max
let of_int i =
if is_valid i then
i
else
invalid_arg "Uchar.of_int"
let unsafe_of_int i =
i
let to_int i =
i
let is_char u =
u < 0x100
let of_char c =
Char.code c
let to_char u =
if is_char u then
Char.unsafe_chr u
else
invalid_arg "Uchar.to_char"
let unsafe_to_char u =
Char.unsafe_chr u
let equal : t -> t -> bool = ( = )
let compare : t -> t -> int = compare
let hash = to_int
*)letrep'=0xFFFDtypeutf_decode=intletvalid_bit=27letdecode_bits=24letutf_decode_is_validd=(dlsrvalid_bit)=1letutf_decode_lengthd=(dlsrdecode_bits)land0b111letutf_decode_uchard=unsafe_of_int(dland0xFFFFFF)letutf_decodenu=((8lorn)lsldecode_bits)lor(to_intu)letutf_decode_invalidn=(nlsldecode_bits)lorrep'letutf_8_byte_lengthu=matchto_intuwith|uwhenu<0->assertfalse|uwhenu<=0x007F->1|uwhenu<=0x07FF->2|uwhenu<=0xFFFF->3|uwhenu<=0x10FFFF->4|_->assertfalseletutf_16_byte_lengthu=matchto_intuwith|uwhenu<0->assertfalse|uwhenu<=0xFFFF->2|uwhenu<=0x10FFFF->4|_->assertfalse(*
let bom = unsafe_of_int 0xFEFF
let rep = unsafe_of_int rep'
*)