1 (***********************************************************************)
4 (* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
6 (* Copyright 2001 Institut National de Recherche en Informatique et *)
7 (* en Automatique. All rights reserved. This file is distributed *)
8 (* under the terms of the Q Public License version 1.0. *)
10 (***********************************************************************)
12 (* $Id: odoc_name.ml 9185 2009-03-12 18:21:08Z doligez $ *)
14 (** Representation of element names. *)
16 let infix_chars = [ '|' ;
36 let parens_if_infix name =
39 | s when s.[0] = '*' || s.[String.length s - 1] = '*' -> "( " ^ s ^ " )"
40 | s when List.mem s.[0] infix_chars -> "(" ^ s ^ ")"
41 | "or" | "mod" | "land" | "lor" | "lxor" | "lsl" | "lsr" | "asr" ->
50 let len = String.length s in
55 let buf = [|Buffer.create len ; Buffer.create len |] in
56 for i = 0 to len - 1 do
64 Buffer.add_char buf.(!j) '.'
66 Buffer.add_char buf.(!j) s.[i]
68 Buffer.add_char buf.(!j) c
70 (Buffer.contents buf.(0), Buffer.contents buf.(1))
73 match List.rev (Str.split (Str.regexp_string ".") s) with
76 (String.concat "." (List.rev q), h)
78 let simple name = snd (cut name)
79 let father name = fst (cut name)
81 let concat n1 n2 = n1^"."^n2
85 let pos = String.index n '.' in
87 let h = String.sub n 0 pos in
89 ignore (String.index h '(');
93 let len = String.length n in
94 if pos >= (len - 1) then
97 (h, String.sub n (pos + 1) (len - pos - 1))
103 let head n = fst (head_and_tail n)
104 let tail n = snd (head_and_tail n)
108 List.length (Str.split (Str.regexp "\\.") name)
115 let len1 = String.length n1 in
116 ((String.sub n2 0 len1) = n1) &
120 let rec get_relative_raw n1 n2 =
121 let (f1,s1) = head_and_tail n1 in
122 let (f2,s2) = head_and_tail n2 in
124 if f2 = s2 or s2 = "" then
127 if f1 = s1 or s1 = "" then
130 get_relative_raw s1 s2
134 let get_relative n1 n2 =
136 let len1 = String.length n1 in
138 String.sub n2 (len1+1) ((String.length n2) - len1 - 1)
144 let hide_given_modules l s =
145 let rec iter = function
148 let s2 = get_relative h s in
156 let qualified name = String.contains name '.'
158 let from_ident ident = Ident.name ident
161 let from_path path = Path.name path
166 (fun acc_opt -> fun s ->
168 None -> Some (Path.Pident (Ident.create s))
169 | Some acc -> Some (Path.Pdot (acc, s, 0)))
171 (Str.split (Str.regexp "\\.") n)
173 None -> raise (Failure "to_path")
176 let from_longident = Odoc_misc.string_of_longident