123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Character operations *)externalcode:char->int="%identity"externalunsafe_chr:int->char="%identity"letchrn=ifn<0||n>255theninvalid_arg"Char.chr"elseunsafe_chrnexternalbytes_create:int->bytes="caml_create_bytes"externalbytes_unsafe_set:bytes->int->char->unit="%bytes_unsafe_set"externalunsafe_to_string:bytes->string="%bytes_to_string"letescaped=function|'\''->"\\'"|'\\'->"\\\\"|'\n'->"\\n"|'\t'->"\\t"|'\r'->"\\r"|'\b'->"\\b"|' '..'~'asc->lets=bytes_create1inbytes_unsafe_sets0c;unsafe_to_strings|c->letn=codecinlets=bytes_create4inbytes_unsafe_sets0'\\';bytes_unsafe_sets1(unsafe_chr(48+n/100));bytes_unsafe_sets2(unsafe_chr(48+(n/10)mod10));bytes_unsafe_sets3(unsafe_chr(48+nmod10));unsafe_to_stringsletlowercase_ascii=function|'A'..'Z'asc->unsafe_chr(codec+32)|c->cletuppercase_ascii=function|'a'..'z'asc->unsafe_chr(codec-32)|c->ctypet=charletcomparec1c2=codec1-codec2letequal(c1:t)(c2:t)=comparec1c2=0externalseeded_hash_param:int->int->int->'a->int="caml_hash"[@@noalloc]letseeded_hashseedx=seeded_hash_param10100seedxlethashx=seeded_hash_param101000xmoduleAscii=struct(* Characters *)letmin='\x00'letmax='\x7F'(* Predicates *)letis_valid=function'\x00'..'\x7F'->true|_->falseletis_upper=function'A'..'Z'->true|_->falseletis_lower=function'a'..'z'->true|_->falseletis_letter=function'A'..'Z'|'a'..'z'->true|_->falseletis_alphanum=function|'0'..'9'|'A'..'Z'|'a'..'z'->true|_->falseletis_white=function' '|'\t'..'\r'->true|_->falseletis_blank=function' '|'\t'->true|_->falseletis_graphic=function'!'..'~'->true|_->falseletis_print=function' '..'~'->true|_->falseletis_control=function'\x00'..'\x1F'|'\x7F'->true|_->false(* Decimal digits *)letis_digit=function'0'..'9'->true|_->falseletdigit_to_int=function|'0'..'9'asc->codec-0x30|c->invalid_arg(escapedc^": not a decimal digit")letdigit_of_intn=unsafe_chr(0x30+abs(nmod10))(* Hexadecimal digits *)letis_hex_digit=function|'0'..'9'|'A'..'F'|'a'..'f'->true|_->falselethex_digit_to_int=function|'0'..'9'asc->codec-0x30|'A'..'F'asc->10+codec-0x41|'a'..'f'asc->10+codec-0x61|c->invalid_arg(escapedc^": not a hexadecimal digit")letlower_hex_digit_of_intn=letd=abs(nmod16)inunsafe_chr(ifd<10then0x30+delse0x57+d)letupper_hex_digit_of_intn=letd=abs(nmod16)inunsafe_chr(ifd<10then0x30+delse0x37+d)(* Casing transforms *)letlowercase=lowercase_asciiletuppercase=uppercase_asciiend