From 5545be32bae3b669c7f86ae2478fe30c483234c4 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sun, 4 Dec 2011 23:41:00 -0800 Subject: [PATCH] adds new utility function enable handling of anon functions in various handlers --- src/jsx_utils.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/jsx_utils.erl b/src/jsx_utils.erl index 8f1eaf9..f30c104 100644 --- a/src/jsx_utils.erl +++ b/src/jsx_utils.erl @@ -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").