reorg of opts parsing, some minor source cleanups

This commit is contained in:
alisdair sullivan 2011-10-19 06:51:36 -07:00
parent 95dd7a67c6
commit 9c5710b97c
7 changed files with 23 additions and 210 deletions

View file

@ -23,11 +23,26 @@
-module(jsx_utils).
-export([nice_decimal/1, json_escape/2]).
-export([parse_opts/1, nice_decimal/1, json_escape/2]).
-include("../include/jsx_opts.hrl").
%% parsing of jsx opts
parse_opts(Opts) ->
parse_opts(Opts, #opts{}).
parse_opts([], Opts) ->
Opts;
parse_opts([loose_unicode|Rest], Opts) ->
parse_opts(Rest, Opts#opts{loose_unicode=true});
parse_opts([escape_forward_slash|Rest], Opts) ->
parse_opts(Rest, Opts#opts{escape_forward_slash=true});
parse_opts(_, _) ->
{error, badarg}.
%% 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
%% silently, and throws exceptions for any operations that would produce NaN
@ -39,7 +54,6 @@
%% algorithm from "Printing Floating-Point Numbers Quickly and Accurately" by
%% Burger & Dybvig
-spec nice_decimal(Float::float()) -> string().
nice_decimal(0.0) -> "0.0";
@ -162,6 +176,7 @@ digits_to_list([Digit|Digits], Dpoint, Acc) ->
%% json string escaping, for utf8 binaries. escape the json control sequences to
%% their json equivalent, escape other control characters to \uXXXX sequences,
%% everything else should be a legal json string component
json_escape(String, Opts) when is_binary(String) ->
json_escape(String, Opts, <<>>);
json_escape(String, Opts) when is_list(String) ->