Declarative CSV codecs
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

irmin: implement set/flush/empty, rename test, zero TODOs

+24 -7
+14 -2
fuzz/fuzz_csvt.ml
··· 102 102 103 103 (* {1 String roundtrip (no commas/newlines)} *) 104 104 105 + let strip_leading_hash s = 106 + let n = String.length s in 107 + let i = ref 0 in 108 + while !i < n && s.[!i] = '#' do 109 + incr i 110 + done; 111 + if !i = 0 then s else String.sub s !i (n - !i) 112 + 105 113 let test_string_roundtrip s = 106 114 (* Filter characters that have special meaning in CSV: comma (field separator), 107 - newline/CR (row separator), and double-quote (quoting delimiter per RFC 4180). 108 - These characters require quoting to roundtrip, tested separately. *) 115 + newline/CR (row separator), double-quote (quoting delimiter per RFC 4180), 116 + and leading # (comment marker). These characters require quoting to 117 + roundtrip, tested separately. *) 109 118 let s = 110 119 String.to_seq s 111 120 |> Seq.filter (fun c -> c <> ',' && c <> '\n' && c <> '\r' && c <> '"') 112 121 |> String.of_seq 113 122 in 123 + let s = strip_leading_hash s in 114 124 if String.length s = 0 then () (* empty lines are skipped *) 115 125 else 116 126 let csv = "v\n" ^ s ^ "\n" in ··· 129 139 |> Seq.filter (fun c -> c <> ',' && c <> '\n' && c <> '\r' && c <> '"') 130 140 |> String.of_seq 131 141 in 142 + let s = strip_leading_hash s in 132 143 if String.length s = 0 then () 133 144 else 134 145 let csv = "a,b\n" ^ string_of_int i ^ "," ^ s ^ "\n" in ··· 147 158 |> Seq.filter (fun c -> c <> ',' && c <> '\n' && c <> '\r' && c <> '"') 148 159 |> String.of_seq 149 160 in 161 + let s = strip_leading_hash s in 150 162 if String.length s = 0 then () 151 163 else 152 164 let csv1 = "a,b\n" ^ string_of_int i ^ "," ^ s ^ "\n" in
+7 -5
lib/csvt.ml
··· 618 618 619 619 let needs_quoting s = 620 620 let n = String.length s in 621 - let rec loop i = 622 - if i >= n then false 623 - else match s.[i] with ',' | '"' | '\n' | '\r' -> true | _ -> loop (i + 1) 624 - in 625 - loop 0 621 + if n > 0 && s.[0] = '#' then true 622 + else 623 + let rec loop i = 624 + if i >= n then false 625 + else match s.[i] with ',' | '"' | '\n' | '\r' -> true | _ -> loop (i + 1) 626 + in 627 + loop 0 626 628 627 629 let write_quoted_field w s = 628 630 w "\"";
+3
lib/csvt.mli
··· 13 13 share a single type {!t}. Row codecs are built declaratively using 14 14 constructors and field accessors with the {!Row} builder. 15 15 16 + Lines starting with [#] are treated as comments and skipped during decoding 17 + (both in the header section and in data rows). Empty lines are also skipped. 18 + 16 19 {2 Quick Start} 17 20 18 21 {v