Commit 9b5a68e8 authored by Sylvain Dailler's avatar Sylvain Dailler

minor rewriting of code handling name labels

parent 359f388e
...@@ -103,21 +103,20 @@ let get_model_trace_string ~labels = ...@@ -103,21 +103,20 @@ let get_model_trace_string ~labels =
let is_name_label label = let is_name_label label =
Strings.has_prefix "name:" label.lab_string Strings.has_prefix "name:" label.lab_string
let get_name_label ~labels = Slab.choose (Slab.filter is_name_label labels) let get_name_label ~labels =
try Some (Slab.choose (Slab.filter is_name_label labels))
with Not_found -> None
let get_element_name ~labels = let get_element_name ~labels =
let name_label = get_name_label ~labels in match get_name_label ~labels with
let splitted1 = Strings.bounded_split ':' name_label.lab_string 2 in | None -> None
let correct_word = Str.regexp "^\\([A-Za-z]+\\)\\([A-Za-z0-9_]*\\)$" in | Some name_label ->
match splitted1 with let splitted1 = Strings.bounded_split ':' name_label.lab_string 2 in
| ["name"; content] when Str.string_match correct_word content 0 -> let correct_word = Str.regexp "^\\([A-Za-z]+\\)\\([A-Za-z0-9_']*\\)$" in
begin match splitted1 with
content | ["name"; content] when Str.string_match correct_word content 0 ->
end; Some content
| [_] -> "" | _ -> None
| _ -> assert false
(** Identifiers *) (** Identifiers *)
...@@ -257,18 +256,16 @@ let id_unique_label printer ?(sanitizer = same) id = ...@@ -257,18 +256,16 @@ let id_unique_label printer ?(sanitizer = same) id =
try try
Hid.find printer.values id Hid.find printer.values id
with Not_found -> with Not_found ->
let labels = id.id_label in let labels = id.id_label in
try let name =
let name = sanitizer (get_element_name ~labels) in match (get_element_name ~labels) with
let name = find_unique printer.indices name in | Some x -> x
Hid.replace printer.values id name; | None -> printer.sanitizer id.id_string
name in
with let name = sanitizer name in
| _ -> let name = find_unique printer.indices name in
let name = sanitizer (printer.sanitizer id.id_string) in Hid.replace printer.values id name;
let name = find_unique printer.indices name in name
Hid.replace printer.values id name;
name
let string_unique printer s = find_unique printer.indices s let string_unique printer s = find_unique printer.indices s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment