Commits

Joby Poriyath committed e86bac8

dinaaa

Comments (0)

Files changed (2)

   List.fold_right, List.fold_left
 
 *)
+
+(* 
+   Selecting on some field is usually done using a function of type
+   data_base -> 'a -> string -> data_card -> bool
+*)
+
+let eq_sfield db s n dc = (s = field db n dc)
+let non_empty_sfield db n dc = ("" <> field db n dc)
+
+let tst_ffield f db v n dc = f v (float_of_string (field db n dc))
+let eq_ffield = tst_ffield (=)
+let lt_ffield = tst_ffield (<)
+let le_ffield = tst_ffield (<=)
+
+(*Date manipulation*)
+
+let split_date s = split_on s (fun c -> c = '.')
+let ints_of_string d = 
+  try
+    match (split_date d) with
+      | [_; _; _] as date -> List.map int_of_string date
+      | _ -> failwith "Bad date format"
+  with Failure "int_of_string" -> failwith "Bad date format"
+    
+
+let ints_of_dpat d =
+  let int_of_stringpat = function "_" -> 0 | s -> int_of_string s in
+  try 
+    match (split_date d) with
+      | [_;_;_] as date -> List.map int_of_stringpat date
+      | _ -> failwith "Bad date format"
+  with Failure "int_of_string" -> failwith "Bad date pattern"
+
+let rec app_dtst r d1 d2 = 
+  match (d1, d2) with
+    |([], []) -> false
+    |(0::d1, _::d2) -> app_dtst r d1 d2
+    |(n1 :: d1, n2 :: d2) -> (r n1 n2) || ((n1 = n2) && app_dtst r d1 d2)
+    |(_, _) -> failwith "Bad date pattern or format"
+
+
+let tst_dfield r db dp n dc = 
+  app_dtst r (ints_of_dpat dp) (ints_of_string (field db n dc))
+    
+let eq_dfield = tst_dfield (=)
+let lt_dfield = tst_dfield (<)
+let le_dfield = tst_dfield (<=)
+Num|Lastname|Firstname|Address|Tel|Email|Pref|Date|Amount
+0:Chailloux:Emmanuel:Universite P6:0144274427:ec@lip6.fr:email:25.12.1998:100.00
+1:Manoury:Pascal:Laboratoire PPS::pm@lip6.fr:mail:03.03.1997:150.00
+2:Pagano:Bruno:Cristal:0139633963::mail:25.12.1998:150.00
+3:Baro:Sylvain::0144274427:baro@pps.fr:email:01.03.1999:50.00