adds new utility function enable handling of anon functions in various handlers

This commit is contained in:
alisdair sullivan 2011-12-04 23:41:00 -08:00
parent 245640743d
commit 5545be32ba

View file

@ -23,7 +23,10 @@
-module(jsx_utils).
-export([parse_opts/1, extract_opts/1, nice_decimal/1, json_escape/2]).
-export([parse_opts/1, extract_opts/1]).
-export([nice_decimal/1]).
-export([json_escape/2]).
-export([handle_event/2, init/1]).
-include("../include/jsx_opts.hrl").
@ -63,6 +66,7 @@ extract_parser_opts([K|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
@ -262,6 +266,13 @@ to_hex(15) -> $f;
to_hex(X) -> X + 48. %% ascii "1" is [49], "2" is [50], etc...
handle_event(Event, {F, undefined}) -> F(Event), {F, undefined};
handle_event(Event, {F, State}) -> {F, F(Event, State)}.
init(State) -> State.
%% eunit tests
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").