[erlang-questions] fast JSON parser in C
Richard A. O'Keefe
ok@REDACTED
Wed Jul 30 05:24:35 CEST 2008
In json_lex2.xrl we find
whole_float(TokenChars) ->
{ok, NowFloat, 1} = regexp:sub(TokenChars, "e", ".0e"),
list_to_float(NowFloat).
I note that the Leex pattern for the token string
allows capital E, but this regular expression doesn't seem to.
\-?{D}+((E|e)(\+|\-)?{D+}
^
I therefore suggest
whole_float(Token_Chars) ->
list_to_float(insert_point_zero(Token_Chars)).
insert_point_zero([$e|Cs]) -> ".0e" ++ Cs;
insert_point_zero([$E|Cs]) -> ".0e" ++ Cs;
insert_point_zero([C |Cs]) -> [C | insert_point_zero(Cs)].
which also avoids the overheads of regular expressions.
More information about the erlang-questions
mailing list