= [{?<, "<"}, {?>, ">"}, {?&, "&"}, {?\", """}, {?\', "'"}] for {match, insert} <- escapes do defp to_iodata(<<unquote(match), rest::bits>>, skip, original, acc) do to_iodata(rest, skip + 1, original, [acc | unquote(insert)]) end end defp to_iodata(<<_char, rest::bits>>, skip, original, acc), do: to_iodata(rest, skip, original, acc, 1) defp to_iodata(<<>>, _skip, _original, acc), do: acc for {match, insert} <- escapes do defp to_iodata(<<unquote(match), rest::bits>>, skip, original, acc, len) do part = binary_part(original, skip, len) to_iodata(rest, skip + len + 1, original, [acc, part | unquote(insert)]) end end defp to_iodata(<<_c, rest::bits>>, skip, orig, acc, len), do: to_iodata(rest, skip, orig, acc, len + 1) defp to_iodata(<<>>, 0, orig, _acc, _len), do: original defp to_iodata(<<>>, s, original, acc, len), do:[acc | binary_part(original, skip, len)]