From: Enrico Tassi Date: Wed, 19 Jan 2005 15:26:12 +0000 (+0000) Subject: fixed #xpointer handling in uri_of_string. new examples : X-Git-Tag: V_0_1_0~124 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=17b586f742e5c58501d62c81b6c517f5ba039f1d;p=helm.git fixed #xpointer handling in uri_of_string. new examples : "cic:/a/b/c.con" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "" |] "cic:/a/b/c.ind#xpointer(1/1)" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "#xpointer(1/1)" |] "cic:/a/b/c.ind#xpointer(1/1/1)" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "#xpointer(1/1/1)" |] --- diff --git a/helm/ocaml/urimanager/uriManager.ml b/helm/ocaml/urimanager/uriManager.ml index 3028cf2b9..cd7f9a119 100644 --- a/helm/ocaml/urimanager/uriManager.ml +++ b/helm/ocaml/urimanager/uriManager.ml @@ -23,17 +23,29 @@ * http://cs.unibo.it/helm/. *) -(* "cic:/a/b/c.con" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c" |] *) +(* +* "cic:/a/b/c.con" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "" |] +* "cic:/a/b/c.ind#xpointer(1/1)" => +* [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "#xpointer(1/1)" |] +* "cic:/a/b/c.ind#xpointer(1/1/1)" => +* [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c"; "#xpointer(1/1/1)" |] +*) type uri = string array;; let eq uri1 uri2 = uri1 == uri2 ;; -let string_of_uri uri = uri.(Array.length uri - 2);; -let name_of_uri uri = uri.(Array.length uri - 1);; -let buri_of_uri uri = uri.(Array.length uri - 3);; -let depth_of_uri uri = Array.length uri - 2;; +let string_of_uri uri = + match uri.(Array.length uri - 1) with + | "" -> + uri.(Array.length uri - 3) + | _ -> + String.concat "#" + [ uri.(Array.length uri - 3); uri.(Array.length uri - 1) ] +let name_of_uri uri = uri.(Array.length uri - 2);; +let buri_of_uri uri = uri.(Array.length uri - 4);; +let depth_of_uri uri = Array.length uri - 3;; module OrderedStrings = struct @@ -62,7 +74,7 @@ let normalize prefix = exception IllFormedUri of string;; -let mk_prefixes str = +let mk_prefixes str xpointer = let rec aux curi = function [he] -> @@ -81,17 +93,28 @@ let mk_prefixes str = with Failure "hd" | Failure "tl" -> raise (IllFormedUri str)) in - aux ty sp + (aux ty sp) @ [xpointer] +;; + + +let sharp_rex = + Str.regexp "#" ;; let uri_of_string str = - try - SetOfStrings.find str !set_of_uri - with - Not_found -> - let uri = Array.of_list (mk_prefixes str) in - set_of_uri := SetOfStrings.add str uri !set_of_uri ; - uri + let base, xpointer = + match Str.split sharp_rex str with + | [base] -> base,"" + | [base; xpointer] -> base,xpointer + | _ -> raise (IllFormedUri str) + in + try + SetOfStrings.find str !set_of_uri + with + Not_found -> + let uri = Array.of_list (mk_prefixes base xpointer) in + set_of_uri := SetOfStrings.add str uri !set_of_uri ; + uri ;; let cicuri_of_uri uri = @@ -104,7 +127,7 @@ let cicuri_of_uri uri = uri else let newuri = Array.copy uri in - newuri.(Array.length uri - 2) <- newcompleteuri ; + newuri.(Array.length uri - 3) <- newcompleteuri ; newuri ;; @@ -114,7 +137,7 @@ let annuri_of_uri uri = uri else let newuri = Array.copy uri in - newuri.(Array.length uri - 2) <- completeuri ^ ".ann" ; + newuri.(Array.length uri - 3) <- completeuri ^ ".ann" ; newuri ;; @@ -126,7 +149,7 @@ let bodyuri_of_uri uri = let struri = string_of_uri uri in if Str.string_match (Str.regexp ".*\\.con$") (string_of_uri uri) 0 then let newuri = Array.copy uri in - newuri.(Array.length uri - 2) <- struri ^ ".body" ; + newuri.(Array.length uri - 3) <- struri ^ ".body" ; Some newuri else None @@ -135,7 +158,7 @@ let bodyuri_of_uri uri = let innertypesuri_of_uri uri = let cicuri = cicuri_of_uri uri in let newuri = Array.copy cicuri in - newuri.(Array.length cicuri - 2) <- (string_of_uri cicuri) ^ ".types" ; + newuri.(Array.length cicuri - 3) <- (string_of_uri cicuri) ^ ".types" ; newuri ;;