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
|
@ -23,7 +23,7 @@
|
|||
|
||||
-module(jsx_utils).
|
||||
|
||||
-export([parse_opts/1, nice_decimal/1, json_escape/2]).
|
||||
-export([parse_opts/1, extract_opts/1, nice_decimal/1, json_escape/2]).
|
||||
|
||||
-include("../include/jsx_opts.hrl").
|
||||
|
||||
|
@ -41,10 +41,28 @@ parse_opts([escape_forward_slash|Rest], Opts) ->
|
|||
parse_opts(Rest, Opts#opts{escape_forward_slash=true});
|
||||
parse_opts([explicit_end|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts#opts{explicit_end=true});
|
||||
parse_opts([{parser, Mode}|Rest], Opts) ->
|
||||
parse_opts(Rest, Opts#opts{parser=Mode});
|
||||
parse_opts(_, _) ->
|
||||
{error, badarg}.
|
||||
|
||||
|
||||
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, parser]) 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.
|
||||
|
||||
|
||||
%% conversion of floats to 'nice' decimal output. erlang's float implementation
|
||||
%% is almost but not quite ieee 754. it converts negative zero to plain zero
|
||||
%% silently, and throws exceptions for any operations that would produce NaN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue