From e245d8aa9234d2284f4142bccc4bf6a056a1e8b5 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Wed, 9 Jun 2010 06:21:03 -0700 Subject: [PATCH] tightened up options allowed --- src/jsx.erl | 12 +++++------- src/jsx_types.hrl | 7 +++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/jsx.erl b/src/jsx.erl index 97c1aba..c191bfe 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -32,7 +32,7 @@ -spec decode(JSON::json()) -> {ok, [jsx_event(),...]} | {error, badjson}. --spec decode(JSON::json(), Opts::[any()]) -> {ok, [jsx_event(),...]} | {error, badjson}. +-spec decode(JSON::json(), Opts::jsx_opts()) -> {ok, [jsx_event(),...]} | {error, badjson}. decode(JSON) -> decode(JSON, []). @@ -47,9 +47,9 @@ decode(JSON, Opts) -> -spec parser() -> jsx_parser(). --spec parser(Opts::[any()]) -> jsx_parser(). --spec parser(Callbacks::{fun((jsx_event(), any()) -> any())}, Opts::[any()]) -> jsx_parser() - ; (Callbacks::{atom(), atom(), any()}, Opts::[any()]) -> jsx_parser(). +-spec parser(Opts::jsx_opts()) -> jsx_parser(). +-spec parser(Callbacks::{fun((jsx_event(), any()) -> any())}, Opts::jsx_opts()) -> jsx_parser() + ; (Callbacks::{atom(), atom(), any()}, Opts::jsx_opts()) -> jsx_parser(). parser() -> parser([]). @@ -96,9 +96,7 @@ parse_opts([{escaped_unicode, Value}|Rest], {Comments, _EscapedUnicode, Stream}) parse_opts(Rest, {Comments, Value, Stream}); parse_opts([{stream_mode, Value}|Rest], {Comments, EscapedUnicode, _Stream}) -> true = lists:member(Value, [true, false]), - parse_opts(Rest, {Comments, EscapedUnicode, Value}); -parse_opts([_UnknownOpt|Rest], Opts) -> - parse_opts(Rest, Opts). + parse_opts(Rest, {Comments, EscapedUnicode, Value}). %% first check to see if there's a bom, if not, use the rfc4627 method for determining diff --git a/src/jsx_types.hrl b/src/jsx_types.hrl index 656bc69..fb742b4 100644 --- a/src/jsx_types.hrl +++ b/src/jsx_types.hrl @@ -27,6 +27,13 @@ -type json() :: binary(). +-type jsx_opts() :: [jsx_opt()]. +-type jsx_opt() :: {comments, true | false} + | {escaped_unicode, ascii | codepoint | none} + | {stream_mode, true | false} + | {encoding, auto | utf8 | utf16 | utf16le | utf32 | utf32le }. + + %% events emitted by the parser and component types -type unicode_codepoint() :: 0..16#10ffff.