1 (* "cic:/a/b/c.con" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c" |] *)
2 type uri = string array;;
8 let string_of_uri uri = uri.(Array.length uri - 2);;
9 let name_of_uri uri = uri.(Array.length uri - 1);;
10 let buri_of_uri uri = uri.(Array.length uri - 3);;
11 let depth_of_uri uri = Array.length uri - 2;;
13 (*CSC: ora e' diventato poco efficiente, migliorare *)
14 let relative_depth curi uri cookingsno =
15 let rec length_of_current_prefix l1 l2 =
17 (he1::tl1, he2::tl2) when he1 == he2 ->
18 1 + length_of_current_prefix tl1 tl2
22 length_of_current_prefix
23 (Array.to_list (Array.sub curi 0 (Array.length curi - (2 + cookingsno))))
24 (Array.to_list (Array.sub uri 0 (Array.length uri - 2)))
25 (*CSC: vecchio codice da eliminare
29 length_of_current_prefix (Array.to_list curi) (Array.to_list uri)
33 module OrderedStrings =
36 let compare (s1 : t) (s2 : t) = compare s1 s2
40 module SetOfStrings = Map.Make(OrderedStrings);;
42 (*CSC: commento obsoleto ed errato *)
43 (* Invariant: the map is the identity function, *)
44 (* i.e. (SetOfStrings.find str !set_of_uri) == str *)
45 let set_of_uri = ref SetOfStrings.empty;;
46 let set_of_prefixes = ref SetOfStrings.empty;;
48 (* similar to uri_of_string, but used for prefixes of uris *)
49 let normalize prefix =
51 SetOfStrings.find prefix !set_of_prefixes
54 set_of_prefixes := SetOfStrings.add prefix prefix !set_of_prefixes ;
58 exception IllFormedUri of string;;
64 let prefix_uri = curi ^ "/" ^ he
65 and name = List.hd (Str.split (Str.regexp "\.") he) in
66 [ normalize prefix_uri ; name ]
68 let prefix_uri = curi ^ "/" ^ he in
69 (normalize prefix_uri)::(aux prefix_uri tl)
70 | _ -> raise (IllFormedUri str)
72 let tokens = (Str.split (Str.regexp "/") str) in
74 let (ty, sp) = (List.hd tokens, List.tl tokens) in
78 let uri_of_string str =
80 SetOfStrings.find str !set_of_uri
83 let uri = Array.of_list (mk_prefixes str) in
84 set_of_uri := SetOfStrings.add str uri !set_of_uri ;