options are now proplist style, so [comments] implies [{comments, true}] et cetera

This commit is contained in:
alisdair sullivan 2011-03-07 14:02:51 -08:00
parent 88da19783a
commit a6e7490a2b
5 changed files with 51 additions and 13 deletions

View file

@ -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()

View file

@ -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

View file

@ -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) ->

View file

@ -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