summaryrefslogtreecommitdiff
path: root/ocamldoc/odoc_name.ml
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2010-08-02 14:37:22 +0000
committerDamien Doligez <damien.doligez-inria.fr>2010-08-02 14:37:22 +0000
commit575555eecd11fcc745e0f1e88d090764b3291b63 (patch)
tree980663cc4b47a8e706079143a22403de6eda968a /ocamldoc/odoc_name.ml
parent7c11c2acf98926b16bfc737dadc64ee3d8eff352 (diff)
downloadocaml-575555eecd11fcc745e0f1e88d090764b3291b63.tar.gz
merge changes from branching of 3.12 to release/3.12.0
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10643 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'ocamldoc/odoc_name.ml')
-rw-r--r--ocamldoc/odoc_name.ml45
1 files changed, 43 insertions, 2 deletions
diff --git a/ocamldoc/odoc_name.ml b/ocamldoc/odoc_name.ml
index 672203ff67..b82cf87458 100644
--- a/ocamldoc/odoc_name.ml
+++ b/ocamldoc/odoc_name.ml
@@ -33,14 +33,39 @@ let infix_chars = [ '|' ;
type t = string
+let strip_string s =
+ let len = String.length s in
+ let rec iter_first n =
+ if n >= len then
+ None
+ else
+ match s.[n] with
+ ' ' | '\t' | '\n' | '\r' -> iter_first (n+1)
+ | _ -> Some n
+ in
+ match iter_first 0 with
+ None -> ""
+ | Some first ->
+ let rec iter_last n =
+ if n <= first then
+ None
+ else
+ match s.[n] with
+ ' ' | '\t' | '\n' | '\r' -> iter_last (n-1)
+ | _ -> Some n
+ in
+ match iter_last (len-1) with
+ None -> String.sub s first 1
+ | Some last -> String.sub s first ((last-first)+1)
+
let parens_if_infix name =
- match name with
+ match strip_string name with
| "" -> ""
| s when s.[0] = '*' || s.[String.length s - 1] = '*' -> "( " ^ s ^ " )"
| s when List.mem s.[0] infix_chars -> "(" ^ s ^ ")"
| "or" | "mod" | "land" | "lor" | "lxor" | "lsl" | "lsr" | "asr" ->
"(" ^ name ^ ")"
- | _ -> name
+ | name -> name
;;
let cut name =
@@ -80,6 +105,22 @@ let father name = fst (cut name)
let concat n1 n2 = n1^"."^n2
+let normalize_name name =
+ let (p,s) = cut name in
+ let len = String.length s in
+ let s =
+ if len >= 2 &&
+ s.[0] = '(' && s.[len - 1] = ')'
+ then
+ parens_if_infix (strip_string (String.sub s 1 (len - 2)))
+ else
+ s
+ in
+ match p with
+ "" -> s
+ | p -> concat p s
+ ;;
+
let head_and_tail n =
try
let pos = String.index n '.' in