Changeset 41 in code for trunk/lib/text.ml


Ignore:
Timestamp:
Dec 13, 2022, 11:04:19 PM (2 years ago)
Author:
fox
Message:

In-Reply-To header field. Note extra list.rev in convert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/text.ml

    r39 r41  
    2323let newest a b = Date.(compare a.date b.date)
    2424let 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
     26let str key m =
     27        try String_map.find (String.lowercase_ascii key) m.string_map
     28        with Not_found -> ""
     29
     30let set key m =
     31        try String_map.find (String.lowercase_ascii key) m.stringset_map
     32        with Not_found -> String_set.empty
     33
     34let 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
    3038        }
    3139
     
    3846        | "author"
    3947        | "authors" -> { x with authors = Person.Set.of_string (trim v)}
    40         | "date"                         -> { x with date = Date.{ x.date with created  = Date.of_string v }}
    41         | "date-edited"-> { x with date = Date.{ x.date with edited             = Date.of_string v }}
     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 }}
    4250        | "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))
     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))
    4654                        x k v
    4755        | k -> { x with string_map = String_map.add k (trim v) x.string_map }
     
    7078        with _ -> Error ("Failed parsing" ^ s)
    7179
    72 let to_string x =
     80let str_set key m = String_set.to_string @@ set key m
     81
     82let to_string x =
    7383        let has_len v = String.length v > 0 in
    7484        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
    7789        let rows = [
    7890                s "ID" x.id;
    79                 d "Date"     x.date.Date.created;
    80                 d "Edited"   x.date.Date.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;
    8294                a x.authors;
    8395                s "Licences" (str_set "licences" x);
    8496                s "Topics"   (str_set "topics" x);
    8597                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);
    87100                s "Series"   (str_set "series" x);
    88101                s "Abstract" (str "abstract" x);
Note: See TracChangeset for help on using the changeset viewer.