123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159open!ImportmoduleArray=Array0moduleString=String0includeChar0moduleT=structtypet=char[@@deriving_inlinecompare,hash,sexp,sexp_grammar]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->funcx;;lett_of_sexp=(char_of_sexp:Sexplib0.Sexp.t->t)letsexp_of_t=(sexp_of_char:t->Sexplib0.Sexp.t)let(t_sexp_grammar:tSexplib0.Sexp_grammar.t)=char_sexp_grammar[@@@end]letto_stringt=String.make1tletof_strings=matchString.lengthswith|1->s.[0]|_->failwithf"Char.of_string: %S"s();;endincludeTincludeIdentifiable.Make(structincludeTletmodule_name="Base.Char"end)letppfmtc=Caml.Format.fprintffmt"%C"c(* 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_compareletinvariant(_:t)=()letall=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)elseNoneletis_hex_digit=function|'0'..'9'|'a'..'f'|'A'..'F'->true|_->false;;letis_hex_digit_lower=function|'0'..'9'|'a'..'f'->true|_->false;;letis_hex_digit_upper=function|'0'..'9'|'A'..'F'->true|_->false;;letget_hex_digit_exn=function|'0'..'9'ast->to_intt-to_int'0'|'a'..'f'ast->to_intt-to_int'a'+10|'A'..'F'ast->to_intt-to_int'A'+10|t->Error.raise_s(Sexp.message"Char.get_hex_digit_exn: not a hexadecimal digit"["char",sexp_of_tt]);;letget_hex_digitt=ifis_hex_digittthenSome(get_hex_digit_exnt)elseNonemoduleO=structlet(>=)=(>=)let(<=)=(<=)let(=)=(=)let(>)=(>)let(<)=(<)let(<>)=(<>)endmoduleCaseless=structmoduleT=structtypet=char[@@deriving_inlinesexp,sexp_grammar]lett_of_sexp=(char_of_sexp:Sexplib0.Sexp.t->t)letsexp_of_t=(sexp_of_char:t->Sexplib0.Sexp.t)let(t_sexp_grammar:tSexplib0.Sexp_grammar.t)=char_sexp_grammar[@@@end]letcomparec1c2=compare(lowercasec1)(lowercasec2)lethash_fold_tstatet=hash_fold_charstate(lowercaset)lethasht=Hash.runhash_fold_ttendincludeTincludeComparable.Make(T)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