12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576(**************************************************************************)(* *)(* 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_stringsletlowercasec=if(c>='A'&&c<='Z')||(c>='\192'&&c<='\214')||(c>='\216'&&c<='\222')thenunsafe_chr(codec+32)elsecletuppercasec=if(c>='a'&&c<='z')||(c>='\224'&&c<='\246')||(c>='\248'&&c<='\254')thenunsafe_chr(codec-32)elsecletlowercase_asciic=if(c>='A'&&c<='Z')thenunsafe_chr(codec+32)elsecletuppercase_asciic=if(c>='a'&&c<='z')thenunsafe_chr(codec-32)elsectypet=charletcomparec1c2=codec1-codec2letequal(c1:t)(c2:t)=comparec1c2=0