ocaml-containers/src/core/CCChar.ml
Fardale 0dafceb708 Adding to_string (#270)
* add `CCArray.to_string`
* add `CCArrayLabels.to_string`
* add `CCList.to_string`
* add `CCListLabels.to_string`
* add `CCChar.to_string`
* add `CCPair.to_string`
* add `CCHeap.to_string`
* add `CCSet.to_string`
* add `CCVector.to_string`
2019-10-30 14:26:52 -05:00

31 lines
690 B
OCaml

(* This file is free software, part of containers. See file "license" for more details. *)
(** {1 Utils around char}
@since 0.14 *)
open CCShims_
include Char
let equal (a:char) b = Stdlib.(=) a b
let pp_buf = Buffer.add_char
let pp = 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 to_string c = String.make 1 c
(*$Q to_string
(Q.string_of_size (Q.Gen.return 1)) (fun s -> to_string s.[0] = s)
*)
let lowercase_ascii = function
| 'A'..'Z' as c -> Char.unsafe_chr (Char.code c + 32)
| c -> c
let uppercase_ascii = function
| 'a'..'z' as c -> Char.unsafe_chr (Char.code c - 32)
| c -> c