123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141(*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program 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; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program 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.
*)(* Utils, some from stdext originally *)(**
* @group Performance Monitoring
*)exceptionParse_errormoduleBoundedFloat:sigtypet=privatefloattypeentry_fun=Clamp|To_Nanvalof_float:minimum:float->maximum:float->f:entry_fun->float->tvalto_float:t->floatend=structtypet=floattypeentry_fun=Clamp|To_Nanletof_float~minimum~maximum~fx=matchfwith|Clamp->minmaximum(maxminimumx)|To_Nanwhenx<minimum||x>maximum->nan|To_Nan->xletto_floatx=xendletisnanx=matchclassify_floatxwithFP_nan->true|_->falseletarray_indexea=letlen=Array.lengthainletrecchecki=iflen<=ithen-1elseifa.(i)=ethenielsecheck(i+1)incheck0letarray_removena=Array.append(Array.suba0n)(Array.suba(n+1)(Array.lengtha-n-1))letfilter_mapflist=letrecinneraccl=matchlwith|[]->List.revacc|x::xs->letacc=matchfxwithSomeres->res::acc|None->accininneraccxsininner[]listletrecsetify=function|[]->[]|x::xs->ifList.memxxsthensetifyxselsex::setifyxs(** C# and JS representation of special floats are 'NaN' and 'Infinity' which
are different from ocaml's native representation. Caml is fortunately more
forgiving when doing a float_of_string, and can cope with these forms, so
we make a generic float_to_string function here *)letf_to_sf=matchclassify_floatfwith|FP_normal|FP_subnormal->Printf.sprintf"%0.4f"f|FP_nan->"NaN"|FP_infinite->iff>0.0then"Infinity"else"-Infinity"|FP_zero->"0.0"moduleXmlm_utils=structlettagn=(("",n),[])letstart_tagn=`El_start(tagn)letacceptsi=ifXmlm.inputi=sthen()elseraiseParse_errorletreciter_seqelacci=matchXmlm.peekiwith|`El_start_->iter_seqel(eli::acc)i|`El_end->List.revacc|_->raiseParse_errorletget_elni=ifXmlm.inputi=start_tagnthen(letd=matchXmlm.peekiwith|`Datad->ignore(Xmlm.inputi);d|`El_end->""|_->raiseParse_errorinaccept`El_endi;d)elseraiseParse_errorletrecread_alltread_fiacc=ifXmlm.peeki=start_tagtthenread_alltread_fi(read_fi::acc)elseList.revaccletread_blocktfi=accept(start_tagt)i;letres=fiinaccept`El_endi;resend