12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152(* Copyright (C) 2017--2019 Petter A. Urkedal <paurkedal@gmail.com>
*
* 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 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* 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, see <http://www.gnu.org/licenses/>.
*)openCaqti_common_privletlinear_param_lengthtempl=letrecloop=function|Caqti_query.L_->ident|Caqti_query.Q_->succ|Caqti_query.P_->succ|Caqti_query.Sfrags->List.foldloopfragsinlooptempl0letnonlinear_param_lengthtempl=letrecloop=function|Caqti_query.L_->ident|Caqti_query.Q_->ident|Caqti_query.Pn->max(n+1)|Caqti_query.Sfrags->List.foldloopfragsinlooptempl0letlinear_param_ordertempl=leta=Array.make(nonlinear_param_lengthtempl)[]inletrecloop=function|Caqti_query.L_->ident|Caqti_query.Qs->fun(j,quotes)->(j+1,(j,s)::quotes)|Caqti_query.Pi->fun(j,quotes)->a.(i)<-j::a.(i);(j+1,quotes)|Caqti_query.Sfrags->List.foldloopfragsinlet_,quotes=looptempl(0,[])in(Array.to_lista,List.revquotes)letlinear_query_stringtempl=letbuf=Buffer.create64inletrecloop=function|Caqti_query.Ls->Buffer.add_stringbufs|Caqti_query.Q_|Caqti_query.P_->Buffer.add_charbuf'?'|Caqti_query.Sfrags->List.iterloopfragsinlooptempl;Buffer.contentsbuf