public interface begun
This commit is contained in:
parent
7468313ffc
commit
a932422d17
3 changed files with 37 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
-record(opts, {
|
-record(opts, {
|
||||||
comments = false,
|
comments = false,
|
||||||
escaped_unicode = ascii,
|
escaped_unicode = ascii,
|
||||||
naked_values = false
|
naked_values = false,
|
||||||
|
encoding = utf8
|
||||||
}).
|
}).
|
34
src/jsx.erl
Normal file
34
src/jsx.erl
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
-module(jsx).
|
||||||
|
|
||||||
|
-export([decoder/0, decoder/1]).
|
||||||
|
|
||||||
|
-include("../include/jsx.hrl").
|
||||||
|
|
||||||
|
decoder() ->
|
||||||
|
decoder([]).
|
||||||
|
|
||||||
|
decoder(OptsList) ->
|
||||||
|
OptsRec = parse_opts(OptsList),
|
||||||
|
case OptsRec#opts.encoding of
|
||||||
|
utf8 ->
|
||||||
|
fun(Stream) -> jsx_utf8:start(Stream, [], [], OptsRec) end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
parse_opts(Opts) ->
|
||||||
|
parse_opts(Opts, #opts{}).
|
||||||
|
|
||||||
|
parse_opts([], Opts) ->
|
||||||
|
Opts;
|
||||||
|
parse_opts([{comments, Value}|Rest], Opts) ->
|
||||||
|
true = lists:member(Value, [true, false]),
|
||||||
|
parse_opts(Rest, Opts#opts{comments = Value});
|
||||||
|
parse_opts([{escaped_unicode, Value}|Rest], Opts) ->
|
||||||
|
true = lists:member(Value, [ascii, codepoint, none]),
|
||||||
|
parse_opts(Rest, Opts#opts{escaped_unicode = Value});
|
||||||
|
parse_opts([{naked_values, Value}|Rest], Opts) ->
|
||||||
|
true = lists:member(Value, [true, false]),
|
||||||
|
parse_opts(Rest, Opts#opts{naked_values = Value});
|
||||||
|
parse_opts([{encoding, Value}|Rest], Opts) ->
|
||||||
|
true = lists:member(Value, [utf8]),
|
||||||
|
parse_opts(Rest, Opts#opts{encoding = Value}).
|
|
@ -204,7 +204,7 @@ escaped_unicode(<<D/utf8, Rest/binary>>, Stack, Callbacks, Opts, String, [C, B,
|
||||||
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
||||||
; codepoint ->
|
; codepoint ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
||||||
; _ ->
|
; none ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [?rsolidus, $u, A, B, C, D] ++ String)
|
string(Rest, Stack, Callbacks, Opts, [?rsolidus, $u, A, B, C, D] ++ String)
|
||||||
end;
|
end;
|
||||||
escaped_unicode(<<S/utf8, Rest/binary>>, Stack, Callbacks, Opts, String, Acc) when ?is_hex(S) ->
|
escaped_unicode(<<S/utf8, Rest/binary>>, Stack, Callbacks, Opts, String, Acc) when ?is_hex(S) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue