rewrote extraction of core parser options in various components in a consistent manner

This commit is contained in:
alisdair sullivan 2010-09-23 22:26:04 -07:00
parent ea32b3db40
commit b73e506fe2
2 changed files with 8 additions and 25 deletions

View file

@ -43,13 +43,15 @@
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
is_json(JSON, Opts) ->
Encoding = proplists:get_value(encoding, Opts, utf8),
Comments = proplists:get_value(comments, Opts, false),
P = jsx:parser([{encoding, Encoding}, {comments, Comments}]),
P = jsx:parser(extract_parser_opts(Opts)),
case proplists:get_value(strict, Opts, true) of
true -> collect_strict(P(JSON), [[]])
; false -> collect(P(JSON), [[]])
end.
extract_parser_opts(Opts) ->
[ {K, V} || {K, V} <- Opts, lists:member(K, [comments, encoding]) ].
%% enforce only arrays and objects at top level