(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: cocanwiki_cgi_args.ml,v 1.1 2004/09/24 10:44:55 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * This badly needs to become a standard part of the Cgi library. *) let split1_re = Pcre.regexp "\\?" let split2_re = Pcre.regexp "&" let split3_re = Pcre.regexp "=" let parse full_url = let url, qs = match Pcre.split ~rex:split1_re ~max:2 full_url with | [url] | [url;""] -> url, None | [url;qs] -> url, Some qs | _ -> assert false in let args = match qs with None -> [] | Some qs -> let args = Pcre.split ~rex:split2_re qs in let f arg = match Pcre.split ~rex:split3_re ~max:2 arg with | [] -> ("", "") | [key] -> (key, "") | [key;value] -> (key, value) | _ -> assert false in List.map f args in url, qs, args