2 * UChar - Unicode (ISO-UCS) characters
3 * Copyright (C) 2002, 2003 Yamagata Yoriyuki
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version,
9 * with the special exception on linking described in file LICENSE.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 exception Out_of_range
25 external unsafe_chr_of_uint
: int -> t
= "%identity"
26 external uint_code
: t
-> int = "%identity"
29 if c
>= 0 && c
< 0x100 then Char.chr c
else raise Out_of_range
31 let of_char = Char.code
33 let code c
= if c
>= 0 then c
else raise Out_of_range
36 if n
>= 0 && n
lsr 31 = 0 then n
else invalid_arg
"UChar.chr"
38 let chr_of_uint n
= if n
lsr 31 = 0 then n
else invalid_arg
"UChar.uint_chr"
40 let eq (u1
: t
) (u2
: t
) = u1
= u2
42 let sgn = (u1
lsr 16) - (u2
lsr 16) in
43 if sgn = 0 then (u1
land 0xFFFF) - (u2
land 0xFFFF) else sgn
47 let int_of_uchar u
= uint_code u
48 let uchar_of_int n
= chr_of_uint n