1234567891011121314151617181920212223242526272829303132(* [Char0] defines char functions that are primitives or can be simply defined in terms of
[Caml.Char]. [Char0] is intended to completely express the part of [Caml.Char] that
[Base] uses -- no other file in Base other than char0.ml should use [Caml.Char].
[Char0] has few dependencies, and so is available early in Base's build order. All
Base files that need to use chars and come before [Base.Char] in build order should do
[module Char = Char0]. Defining [module Char = Char0] is also necessary because it
prevents ocamldep from mistakenly causing a file to depend on [Base.Char]. *)open!Import0letfailwithf=Printf.failwithfletescaped=Caml.Char.escapedletlowercase=Caml.Char.lowercase_asciiletto_int=Caml.Char.codeletunsafe_of_int=Caml.Char.unsafe_chrletuppercase=Caml.Char.uppercase_ascii(* We use our own range test when converting integers to chars rather than
calling [Caml.Char.chr] because it's simple and it saves us a function call
and the try-with (exceptions cost, especially in the world with backtraces). *)letint_is_oki=0<=i&&i<=255letmin_value=unsafe_of_int0letmax_value=unsafe_of_int255letof_inti=ifint_is_okithenSome(unsafe_of_inti)elseNoneletof_int_exni=ifint_is_okithenunsafe_of_intielsefailwithf"Char.of_int_exn got integer out of range: %d"i();;letequal(t1:char)t2=Poly.equalt1t2