Changeset 41 in code for trunk/lib/text.ml
- Timestamp:
- Dec 13, 2022, 11:04:19 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/text.ml
r39 r41 23 23 let newest a b = Date.(compare a.date b.date) 24 24 let oldest a b = Date.(compare b.date a.date) 25 let str key m = try String_map.find (String.lowercase_ascii key) m.string_map with Not_found -> "" 26 let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty 27 let str_set key m = String_set.to_string @@ set key m 28 let 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 25 26 let str key m = 27 try String_map.find (String.lowercase_ascii key) m.string_map 28 with Not_found -> "" 29 30 let set key m = 31 try String_map.find (String.lowercase_ascii key) m.stringset_map 32 with Not_found -> String_set.empty 33 34 let with_str_set ?(separator=String_set.of_csv_string) m key str = 35 { m with 36 stringset_map = String_map.add (String.lowercase_ascii key) (separator str) 37 m.stringset_map 30 38 } 31 39 … … 38 46 | "author" 39 47 | "authors" -> { x with authors = Person.Set.of_string (trim v)} 40 | "date" -> { x with date = Date.{ x.date with created 41 | "date-edited"-> { x with date = Date.{ x.date with edited 48 | "date" -> { x with date = Date.{ x.date with created = Date.of_string v }} 49 | "date-edited"-> { x with date = Date.{ x.date with edited = Date.of_string v }} 42 50 | "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v 43 | "references" -> with_str_set44 ~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2)))45 ( String_set.of_ssv_string x))51 | "references" | "in-reply-to" -> with_str_set 52 ~separator:(fun x -> String_set.map 53 (fun x -> String.(sub x 1 (length x-2))) (String_set.of_ssv_string x)) 46 54 x k v 47 55 | k -> { x with string_map = String_map.add k (trim v) x.string_map } … … 70 78 with _ -> Error ("Failed parsing" ^ s) 71 79 72 let to_string x = 80 let str_set key m = String_set.to_string @@ set key m 81 82 let to_string x = 73 83 let has_len v = String.length v > 0 in 74 84 let s field value = if has_len value then field ^ ": " ^ value ^ "\n" else "" in 75 let a value = if Person.Set.is_empty value then "" else "Authors: " ^ Person.Set.to_string value ^ "\n" in 76 let d field value = match value with "" -> "" | s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in 85 let a value = if Person.Set.is_empty value then "" 86 else "Authors: " ^ Person.Set.to_string value ^ "\n" in 87 let d field value = match value with "" -> "" 88 | s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in 77 89 let rows = [ 78 90 s "ID" x.id; 79 d "Date" 80 d "Edited" 81 s "Title" x.title;91 d "Date" x.date.Date.created; 92 d "Edited" x.date.Date.edited; 93 s "Title" x.title; 82 94 a x.authors; 83 95 s "Licences" (str_set "licences" x); 84 96 s "Topics" (str_set "topics" x); 85 97 s "Keywords" (str_set "keywords" x); 86 s "References"(str_set "references" x); 98 s "References"(str_set "references" x); (*todo: add to output <>*) 99 s "In-Reply-To"(str_set "in-reply-to" x); 87 100 s "Series" (str_set "series" x); 88 101 s "Abstract" (str "abstract" x);
Note:
See TracChangeset
for help on using the changeset viewer.