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

@ -141,15 +141,21 @@ parse_opts([], Opts) ->
parse_opts([{comments, Value}|Rest], Opts) -> parse_opts([{comments, Value}|Rest], Opts) ->
true = lists:member(Value, [true, false]), true = lists:member(Value, [true, false]),
parse_opts(Rest, Opts#opts{comments=Value}); 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) -> parse_opts([{escaped_unicode, Value}|Rest], Opts) ->
true = lists:member(Value, [ascii, codepoint, none]), true = lists:member(Value, [ascii, codepoint, none]),
parse_opts(Rest, Opts#opts{escaped_unicode=Value}); parse_opts(Rest, Opts#opts{escaped_unicode=Value});
parse_opts([{unquoted_keys, Value}|Rest], Opts) -> parse_opts([{unquoted_keys, Value}|Rest], Opts) ->
true = lists:member(Value, [true, false]), true = lists:member(Value, [true, false]),
parse_opts(Rest, Opts#opts{unquoted_keys=Value}); 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) -> parse_opts([{multi_term, Value}|Rest], Opts) ->
true = lists:member(Value, [true, false]), true = lists:member(Value, [true, false]),
parse_opts(Rest, Opts#opts{multi_term=Value}); 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([{encoding, _}|Rest], Opts) ->
parse_opts(Rest, Opts); parse_opts(Rest, Opts);
parse_opts(_, _) -> parse_opts(_, _) ->

View file

@ -258,11 +258,14 @@ json_to_term(JSON) ->
-spec json_to_term(JSON::binary(), Opts::decoder_opts()) -> eep0018(). -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) -> json_to_term(JSON, Opts) ->
try jsx_eep0018:json_to_term(JSON, Opts) jsx_eep0018:json_to_term(JSON, Opts).
%% rethrow exception so internals aren't confusingly exposed to users
catch error:badarg -> erlang:error(badarg)
end.
%% @spec term_to_json(JSON::eep0018()) -> binary() %% @spec term_to_json(JSON::eep0018()) -> binary()

View file

@ -69,10 +69,19 @@ term_to_json(List, Opts) ->
extract_parser_opts(Opts) -> extract_parser_opts(Opts) ->
[ {K, V} || {K, V} <- extract_parser_opts(Opts, []).
Opts, lists:member(K, [comments, encoding, unquoted_keys])
].
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 %% ensure the first jsx event we get is start_object or start_array when running
%% in strict mode %% in strict mode

View file

@ -72,9 +72,19 @@ parse_opts([], Opts) ->
extract_parser_opts(Opts) -> extract_parser_opts(Opts) ->
[ {K, V} || {K, V} <- extract_parser_opts(Opts, []).
Opts, lists:member(K, [comments, encoding, unquoted_keys])
]. 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) -> format_something({event, start_object, Next}, Opts, Level) ->

View file

@ -51,9 +51,19 @@ is_json(JSON, Opts) ->
extract_parser_opts(Opts) -> extract_parser_opts(Opts) ->
[ {K, V} || {K, V} <- extract_parser_opts(Opts, []).
Opts, lists:member(K, [comments, encoding, unquoted_keys])
]. 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 %% enforce only arrays and objects at top level