is_json/2 and format/2 now both accept either a json text (binary) or a function that acts as a jsx iterator. specs updated to reflect

This commit is contained in:
alisdair sullivan 2011-07-04 19:25:09 -07:00
parent e088c6fd26
commit 0052480652
3 changed files with 38 additions and 32 deletions

View file

@ -32,17 +32,13 @@
-include("jsx_format.hrl").
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist().
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist()
; (F::jsx_iterator(), Opts::format_opts()) -> binary() | iolist().
format(JSON, Opts) when is_binary(JSON) ->
P = jsx:decoder(extract_parser_opts(Opts)),
format(fun() -> P(JSON) end, Opts);
format(JSON, OptsList) when is_binary(JSON) ->
P = jsx:decoder(extract_parser_opts(OptsList)),
format(fun() -> P(JSON) end, OptsList);
format(F, OptsList) when is_function(F) ->
Opts = parse_opts(OptsList, #format_opts{}),
{Continue, String} = format_something(F(), Opts, 0),
@ -198,6 +194,7 @@ space(Opts) ->
%% eunit tests
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
minify_test_() ->
[