123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102open!ImportmoduleArray=Array0moduleString=String0includeChar0moduleT=structtypet=char[@@deriving_inlinecompare,hash,sexp]letcompare=(compare_char:t->t->int)let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_charand(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_charinfunx->funcxlett_of_sexp=(char_of_sexp:Ppx_sexp_conv_lib.Sexp.t->t)letsexp_of_t=(sexp_of_char:t->Ppx_sexp_conv_lib.Sexp.t)[@@@end]letto_stringt=String.make1tletof_strings=matchString.lengthswith|1->s.[0]|_->failwithf"Char.of_string: %S"s();;endincludeTincludeIdentifiable.Make(structincludeTletmodule_name="Base.Char"end)(* Open replace_polymorphic_compare after including functor instantiations so they do not
shadow its definitions. This is here so that efficient versions of the comparison
functions are available within this module. *)open!Char_replace_polymorphic_compareletall=Array.init256~f:unsafe_of_int|>Array.to_listletis_lowercase=function|'a'..'z'->true|_->false;;letis_uppercase=function|'A'..'Z'->true|_->false;;letis_print=function|' '..'~'->true|_->false;;letis_whitespace=function|'\t'|'\n'|'\011'(* vertical tab *)|'\012'(* form feed *)|'\r'|' '->true|_->false;;letis_digit=function|'0'..'9'->true|_->false;;letis_alpha=function|'a'..'z'|'A'..'Z'->true|_->false;;(* Writing these out, instead of calling [is_alpha] and [is_digit], reduces
runtime by approx. 30% *)letis_alphanum=function|'a'..'z'|'A'..'Z'|'0'..'9'->true|_->false;;letget_digit_unsafet=to_intt-to_int'0'letget_digit_exnt=ifis_digittthenget_digit_unsafetelsefailwithf"Char.get_digit_exn %C: not a digit"t();;letget_digitt=ifis_digittthenSome(get_digit_unsafet)elseNonemoduleO=structlet(>=)=(>=)let(<=)=(<=)let(=)=(=)let(>)=(>)let(<)=(<)let(<>)=(<>)end(* Include type-specific [Replace_polymorphic_compare] at the end, after
including functor application that could shadow its definitions. This is
here so that efficient versions of the comparison functions are exported by
this module. *)includeChar_replace_polymorphic_compare