add collect function to jsx_utils for later use
This commit is contained in:
parent
59bde85780
commit
39605da171
1 changed files with 13 additions and 4 deletions
|
@ -23,12 +23,20 @@
|
||||||
|
|
||||||
-module(jsx_utils).
|
-module(jsx_utils).
|
||||||
|
|
||||||
-export([nice_decimal/1, detect_encoding/1, detect_encoding/2]).
|
-export([nice_decimal/1, detect_encoding/1, detect_encoding/2, collect/1]).
|
||||||
|
|
||||||
|
|
||||||
-ifdef(TEST).
|
-spec collect(F::function()) -> {jsx, list(), function()}.
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
collect(F) when is_function(F) ->
|
||||||
|
collect(F(), []).
|
||||||
|
|
||||||
|
collect({error, _}, _) -> {error, badarg};
|
||||||
|
collect({jsx, incomplete, More}, Acc) ->
|
||||||
|
{jsx, incomplete, fun(Stream) -> collect(More(Stream), Acc) end};
|
||||||
|
collect({jsx, end_json, Next}, Acc) ->
|
||||||
|
{jsx, lists:reverse([end_json] ++ Acc), Next};
|
||||||
|
collect({jsx, Event, Next}, Acc) -> collect(Next(), [Event] ++ Acc).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -269,6 +277,7 @@ detect_encoding(Bin, Opts) ->
|
||||||
|
|
||||||
%% eunit tests
|
%% eunit tests
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
nice_decimal_test_() ->
|
nice_decimal_test_() ->
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue