diff --git a/src/core/CCChar.ml b/src/core/CCChar.ml index 07905d8f..848594a0 100644 --- a/src/core/CCChar.ml +++ b/src/core/CCChar.ml @@ -12,6 +12,10 @@ let compare = Char.compare let pp = Buffer.add_char let print = Format.pp_print_char +let of_int_exn = Char.chr +let of_int c = try Some (of_int_exn c) with _ -> None +let to_int = Char.code + let lowercase_ascii c = if c >= 'A' && c <= 'Z' then Char.unsafe_chr (Char. code c + 32) diff --git a/src/core/CCChar.mli b/src/core/CCChar.mli index 33e768e7..351e2617 100644 --- a/src/core/CCChar.mli +++ b/src/core/CCChar.mli @@ -17,5 +17,18 @@ val uppercase_ascii : t -> t (** See {!Char} @since 0.20 *) +val of_int_exn : int -> t +(** Alias to {!Char.chr} + @raise Invalid_argument if the int is not within [0,...,255] + @since NEXT_RELEASE *) + +val of_int : int -> t option +(** Safe version of {!of_int} + @since NEXT_RELEASE *) + +val to_int : t -> int +(** Alias to {!Char.code} + @since NEXT_RELEASE *) + val pp : Buffer.t -> t -> unit val print : Format.formatter -> t -> unit