|
|
@ -14,6 +14,8 @@ open! IStd
|
|
|
|
|
|
|
|
|
|
|
|
(** apply a map function for escape sequences *)
|
|
|
|
(** apply a map function for escape sequences *)
|
|
|
|
let escape_map map_fun s =
|
|
|
|
let escape_map map_fun s =
|
|
|
|
|
|
|
|
let needs_escape = String.exists ~f:(fun c -> Option.is_some (map_fun c)) s in
|
|
|
|
|
|
|
|
if needs_escape then
|
|
|
|
let len = String.length s in
|
|
|
|
let len = String.length s in
|
|
|
|
let buf = Buffer.create len in
|
|
|
|
let buf = Buffer.create len in
|
|
|
|
for i = 0 to len - 1 do
|
|
|
|
for i = 0 to len - 1 do
|
|
|
@ -21,6 +23,8 @@ let escape_map map_fun s =
|
|
|
|
match map_fun c with None -> Buffer.add_char buf c | Some s' -> Buffer.add_string buf s'
|
|
|
|
match map_fun c with None -> Buffer.add_char buf c | Some s' -> Buffer.add_string buf s'
|
|
|
|
done ;
|
|
|
|
done ;
|
|
|
|
Buffer.contents buf
|
|
|
|
Buffer.contents buf
|
|
|
|
|
|
|
|
else (* not escaping anything, so don't waste memory on a copy of the string *)
|
|
|
|
|
|
|
|
s
|
|
|
|
|
|
|
|
|
|
|
|
let escape_csv s =
|
|
|
|
let escape_csv s =
|
|
|
|
let map = function
|
|
|
|
let map = function
|
|
|
|