refactors out extraction of parser opts, generalizes use of specific parsers by processors
This commit is contained in:
parent
55d0259c89
commit
6dacf64620
7 changed files with 57 additions and 80 deletions
|
@ -38,7 +38,7 @@
|
|||
|
||||
is_json(Source, Opts) when (is_binary(Source) andalso is_list(Opts))
|
||||
orelse (is_list(Source) andalso is_list(Opts)) ->
|
||||
try case (gen_json:parser(?MODULE, Opts, extract_opts(Opts)))(Source) of
|
||||
try case (gen_json:parser(?MODULE, Opts, jsx_utils:extract_opts(Opts)))(Source) of
|
||||
{incomplete, _} -> false
|
||||
; true -> true
|
||||
end
|
||||
|
@ -47,9 +47,6 @@ is_json(Source, Opts) when (is_binary(Source) andalso is_list(Opts))
|
|||
|
||||
|
||||
|
||||
init(Opts) -> {parse_opts(Opts), []}.
|
||||
|
||||
|
||||
parse_opts(Opts) -> parse_opts(Opts, #opts{}).
|
||||
|
||||
parse_opts([{repeated_keys, Val}|Rest], Opts) when Val == true; Val == false ->
|
||||
|
@ -62,20 +59,9 @@ parse_opts([], Opts) ->
|
|||
Opts.
|
||||
|
||||
|
||||
extract_opts(Opts) ->
|
||||
extract_parser_opts(Opts, []).
|
||||
|
||||
extract_parser_opts([], Acc) -> Acc;
|
||||
extract_parser_opts([{K,V}|Rest], Acc) ->
|
||||
case lists:member(K, [loose_unicode, escape_forward_slash, explicit_end]) of
|
||||
true -> extract_parser_opts(Rest, [{K,V}] ++ Acc)
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end;
|
||||
extract_parser_opts([K|Rest], Acc) ->
|
||||
case lists:member(K, [loose_unicode, escape_forward_slash, explicit_end]) of
|
||||
true -> extract_parser_opts(Rest, [K] ++ Acc)
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end.
|
||||
init(Opts) -> {parse_opts(Opts), []}.
|
||||
|
||||
|
||||
|
||||
handle_event(end_json, _) -> true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue