encoder now only performs a single pass on strings and can optionally json encode them
This commit is contained in:
parent
821a8ac06e
commit
5bc8bfdf45
4 changed files with 70 additions and 62 deletions
|
@ -39,7 +39,7 @@
|
|||
-spec to_json(Source::any(), Opts::opts()) -> binary().
|
||||
|
||||
to_json(Source, Opts) when is_list(Opts) ->
|
||||
(jsx:encoder(?MODULE, Opts, jsx_utils:extract_opts(Opts)))(Source).
|
||||
(jsx:encoder(?MODULE, Opts, jsx_utils:extract_opts([json_escape] ++ Opts)))(Source).
|
||||
|
||||
|
||||
-spec format(Source::binary(), Opts::opts()) -> binary().
|
||||
|
@ -135,8 +135,8 @@ handle_event(Event, {[array|Stack], Acc, Opts = #opts{depth = Depth}}) ->
|
|||
handle_event(end_json, {[], Acc, _Opts}) -> unicode:characters_to_binary(Acc, utf8).
|
||||
|
||||
|
||||
encode(string, String, Opts) ->
|
||||
[?quote, jsx_utils:json_escape(String, Opts), ?quote];
|
||||
encode(string, String, _Opts) ->
|
||||
[?quote, String, ?quote];
|
||||
encode(literal, Literal, _Opts) ->
|
||||
erlang:atom_to_list(Literal);
|
||||
encode(integer, Integer, _Opts) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue