let filter_map ?(from=0) ?length s ~f =
let length_of_s = String.length s in
let from, length = resize_from_length ~from ?length ~length_of_s in
if length = 0 then empty
else begin
let b = Buffer.create length in
for i = 0 to length - 1 do
match f (get_exn s (i + from)) with
| Some c -> Buffer.add_char b c
| None -> ()
done;
Buffer.contents b
end