Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
alisdair sullivan 2013-10-29 19:49:46 +00:00
commit 4d7c1c5c18
9 changed files with 52 additions and 11 deletions

View file

@ -63,8 +63,15 @@ encode(Source, Config) -> jsx_to_json:to_json(Source, Config).
%% old api, alias for encode/x
-spec to_json(Source::json_term()) -> json_text() | {incomplete, encoder()}.
-spec to_json(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}.
to_json(Source) -> encode(Source, []).
to_json(Source, Config) -> encode(Source, Config).
-spec term_to_json(Source::json_term()) -> json_text() | {incomplete, encoder()}.
-spec term_to_json(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}.
term_to_json(Source) -> encode(Source, []).
term_to_json(Source, Config) -> encode(Source, Config).
@ -94,8 +101,15 @@ decode(Source, Config) -> jsx_to_term:to_term(Source, Config).
%% old api, alias for to_term/x
-spec to_term(Source::json_text()) -> json_term() | {incomplete, decoder()}.
-spec to_term(Source::json_text(), Config::jsx_to_term:config()) -> json_term() | {incomplete, decoder()}.
to_term(Source) -> decode(Source, []).
to_term(Source, Config) -> decode(Source, Config).
-spec json_to_term(Source::json_text()) -> json_term() | {incomplete, decoder()}.
-spec json_to_term(Source::json_text(), Config::jsx_to_term:config()) -> json_term() | {incomplete, decoder()}.
json_to_term(Source) -> decode(Source, []).
json_to_term(Source, Config) -> decode(Source, Config).

View file

@ -35,6 +35,8 @@
%% parsing of jsx config
-spec parse_config(Config::proplists:proplist()) -> config().
parse_config(Config) ->
parse_config(Config, #config{}).
@ -102,6 +104,8 @@ parse_config(Options, Config) ->
erlang:error(badarg, [Options, Config]).
-spec config_to_list(Config::config()) -> proplists:proplist().
config_to_list(Config) ->
lists:map(
fun ({pre_encode, F}) -> {pre_encode, F};
@ -116,6 +120,8 @@ config_to_list(Config) ->
).
-spec valid_flags() -> [atom()].
valid_flags() ->
[
replaced_bad_utf8,
@ -142,6 +148,8 @@ valid_flags() ->
].
-spec extract_config(Config::proplists:proplist()) -> proplists:proplist().
extract_config(Config) ->
extract_parser_config(Config, []).
@ -305,4 +313,4 @@ config_to_list_test_() ->
fake_error_handler(_, _, _) -> ok.
-endif.
-endif.

View file

@ -11,4 +11,6 @@
pre_encode = false,
error_handler = false,
incomplete_handler = false
}).
}).
-type config() :: #config{}.

View file

@ -48,7 +48,7 @@ decoder(Handler, State, Config) ->
Acc::any(),
Stack::list(atom()),
Config::jsx:config()
) -> jsx:decoder().
) -> jsx:decoder() | {incomplete, _}.
resume(Rest, State, Handler, Acc, Stack, Config) ->
case State of
@ -2097,4 +2097,4 @@ custom_incomplete_handler_test_() ->
].
-endif.
-endif.

View file

@ -36,12 +36,12 @@ parser(Handler, State, Config) ->
%% resume allows continuation from interrupted decoding without having to explicitly export
%% all states
-spec resume(
Rest::binary(),
Rest::list(), %% was binary(),
State::atom(),
Handler::{atom(), any()},
Stack::list(atom()),
Config::jsx:config()
) -> jsx:parser().
) -> jsx:parser() | {incomplete, _}.
resume(Rest, State, Handler, Stack, Config) ->
case State of
@ -208,8 +208,12 @@ clean_string(Bin, Tokens, Handler, Stack, Config) ->
%% for raw input
-spec init(proplists:proplist()) -> list().
init([]) -> [].
-spec handle_event(Event::any(), Acc::list()) -> list().
handle_event(end_json, State) -> lists:reverse(State);
handle_event(Event, State) -> [Event] ++ State.
@ -313,4 +317,4 @@ raw_test_() ->
].
-endif.
-endif.

View file

@ -34,6 +34,7 @@
}).
-type config() :: list().
-export_type([config/0]).
-spec to_json(Source::any(), Config::config()) -> binary().
@ -85,10 +86,12 @@ parse_config([], Config) ->
-define(newline, <<"\n">>).
-type state() :: {any(), unicode:charlist(), #config{}}.
-spec init(Config::proplists:proplist()) -> state().
init(Config) -> {start, [], parse_config(Config)}.
-spec handle_event(Event::any(), State::state()) -> state().
handle_event(Event, {start, Acc, Config}) ->
case Event of
@ -304,4 +307,4 @@ handle_event_test_() ->
].
-endif.
-endif.

View file

@ -33,6 +33,8 @@
}).
-type config() :: list().
-export_type([config/0]).
-type json_value() :: list({binary(), json_value()})
| list(json_value())
@ -72,9 +74,12 @@ parse_config([K|Rest] = Options, Config) ->
parse_config([], Config) ->
Config.
-type state() :: {[any()], #config{}}.
-spec init(Config::proplists:proplist()) -> state().
init(Config) -> {[[]], parse_config(Config)}.
-spec handle_event(Event::any(), State::state()) -> state().
handle_event(end_json, {[[Terms]], _Config}) -> Terms;

View file

@ -32,6 +32,7 @@
}).
-type config() :: [].
-export_type([config/0]).
-spec is_json(Source::binary(), Config::config()) -> true | false.
@ -72,10 +73,14 @@ parse_config([K|Rest] = Options, Config) ->
parse_config([], Config) ->
Config.
-type state() :: {#config{}, any()}.
-spec init(Config::proplists:proplist()) -> state().
init(Config) -> {parse_config(Config), []}.
-spec handle_event(Event::any(), State::state()) -> state().
handle_event(end_json, _) -> true;
handle_event(_, {Config, _} = State) when Config#config.repeated_keys == true -> State;
@ -165,4 +170,4 @@ handle_event_test_() ->
].
-endif.
-endif.