let replace_chars ~src ~patterns =
let l_src = String.length src in
let res_buf = Buffer.create (2 * l_src) in
let rec parse_list cur = function
| [] -> string_of_char cur
| (c, replace) :: t ->
if c = cur then replace else parse_list cur t
in
for i = 0 to l_src - 1 do
Buffer.add_string res_buf (parse_list src.[i] patterns);
done;
Buffer.contents res_buf