summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTimothy J. Wood <tjw@omnigroup.com>2009-02-26 13:41:46 -0800
committerTimothy J. Wood <tjw@omnigroup.com>2009-02-26 13:41:46 -0800
commit1a7a73039abf621af36f73adf4a4ca77c2c94bd9 (patch)
treee7ea2f80377f3dcb2c80bfc2a9b53c5332ec29b6 /test
parentd4d5f5af2cc52d7b8c92fc2a57f18e38d1f6f5d2 (diff)
downloadyajl-1a7a73039abf621af36f73adf4a4ca77c2c94bd9.tar.gz
A simple fix for lonely_number.json
- Add new parser function, yajl_parse_complete(). This is defined to parse any buffered data assuming that there is no more input forthcoming and may issue callbacks based on that parse. - Implement this as parsing a single space character. This is sufficient to handle the problem case, a number at the end of the stream. - Updated yagl_test.c to call this when the stream ends.
Diffstat (limited to 'test')
-rw-r--r--test/yajl_test.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/test/yajl_test.c b/test/yajl_test.c
index 35bcc9d..5f1dd31 100644
--- a/test/yajl_test.c
+++ b/test/yajl_test.c
@@ -185,26 +185,33 @@ main(int argc, char ** argv)
/* ok. open file. let's read and parse */
hand = yajl_alloc(&callbacks, &cfg, NULL);
- for(;;) {
+ int done = 0;
+ while (!done) {
rd = fread((void *) fileData, 1, bufSize, stdin);
if (rd == 0) {
if (!feof(stdin)) {
fprintf(stderr, "error reading from '%s'\n", fileName);
+ break;
}
- break;
- } else {
+ done = 1;
+ }
+
+ if (done)
+ /* parse any remaining buffered data */
+ stat = yajl_parse_complete(hand);
+ else
/* read file data, pass to parser */
stat = yajl_parse(hand, fileData, rd);
- if (stat != yajl_status_insufficient_data &&
- stat != yajl_status_ok)
- {
- unsigned char * str = yajl_get_error(hand, 0, fileData, rd);
- fflush(stdout);
- fprintf(stderr, (char *) str);
- yajl_free_error(str);
- break;
- }
+
+ if (stat != yajl_status_insufficient_data &&
+ stat != yajl_status_ok)
+ {
+ unsigned char * str = yajl_get_error(hand, 0, fileData, rd);
+ fflush(stdout);
+ fprintf(stderr, (char *) str);
+ yajl_free_error(str);
+ break;
}
}