123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145# 1 "Camomile/public/uCS4.ml"(** UCS4 encoded string. The type is the bigarray of 32-bit integers.
Bigarray.cma or Bigarray.cmxa must be linked when this module is used. *)(* Copyright (C) 2002, 2003, 2004 Yamagata Yoriyuki. *)(* This library is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Lesser General Public License *)(* as published by the Free Software Foundation; either version 2 of *)(* the License, or (at your option) any later version. *)(* As a special exception to the GNU Library General Public License, you *)(* may link, statically or dynamically, a "work that uses this library" *)(* with a publicly distributed version of this library to produce an *)(* executable file containing portions of this library, and distribute *)(* that executable file under terms of your choice, without any of the *)(* additional requirements listed in clause 6 of the GNU Library General *)(* Public License. By "a publicly distributed version of this library", *)(* we mean either the unmodified Library as distributed by the authors, *)(* or a modified version of this library that is distributed under the *)(* conditions defined in clause 3 of the GNU Library General Public *)(* License. This exception does not however invalidate any other reasons *)(* why the executable file might be covered by the GNU Library General *)(* Public License . *)(* This library is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)(* Lesser General Public License for more details. *)(* You should have received a copy of the GNU Lesser General Public *)(* License along with this library; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)(* USA *)(* You can contact the authour by sending email to *)(* yoriyuki.y@gmail.com *)openBigarray(* UCS4 encoded string. the type is bigarray of 32-bit integers. *)typet=(int32,int32_elt,c_layout)Array1.ttypeindex=intexceptionMalformed_codeletrecvalidate_aux(a:t)i=ifi>=Array1.dimathen()elsematchInt32.to_int(Int32.shift_righta.{i}31)with0->validate_auxa(i+1)|_->raiseMalformed_codeletvalidate(a:t)=validate_auxa0letlook(a:t)i:UChar.t=UChar.chr_of_uint(Int32.to_inta.{i})letlength(a:t)=Array1.dimaletnext_i=i+1letprev_i=i-1letmove(_:t)ic=i+cletfirst_=0letlast(a:t)=Array1.dima-1letout_of_range(a:t)i=i<0||i>=Array1.dimaletcompare_index_ij=i-jletnth(_:t)c=cletget(a:t)c=lookacletreciter_auxproc(a:t)i=ifi>=Array1.dimathen()elsebeginproc(lookai);iter_auxproca(i+1)endletiterproc(a:t)=iter_auxproca0letinitlenf=leta=Array1.createint32c_layoutleninfori=0tolen-1doa.{i}<-Int32.of_int(UChar.uint_code(fi))done;amoduleBuf=structtypebuf={init_size:int;mutablepos:index;mutablecontents:t}letcreaten=letcontents=Array1.createint32c_layoutnin{init_size=n;pos=0;contents=contents}letclearbuf=buf.pos<-0letresetbuf=buf.contents<-Array1.createint32c_layoutbuf.init_size;buf.pos<-0letcontentsbuf=leta=Array1.createint32c_layoutbuf.posinletsrc=Array1.subbuf.contents0buf.posinArray1.blitsrca;aletresizebufn=ifArray1.dimbuf.contents>=nthen()elseleta=Array1.createint32c_layout(2*n)inleta'=Array1.suba0(Array1.dimbuf.contents)inArray1.blitbuf.contentsa';buf.contents<-aletadd_charbufu=resizebuf(buf.pos+1);buf.contents.{buf.pos}<-Int32.of_int(UChar.uint_codeu);buf.pos<-buf.pos+1letadd_stringbuf(a:t)=letlen=buf.pos+Array1.dimainresizebuflen;letb=Array1.subbuf.contentsbuf.pos(Array1.dima)inArray1.blitab;buf.pos<-lenletadd_bufferbuf1buf2=letlen=buf1.pos+buf2.posinresizebuf1len;leta=Array1.subbuf2.contents0buf2.posinletb=Array1.subbuf1.contentsbuf1.posbuf2.posinArray1.blitab;buf1.pos<-lenendletcompare(a:t)(b:t)=matchArray1.dima-Array1.dimbwith0->Pervasives.compareab|sgn->sgn