general cleanup of modules, moved most types, specs, defines and records to header files and did some minor reformatting to adhere to style guidelines
This commit is contained in:
parent
86b4fbbec9
commit
c098b06e88
16 changed files with 247 additions and 147 deletions
51
include/jsx.hrl
Normal file
51
include/jsx.hrl
Normal file
|
@ -0,0 +1,51 @@
|
|||
%% The MIT License
|
||||
|
||||
%% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
|
||||
|
||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%% of this software and associated documentation files (the "Software"), to deal
|
||||
%% in the Software without restriction, including without limitation the rights
|
||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%% copies of the Software, and to permit persons to whom the Software is
|
||||
%% furnished to do so, subject to the following conditions:
|
||||
|
||||
%% The above copyright notice and this permission notice shall be included in
|
||||
%% all copies or substantial portions of the Software.
|
||||
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
|
||||
-include("jsx_common.hrl").
|
||||
|
||||
|
||||
|
||||
%% opts record
|
||||
-record(opts, {
|
||||
comments = false,
|
||||
escaped_unicode = codepoint,
|
||||
multi_term = false,
|
||||
encoding = auto
|
||||
}).
|
||||
|
||||
|
||||
-spec parser() -> jsx_parser().
|
||||
-spec parser(Opts::jsx_opts()) -> jsx_parser().
|
||||
|
||||
-spec term_to_json(JSON::eep0018()) -> binary().
|
||||
-spec term_to_json(JSON::eep0018(), Opts::encoder_opts()) -> binary().
|
||||
|
||||
-spec json_to_term(JSON::binary()) -> eep0018().
|
||||
-spec json_to_term(JSON::binary(), Opts::decoder_opts()) -> eep0018().
|
||||
|
||||
-spec is_json(JSON::binary()) -> true | false.
|
||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
|
||||
|
||||
-spec format(JSON::binary()) -> binary() | iolist().
|
||||
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist().
|
||||
|
||||
-spec eventify(List::list()) -> jsx_parser_result().
|
|
@ -21,8 +21,10 @@
|
|||
%% THE SOFTWARE.
|
||||
|
||||
|
||||
%% unsure of how to specify a binary with a complex structure like utfx encoded
|
||||
%% binaries. this should be further limited somehow probably.
|
||||
|
||||
-define(is_utf_encoding(X),
|
||||
X == utf8; X == utf16; X == utf32; X == {utf16, little}; X == {utf32, little}
|
||||
).
|
||||
|
||||
|
||||
-type jsx_opts() :: [jsx_opt()].
|
||||
|
@ -33,7 +35,6 @@
|
|||
|
||||
|
||||
%% events emitted by the parser and component types
|
||||
|
||||
-type unicode_codepoint() :: 0..16#10ffff.
|
||||
-type unicode_string() :: [unicode_codepoint()].
|
||||
|
||||
|
@ -52,7 +53,6 @@
|
|||
|
||||
|
||||
%% this probably doesn't work properly
|
||||
|
||||
-type jsx_parser() :: fun((binary()) -> jsx_parser_result()).
|
||||
|
||||
-type jsx_parser_result() :: {event, jsx_event(), fun(() -> jsx_parser_result())}
|
||||
|
@ -60,7 +60,11 @@
|
|||
| {error, badjson}
|
||||
| ok.
|
||||
|
||||
|
||||
|
||||
-type supported_utf() :: utf8 | utf16 | {utf16, little} | utf32 | {utf32, little}.
|
||||
|
||||
|
||||
%% eep0018 json specification
|
||||
-type eep0018() :: eep0018_object() | eep0018_array().
|
||||
|
||||
-type eep0018_array() :: [eep0018_term()].
|
||||
|
@ -75,9 +79,6 @@
|
|||
-type eep0018_number() :: float() | integer().
|
||||
|
||||
|
||||
-type supported_utf() :: utf8 | utf16 | {utf16, little} | utf32 | {utf32, little}.
|
||||
|
||||
|
||||
-type encoder_opts() :: [encoder_opt()].
|
||||
-type encoder_opt() :: {strict, true | false}
|
||||
| {encoding, supported_utf()}
|
||||
|
@ -87,7 +88,6 @@
|
|||
| indent.
|
||||
|
||||
|
||||
|
||||
-type decoder_opts() :: [decoder_opt()].
|
||||
-type decoder_opt() :: {strict, true | false}
|
||||
| {comments, true | false}
|
|
@ -20,6 +20,13 @@
|
|||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
|
||||
-include("./include/jsx_common.hrl").
|
||||
|
||||
|
||||
|
||||
-spec parse(JSON::eep0018(), Opts::jsx_opts()) -> jsx_parser_result().
|
||||
|
||||
|
||||
%% option flags
|
||||
|
||||
-define(comments_enabled(X), {_, true, _, _, _} = X).
|
||||
|
|
30
include/jsx_eep0018.hrl
Normal file
30
include/jsx_eep0018.hrl
Normal file
|
@ -0,0 +1,30 @@
|
|||
%% The MIT License
|
||||
|
||||
%% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
|
||||
|
||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%% of this software and associated documentation files (the "Software"), to deal
|
||||
%% in the Software without restriction, including without limitation the rights
|
||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%% copies of the Software, and to permit persons to whom the Software is
|
||||
%% furnished to do so, subject to the following conditions:
|
||||
|
||||
%% The above copyright notice and this permission notice shall be included in
|
||||
%% all copies or substantial portions of the Software.
|
||||
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
|
||||
-include("jsx_common.hrl").
|
||||
|
||||
|
||||
|
||||
-spec json_to_term(JSON::binary(), Opts::decoder_opts()) -> eep0018().
|
||||
|
||||
-spec term_to_json(JSON::eep0018(), Opts::encoder_opts()) -> binary().
|
||||
|
46
include/jsx_format.hrl
Normal file
46
include/jsx_format.hrl
Normal file
|
@ -0,0 +1,46 @@
|
|||
%% The MIT License
|
||||
|
||||
%% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
|
||||
|
||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%% of this software and associated documentation files (the "Software"), to deal
|
||||
%% in the Software without restriction, including without limitation the rights
|
||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%% copies of the Software, and to permit persons to whom the Software is
|
||||
%% furnished to do so, subject to the following conditions:
|
||||
|
||||
%% The above copyright notice and this permission notice shall be included in
|
||||
%% all copies or substantial portions of the Software.
|
||||
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
|
||||
-include("jsx_common.hrl").
|
||||
|
||||
|
||||
|
||||
-record(opts, {
|
||||
space = 0,
|
||||
indent = 0,
|
||||
output_encoding = utf8,
|
||||
strict = true
|
||||
}).
|
||||
|
||||
|
||||
-define(newline, $\n).
|
||||
-define(space, 16#20). %% ascii code for space
|
||||
-define(quote, $\").
|
||||
-define(comma, $,).
|
||||
-define(colon, $:).
|
||||
-define(start_object, ${).
|
||||
-define(end_object, $}).
|
||||
-define(start_array, $[).
|
||||
-define(end_array, $]).
|
||||
|
||||
|
||||
-spec format(JSON::binary(), Opts::format_opts()) -> binary() | iolist().
|
27
include/jsx_verify.hrl
Normal file
27
include/jsx_verify.hrl
Normal file
|
@ -0,0 +1,27 @@
|
|||
%% The MIT License
|
||||
|
||||
%% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
|
||||
|
||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%% of this software and associated documentation files (the "Software"), to deal
|
||||
%% in the Software without restriction, including without limitation the rights
|
||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%% copies of the Software, and to permit persons to whom the Software is
|
||||
%% furnished to do so, subject to the following conditions:
|
||||
|
||||
%% The above copyright notice and this permission notice shall be included in
|
||||
%% all copies or substantial portions of the Software.
|
||||
|
||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%% THE SOFTWARE.
|
||||
|
||||
-include("jsx_common.hrl").
|
||||
|
||||
|
||||
|
||||
-spec is_json(JSON::binary(), Opts::verify_opts()) -> true | false.
|
Loading…
Add table
Add a link
Reference in a new issue