1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* order, uri, (which, constructor) *)
27 type uri = Uri of int * string * (int * int option ) option
31 let string_of_uri = function
33 | Uri (_,s,Some (i,None)) ->
34 s ^ "#xpointer(1/" ^ string_of_int (i+1) ^ ")"
35 | Uri (_,s,Some (i, Some k)) ->
36 s ^ "#xpointer(1/" ^ string_of_int (i+1) ^ "/" ^ string_of_int (k+1) ^ ")"
39 module OrderedStrings =
42 let compare (s1 : t) (s2 : t) = compare s1 s2
46 module MapStringsToUri = Map.Make(OrderedStrings);;
48 let set_of_uri = ref MapStringsToUri.empty;;
50 let uri_of_string_aux =
51 let counter = ref 0 in fun s ->
54 let sharp = String.rindex s '#' in
55 let pre = String.sub s 0 sharp in
56 let ind = String.sub s (sharp+12) (String.length s - (sharp+13)) in
58 let slash = String.rindex ind '/' in
59 let indno = String.sub ind 0 slash in
60 let constr = String.sub ind (slash+1) (String.length ind - (slash+1)) in
61 Uri(!counter,pre,Some(int_of_string indno-1,Some(int_of_string constr-1)))
62 with Not_found -> Uri (!counter,pre,Some (int_of_string ind-1, None))
63 with Not_found -> Uri (!counter,s,None)
68 MapStringsToUri.find s !set_of_uri
70 let new_uri = uri_of_string_aux s in
71 set_of_uri := MapStringsToUri.add s new_uri !set_of_uri;
75 let nuri_of_ouri u indinfo =
76 uri_of_string (string_of_uri (Uri(0,UriManager.string_of_uri u,indinfo)))
80 UriManager.uri_of_string (string_of_uri u)