12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2010 Raphaël Proust, Jérôme Vouillon
* Laboratoire PPS - CNRS Université Paris Diderot
*
* 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, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)open!Importtyperegexp=Js.regExpJs.ttyperesult=Js.match_resultJs.tletregexps=new%jsJs.regExp_withFlags(Js.bytestrings)(Js.string"g")letregexp_case_folds=new%jsJs.regExp_withFlags(Js.bytestrings)(Js.string"gi")letregexp_with_flagsf=new%jsJs.regExp_withFlags(Js.bytestrings)(Js.string("g"^f))letblunt_str_array_getai=Js.to_bytestring(Js.Optdef.get(Js.array_getai)(fun()->assertfalse))letstring_matchrsi=r##.lastIndex:=i;Js.Opt.to_option(Js.Opt.map(r##exec(Js.bytestrings))Js.match_result)letsearchrsi=r##.lastIndex:=i;Js.Opt.to_option(Js.Opt.map(r##exec(Js.bytestrings))(funres_pre->letres=Js.match_resultres_preinres##.index,res))letsearch_forward=searchletmatched_stringr=blunt_str_array_getr0letmatched_groupri=Js.Optdef.to_option(Js.Optdef.map(Js.array_getri)Js.to_bytestring)letquote_repl_re=new%jsJs.regExp_withFlags(Js.string"[$]")(Js.string"g")letquote_repls=(Js.bytestrings)##replacequote_repl_re(Js.string"$$$$")letglobal_replacerss_by=r##.lastIndex:=0;Js.to_bytestring(Js.bytestrings)##(replacer(quote_repls_by))letreplace_firstrss_by=letflags=matchJs.to_boolr##.ignoreCase,Js.to_boolr##.multilinewith|false,false->Js.string""|false,true->Js.string"m"|true,false->Js.string"i"|true,true->Js.string"mi"inletr'=new%jsJs.regExp_withFlagsr##.sourceflagsinJs.to_bytestring(Js.bytestrings)##(replacer'(quote_repls_by))letlist_of_js_arraya=letrecauxaccuidx=ifidx<0thenaccuelseaux(blunt_str_array_getaidx::accu)(idx-1)inaux[](a##.length-1)letsplitrs=r##.lastIndex:=0;list_of_js_array(Js.str_array(Js.bytestrings)##(split_regExpr))letbounded_splitrsi=r##.lastIndex:=0;list_of_js_array(Js.str_array(Js.bytestrings)##(split_regExpLimitedri))(* More constructors *)letquote_re=regexp"[\\][()\\\\|+*.?{}^$]"letquotes=Js.to_bytestring(Js.bytestrings)##(replacequote_re(Js.string"\\$&"))letregexp_strings=regexp(quotes)letregexp_string_case_folds=regexp_case_fold(quotes)