let multiline f str = 
  if String.length str > 0 then
    let buf = Buffer.create 80 in
    let flush () = f (Buffer.contents buf); Buffer.clear buf in
      String.iter
        (function '\n' -> flush () | c -> Buffer.add_char buf c)
        str;
      flush ()