Changeset 3 in code for trunk/lib/person.ml
- Timestamp:
- Apr 15, 2022, 1:17:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/person.ml
r2 r3 1 1 module Person = struct 2 2 type name_t = string 3 type address_t = Uri.t3 type address_t = string 4 4 type t = { name: name_t; addresses: address_t list } 5 5 let empty = { name = ""; addresses = [] } 6 6 let compare = Stdlib.compare 7 let to_string p = List.fold_left (fun a e -> a^" <"^Uri.to_string e^">") p.name p.addresses 7 let name_to_string p = p.name 8 let to_string p = List.fold_left (fun a e -> Printf.sprintf "%s <%s>" a e) p.name p.addresses 8 9 let of_string s = match String.trim s with "" -> empty | s -> 9 match Re.Str.(split (regexp " *< *") s) with10 match Str.(split (regexp " *< *") s) with 10 11 | [] -> empty 11 12 | [n] -> let name = String.trim n in { empty with name } 12 13 | n::adds -> 13 14 let name = String.trim n in 14 let addresses = List.map (fun f -> Uri.of_string @@String.(sub f 0 (length f -1))) adds in15 let addresses = List.map (fun f -> String.(sub f 0 (length f -1))) adds in 15 16 { name; addresses } 16 17 end … … 20 21 module Set = struct 21 22 include Set.Make(Person) 22 let to_string ?( pre="") ?(sep=", ") s =23 let str = Person.to_string in23 let to_string ?(names_only=false) ?(pre="") ?(sep=", ") s = 24 let str = if names_only then Person.name_to_string else Person.to_string in 24 25 let j x a = match a, x with "",_ -> str x | _,x when x = Person.empty -> a | _ -> a^sep^str x in 25 26 fold j s pre
Note:
See TracChangeset
for help on using the changeset viewer.