let escape_char ~needle haystack = let escfun c = if c = needle then ['\\'; c] else [c] in String.rev haystack |> String.fold ~init:[] ~f:(fun x c -> (escfun c) @ x) |> List.map ~f:String.of_character |> String.concat