uCharExt.mli 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. (*
  2. * UChar - Unicode (ISO-UCS) characters
  3. * Copyright (C) 2002, 2003 Yamagata Yoriyuki
  4. *
  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.
  10. *
  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.
  15. *
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  19. *)
  20. (** Unicode (ISO-UCS) characters.
  21. This module implements Unicode (actually ISO-UCS) characters. All
  22. 31-bit code points are allowed.
  23. *)
  24. (** Unicode characters. All 31-bit code points are allowed.*)
  25. type t
  26. exception Out_of_range
  27. (** [char_of u] returns the Latin-1 representation of [u].
  28. If [u] can not be represented by Latin-1, raises Out_of_range *)
  29. val char_of : t -> char
  30. (** [of_char c] returns the Unicode character of the Latin-1 character [c] *)
  31. val of_char : char -> t
  32. (** [code u] returns the Unicode code number of [u].
  33. If the value can not be represented by a positive integer,
  34. raise Out_of_range *)
  35. val code : t -> int
  36. (** [code n] returns the Unicode character with the code number [n].
  37. If n >= 2^32 or n < 0, raises [invalid_arg] *)
  38. val chr : int -> t
  39. (** [uint_code u] returns the Unicode code number of [u].
  40. The returned int is unsigned, that is, on 32-bit platforms,
  41. the sign bit is used for storing the 31-th bit of the code number. *)
  42. external uint_code : t -> int = "%identity"
  43. (** [chr_of_uint n] returns the Unicode character of the code number [n].
  44. [n] is interpreted as unsigned, that is, on 32-bit platforms,
  45. the sign bit is treated as the 31-th bit of the code number.
  46. If n exceeds 31-bit values, then raise [Invalid_arg]. *)
  47. val chr_of_uint : int -> t
  48. (** Unsafe version of {!UChar.chr_of_uint}.
  49. No check of its argument is performed. *)
  50. external unsafe_chr_of_uint : int -> t = "%identity"
  51. (** Equality by code point comparison *)
  52. val eq : t -> t -> bool
  53. (** [compare u1 u2] returns,
  54. a value > 0 if [u1] has a larger Unicode code number than [u2],
  55. 0 if [u1] and [u2] are the same Unicode character,
  56. a value < 0 if [u1] has a smaller Unicode code number than [u2]. *)
  57. val compare : t -> t -> int
  58. (** Aliases of [type t] *)
  59. type uchar = t
  60. (** Alias of [uint_code] *)
  61. val int_of_uchar : uchar -> int
  62. (** Alias of [chr_of_uint] *)
  63. val uchar_of_int : int -> uchar