Skip to content

Support returning result as iodata and as safe iodata

Justin Tormey requested to merge jtormey/linkify:iodata into master

Implements link_to_iodata/2 and link_safe/2 as discussed in the issue thread (closes #20 (closed)).

I was able to do this without changing the structure of the program much. The key change is that the accumulator value can now be either binary or iodata, the accumulate/3 function matches on and handles these two cases.

The biggest change here is that the reduce/3 operation for identifying multiple link types has been moved from parse/2 into link/3. This is because do_parse/3 may now return iodata, which cannot then be fed back into the parser. My solution was to run it on the buffer in question directly, deeper in the parsing operation, such that only one pass is needed on the initial input. A benefit of this is that the type doesn't have to be propagated down as a function argument anymore.

Something to note, the functions added assume a keyword list is passed as opts. I wasn't sure which format was best to use, since the default in link/2 is opts \\ [] while parse/2 seems to prefer a map by specifying opts \\ %{}.

All existing tests pass without any modification, and I added tests for the new functionality. Looking forward to hearing feedback!

Merge request reports