moved function that fakes the jsx parser iterator to jsx so any client program can take advantage of it
This commit is contained in:
parent
422f5958a0
commit
45b9bc1dd0
2 changed files with 13 additions and 10 deletions
13
src/jsx.erl
13
src/jsx.erl
|
@ -30,6 +30,7 @@
|
||||||
-export([json_to_term/1, json_to_term/2]).
|
-export([json_to_term/1, json_to_term/2]).
|
||||||
-export([is_json/1, is_json/2]).
|
-export([is_json/1, is_json/2]).
|
||||||
-export([format/1, format/2]).
|
-export([format/1, format/2]).
|
||||||
|
-export([eventify/1]).
|
||||||
|
|
||||||
|
|
||||||
%% types for function specifications
|
%% types for function specifications
|
||||||
|
@ -104,7 +105,17 @@ format(JSON) ->
|
||||||
format(JSON, []).
|
format(JSON, []).
|
||||||
|
|
||||||
format(JSON, Opts) ->
|
format(JSON, Opts) ->
|
||||||
jsx_format:format(JSON, Opts).
|
jsx_format:format(JSON, Opts).
|
||||||
|
|
||||||
|
|
||||||
|
-spec eventify(List::list()) -> jsx_parser_result().
|
||||||
|
|
||||||
|
%% fake the jsx api with a closure to be passed to the pretty printer
|
||||||
|
|
||||||
|
eventify([]) ->
|
||||||
|
fun() -> {incomplete, fun(end_stream) -> eventify([]) end} end;
|
||||||
|
eventify([Next|Rest]) ->
|
||||||
|
fun() -> {event, Next, eventify(Rest)} end.
|
||||||
|
|
||||||
|
|
||||||
%% ----------------------------------------------------------------------------
|
%% ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -58,15 +58,7 @@ term_to_json(List, Opts) ->
|
||||||
; false -> continue
|
; false -> continue
|
||||||
end,
|
end,
|
||||||
Encoding = proplists:get_value(encoding, Opts, utf8),
|
Encoding = proplists:get_value(encoding, Opts, utf8),
|
||||||
jsx:format(event_generator(lists:reverse(term_to_events(List))), [{output_encoding, Encoding}] ++ Opts).
|
jsx:format(jsx:eventify(lists:reverse([end_json] ++ term_to_events(List))), [{output_encoding, Encoding}] ++ Opts).
|
||||||
|
|
||||||
|
|
||||||
%% fake the jsx api with a closure to be passed to the pretty printer
|
|
||||||
|
|
||||||
event_generator([]) ->
|
|
||||||
fun() -> {event, end_json, fun() -> {incomplete, fun(end_stream) -> event_generator([]) end} end} end;
|
|
||||||
event_generator([Next|Rest]) ->
|
|
||||||
fun() -> {event, Next, event_generator(Rest)} end.
|
|
||||||
|
|
||||||
|
|
||||||
%% parse opts for the decoder
|
%% parse opts for the decoder
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue