Changeset 39 in code for trunk/lib


Ignore:
Timestamp:
Dec 12, 2022, 10:52:55 PM (2 years ago)
Author:
fox
Message:

Read References field; referred by listing; test & tidy documentation

Location:
trunk/lib
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/id.ml

    r3 r39  
    1313
    1414type t = string
    15 let compare = String.compare   
     15let compare = String.compare
    1616let nil = ""
    1717
  • trunk/lib/string_set.ml

    r3 r39  
    22
    33let list_of_csv x = Str.(split (regexp " *, *")) (String.trim x)
    4 let of_string x = of_list (list_of_csv x)
     4let list_of_ssv x = Str.(split (regexp " +")) (String.trim x)
     5
     6let of_string ?(separator=list_of_csv) x = of_list (separator x)
     7let of_csv_string x = of_string ~separator:list_of_csv x
     8let of_ssv_string x = of_string ~separator:list_of_ssv x
     9
    510let to_string ?(pre="") ?(sep=", ") s =
    611  let j a x = match a, x with "", _ -> x | _, "" -> a | _ -> a ^ sep ^ x in
  • trunk/lib/text.ml

    r38 r39  
    2626let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty
    2727let str_set key m = String_set.to_string @@ set key m
    28 let with_str_set m key str = { m with
    29         stringset_map = String_map.add (String.lowercase_ascii key) (String_set.of_string str) m.stringset_map
     28let with_str_set ?(separator=String_set.of_csv_string) m key str = { m with
     29        stringset_map = String_map.add (String.lowercase_ascii key) (separator str) m.stringset_map
    3030        }
    3131
     
    4040        | "date"                         -> { x with date = Date.{ x.date with created   = Date.of_string v }}
    4141        | "date-edited"-> { x with date = Date.{ x.date with edited             = Date.of_string v }}
    42         | "licences" | "topics" | "keywords" | "references" | "series" as k -> with_str_set x k v
     42        | "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v
     43        | "references" -> with_str_set
     44                        ~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2)))
     45                                (String_set.of_ssv_string x))
     46                        x k v
    4347        | k -> { x with string_map = String_map.add k (trim v) x.string_map }
    4448
Note: See TracChangeset for help on using the changeset viewer.