]> git.evergreen-ils.org Git - OpenSRF.git/commit
Patch from Scott McKellar:
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Sat, 5 Jan 2008 19:07:02 +0000 (19:07 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Sat, 5 Jan 2008 19:07:02 +0000 (19:07 +0000)
commit2f83f103b758a32d6213ec0b84918438f0bc7524
tree63ead9c4170e2935f6bd877a40acec96f15c2193
parente99f825cfc48b03ef4dd070bade0cb20281cf1ce
Patch from Scott McKellar:

These patches are the culmination of several postings on this subject.
The overall effect is to store numbers in jsonObjects as strings,
rather than as doubles, in order to avoid needless loss of precision
in translating back and forth between text and floating point
representations.

I shall not repeat the details outlined in previous posts, but rather
focus on what's new:

1. A new extern function jsonNewNumberStringObject constructs a
JSON_NUMBER from a character string.  If the string is not numeric
according to JSON rules, the function returns NULL.

2. A new extern function jsonScrubNumber accepts a character string
and reformats it, if possible, into a numeric string that is valid
according to JSON rules.  For example, it transforms "  +00.42"
into "0.42".  The transformed string is returned as a char* that
the caller is responsible for freeing.

jsonScrubNumber performs this transformation by manipulating text,
not by passing the value through a double.  Therefore it can handle
numbers that would be too long, too large, or too small for strtod()
and its kindred to handle.

It accepts leading white space and scientific notation, but not
trailing white space, hex, or octal.

If the input string is not numeric, jsonScrubNumber returns NULL.

3. The doubleToString function now translates the incoming double
to a character string with up to 30 decimal digits of precision.
That should be enough to minimize the impact on existing code,
depending of course on how faithfully snprintf() does the formatting.

4. In osrf_json.h: I changed the signature of the next-to-last
function pointer in a jsonParserHandler, so that it accepts a
character pointer instead of a double.  Likewise for the corresponding
declaration of _jsonHandleNumber in osrf_json_utils.h.

5. In osrf_json_parser.c: I construct a JSON_NUMBER from the input
character string without passing it through a double.  If the input
character string is not valid according to JSON rules, I try to use
the new jsonScrubNumber() to normalize the formatting so that JSON
can accept it.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1199 9efc2488-bf62-4759-914b-345cdb29e865
include/opensrf/osrf_json.h
include/opensrf/osrf_json_utils.h
src/libopensrf/osrf_json_object.c
src/libopensrf/osrf_json_parser.c