adds new utility function enable handling of anon functions in various handlers
This commit is contained in:
parent
245640743d
commit
5545be32ba
1 changed files with 12 additions and 1 deletions
|
@ -23,7 +23,10 @@
|
||||||
|
|
||||||
-module(jsx_utils).
|
-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").
|
-include("../include/jsx_opts.hrl").
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ extract_parser_opts([K|Rest], Acc) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% conversion of floats to 'nice' decimal output. erlang's float implementation
|
%% 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
|
%% 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
|
%% 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...
|
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
|
%% eunit tests
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue