33 #define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL 34 #define LLONG_MIN (-0x7FFFFFFFFFFFFFFFLL - 1) 37 #define MAX_VALUE_TO_MULTIPLY ((LLONG_MAX / 10) + (LLONG_MAX % 10)) 45 const unsigned char *pos = number;
46 if (*pos ==
'-') { pos++; sign = -1; }
47 if (*pos ==
'+') { pos++; }
49 while (pos < number + length) {
59 ret += (*pos++ -
'0');
67 size_t jsonTextLen,
int verbose)
71 const char * errorType =
NULL;
72 const char * errorText =
NULL;
74 const char * arrow =
" (right here) ------^\n";
80 errorType =
"lexical";
83 errorType =
"unknown";
88 memneeded += strlen(errorType);
89 memneeded += strlen(
" error");
90 if (errorText !=
NULL) {
91 memneeded += strlen(
": ");
92 memneeded += strlen(errorText);
95 if (!str)
return NULL;
97 strcat((
char *) str, errorType);
98 strcat((
char *) str,
" error");
99 if (errorText !=
NULL) {
100 strcat((
char *) str,
": ");
101 strcat((
char *) str, errorText);
103 strcat((
char *) str,
"\n");
109 size_t start, end,
i;
112 spacesNeeded = (offset < 30 ? 40 - offset : 10);
113 start = (offset >= 30 ? offset - 30 : 0);
114 end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
116 for (i=0;i<spacesNeeded;i++) text[i] =
' ';
118 for (;start < end;start++, i++) {
119 if (jsonText[start] !=
'\n' && jsonText[start] !=
'\r')
121 text[
i] = jsonText[start];
132 char * newStr = (
char *)
134 strlen((
char *) text) +
138 strcat((
char *) newStr, (
char *) str);
139 strcat((
char *) newStr, text);
140 strcat((
char *) newStr, arrow);
143 str = (
unsigned char *) newStr;
152 yajl_bs_set(hand->stateStack, yajl_state_parse_error); \ 154 "client cancelled parse via callback return value"; \ 155 return yajl_status_client_canceled; \ 191 const unsigned char * buf;
205 if (*offset != jsonTextLen) {
207 offset, &buf, &bufLen);
234 offset, &buf, &bufLen);
284 hand->
ctx,(
const char *) buf, bufLen));
295 if (*offset >= bufLen) *offset -= bufLen;
308 hand->
ctx, (
const char *) buf, bufLen));
314 d = strtod((
char *) buf,
NULL);
315 if ((d == HUGE_VAL || d == -HUGE_VAL) &&
320 hand->
parseError =
"numeric (floating point) " 323 if (*offset >= bufLen) *offset -= bufLen;
352 "unallowed token at this point in JSON text";
356 hand->
parseError =
"invalid token, internal error";
382 offset, &buf, &bufLen);
418 "invalid object key (must be a string)";
424 offset, &buf, &bufLen);
436 hand->
parseError =
"object key and value must " 437 "be separated by a colon (':')";
443 offset, &buf, &bufLen);
461 hand->
parseError =
"after key and value, inside map, " 462 "I expect ',' or '}'";
464 if (*offset >= bufLen) *offset -= bufLen;
471 offset, &buf, &bufLen);
490 "after array element, I expect ',' or ']'";
#define YA_MALLOC(afs, sz)
int(* yajl_null)(void *ctx)
#define assert(exp)
Declare that a condition should be true.
yajl_lex_error yajl_lex_get_error(yajl_lexer lexer)
#define YA_FREE(afs, ptr)
int(* yajl_double)(void *ctx, double doubleVal)
const char * yajl_lex_error_to_string(yajl_lex_error error)
int(* yajl_integer)(void *ctx, long long integerVal)
#define yajl_bs_push(obs, byte)
#define yajl_bs_set(obs, byte)
#define yajl_bs_current(obs)
int(* yajl_number)(void *ctx, const char *numberVal, size_t numberLen)
int(* yajl_end_map)(void *ctx)
unsigned char * yajl_render_error_string(yajl_handle hand, const unsigned char *jsonText, size_t jsonTextLen, int verbose)
yajl_status yajl_do_parse(yajl_handle hand, const unsigned char *jsonText, size_t jsonTextLen)
size_t yajl_buf_len(yajl_buf buf)
void yajl_buf_append(yajl_buf buf, const void *data, size_t len)
Interface to YAJL's JSON stream parsing facilities.
int(* yajl_map_key)(void *ctx, const unsigned char *key, size_t stringLen)
yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char *jsonText, size_t jsonTextLen, size_t *offset, const unsigned char **outBuf, size_t *outLen)
#define MAX_VALUE_TO_MULTIPLY
void yajl_buf_clear(yajl_buf buf)
int(* yajl_start_array)(void *ctx)
long long yajl_parse_integer(const unsigned char *number, size_t length)
int(* yajl_start_map)(void *ctx)
int(* yajl_end_array)(void *ctx)
yajl_status yajl_do_finish(yajl_handle hand)
const yajl_callbacks * callbacks
const unsigned char * yajl_buf_data(yajl_buf buf)
void yajl_string_decode(yajl_buf buf, const unsigned char *str, size_t len)
yajl_bytestack stateStack
int(* yajl_boolean)(void *ctx, int boolVal)
int(* yajl_string)(void *ctx, const unsigned char *stringVal, size_t stringLen)