source: Deliverables/D2.2/8051/src/utilities/stringTools.ml @ 486

Last change on this file since 486 was 486, checked in by ayache, 8 years ago

Deliverable D2.2

File size: 786 bytes
Line 
1
2(** FIXME: document here *)
3
4type t = string
5
6let compare = String.compare
7
8
9module Set = Set.Make (String)
10
11
12module Map = Map.Make (String)
13
14
15module Gen = struct
16
17  type universe = { prefix : string ; mutable next : int }
18
19  let added_prefix = "_"
20
21  let is_prefix prefix s =
22    let l = String.length prefix in
23    (String.length s >= l) && (String.sub s 0 l = prefix)
24
25  let has_prefix set prefix =
26    let f s b = b || (is_prefix prefix s) in
27    Set.fold f set false
28
29  let fresh_prefix set prefix =
30    let rec aux prefix =
31      if has_prefix set prefix then aux (added_prefix ^ prefix)
32      else prefix in
33    aux prefix
34
35
36  let new_universe s = { prefix = s ; next = 0 }
37
38  let fresh u =
39    let s = u.prefix ^ (string_of_int u.next) in
40    u.next <- u.next + 1 ;
41    s
42
43end
Note: See TracBrowser for help on using the repository browser.