options are now proplist style, so [comments] implies [{comments, true}] et cetera
This commit is contained in:
parent
88da19783a
commit
a6e7490a2b
5 changed files with 51 additions and 13 deletions
|
@ -141,15 +141,21 @@ parse_opts([], Opts) ->
|
|||
parse_opts([{comments, Value}|Rest], Opts) ->
|
||||
true = lists:member(Value, [true, false]),
|
||||
parse_opts(Rest, Opts#opts{comments=Value});
|
||||
parse_opts([comments|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts#opts{comments=true});
|
||||
parse_opts([{escaped_unicode, Value}|Rest], Opts) ->
|
||||
true = lists:member(Value, [ascii, codepoint, none]),
|
||||
parse_opts(Rest, Opts#opts{escaped_unicode=Value});
|
||||
parse_opts([{unquoted_keys, Value}|Rest], Opts) ->
|
||||
true = lists:member(Value, [true, false]),
|
||||
parse_opts(Rest, Opts#opts{unquoted_keys=Value});
|
||||
parse_opts([unquoted_keys|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts#opts{unquoted_keys=true});
|
||||
parse_opts([{multi_term, Value}|Rest], Opts) ->
|
||||
true = lists:member(Value, [true, false]),
|
||||
parse_opts(Rest, Opts#opts{multi_term=Value});
|
||||
parse_opts([multi_term|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts#opts{multi_term=true});
|
||||
parse_opts([{encoding, _}|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts);
|
||||
parse_opts(_, _) ->
|
||||
|
|
11
src/jsx.erl
11
src/jsx.erl
|
@ -258,11 +258,14 @@ json_to_term(JSON) ->
|
|||
|
||||
-spec json_to_term(JSON::binary(), Opts::decoder_opts()) -> eep0018().
|
||||
|
||||
%json_to_term(JSON, Opts) ->
|
||||
% try jsx_eep0018:json_to_term(JSON, Opts)
|
||||
% %% rethrow exception so internals aren't confusingly exposed to users
|
||||
% catch error:badarg -> erlang:error(badarg)
|
||||
% end.
|
||||
|
||||
json_to_term(JSON, Opts) ->
|
||||
try jsx_eep0018:json_to_term(JSON, Opts)
|
||||
%% rethrow exception so internals aren't confusingly exposed to users
|
||||
catch error:badarg -> erlang:error(badarg)
|
||||
end.
|
||||
jsx_eep0018:json_to_term(JSON, Opts).
|
||||
|
||||
|
||||
%% @spec term_to_json(JSON::eep0018()) -> binary()
|
||||
|
|
|
@ -69,10 +69,19 @@ term_to_json(List, Opts) ->
|
|||
|
||||
|
||||
extract_parser_opts(Opts) ->
|
||||
[ {K, V} || {K, V} <-
|
||||
Opts, lists:member(K, [comments, encoding, unquoted_keys])
|
||||
].
|
||||
extract_parser_opts(Opts, []).
|
||||
|
||||
extract_parser_opts([], Acc) -> Acc;
|
||||
extract_parser_opts([{K,V}|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [{K,V}] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end;
|
||||
extract_parser_opts([K|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [K] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end.
|
||||
|
||||
%% ensure the first jsx event we get is start_object or start_array when running
|
||||
%% in strict mode
|
||||
|
|
|
@ -72,9 +72,19 @@ parse_opts([], Opts) ->
|
|||
|
||||
|
||||
extract_parser_opts(Opts) ->
|
||||
[ {K, V} || {K, V} <-
|
||||
Opts, lists:member(K, [comments, encoding, unquoted_keys])
|
||||
].
|
||||
extract_parser_opts(Opts, []).
|
||||
|
||||
extract_parser_opts([], Acc) -> Acc;
|
||||
extract_parser_opts([{K,V}|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [{K,V}] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end;
|
||||
extract_parser_opts([K|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [K] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end.
|
||||
|
||||
|
||||
format_something({event, start_object, Next}, Opts, Level) ->
|
||||
|
|
|
@ -51,9 +51,19 @@ is_json(JSON, Opts) ->
|
|||
|
||||
|
||||
extract_parser_opts(Opts) ->
|
||||
[ {K, V} || {K, V} <-
|
||||
Opts, lists:member(K, [comments, encoding, unquoted_keys])
|
||||
].
|
||||
extract_parser_opts(Opts, []).
|
||||
|
||||
extract_parser_opts([], Acc) -> Acc;
|
||||
extract_parser_opts([{K,V}|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [{K,V}] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end;
|
||||
extract_parser_opts([K|Rest], Acc) ->
|
||||
case lists:member(K, [comments, encoding, unquoted_keys]) of
|
||||
true -> [K] ++ Acc
|
||||
; false -> extract_parser_opts(Rest, Acc)
|
||||
end.
|
||||
|
||||
|
||||
%% enforce only arrays and objects at top level
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue