let string_of_filter f =
  let b = Buffer.create 256 in
  let rec iter = function
    Group s -> Printf.bprintf b "group: \"%s\"" (escape_quotes s)
  | Item s -> Printf.bprintf b "item: \"%s\"" (escape_quotes s)
  | Empty -> Buffer.add_string b "empty"
  | State s ->
      Printf.bprintf b "state: %s"
        (match s with
          Done -> "done"
         | Suspended -> "suspended"
         | Priority_low -> "low"
         | Priority_normal -> "normal"
         | Priority_high -> "high"
        )
  | Desc s -> Printf.bprintf b "desc: \"%s\""(escape_quotes s)
  | Before d ->
      Printf.bprintf b "before %s" (string_of_date d)
  | Or (f1, f2) ->
      iter f1 ;
      Buffer.add_string b " or ";
      iter f2
  | And (f1, f2) ->
      iter f1 ;
      Buffer.add_string b " and ";
      iter f2
  | Not f ->
      Buffer.add_string b "not ";
      iter f
  in
  iter f;
  Buffer.contents b