Compare commits

..

7 Commits

Author SHA1 Message Date
P4t 053d3cd292
Merge pull request #175 from pks-t/pks/struct-type
5 years ago
Toni Uhlig a91022a07d
fix gcc/clang warning and unnecessary implicit type conversion to different size/signedness (#187)
5 years ago
Alexey Radkov 7b6858a585
Fixed a typo (value -> number) (#186)
5 years ago
Patrick Steinhardt 0837288b7c jsmn: declare struct names to allow forward decls
5 years ago
P4t 85695f3d59
Merge pull request #162 from ghane/Case-Warning
5 years ago
Sanjeev Gupta cdcfaafa49 Quieten a warning from the compiler
5 years ago
Serge Zaitsev fdcef3ebf8
Modernize (#149)
6 years ago

@ -158,7 +158,7 @@ the `js` string.
A non-negative return value of `jsmn_parse` is the number of tokens actually A non-negative return value of `jsmn_parse` is the number of tokens actually
used by the parser. used by the parser.
Passing NULL instead of the tokens array would not store parsing results, but Passing NULL instead of the tokens array would not store parsing results, but
instead the function will return the value of tokens needed to parse the given instead the function will return the number of tokens needed to parse the given
string. This can be useful if you don't know yet how many tokens to allocate. string. This can be useful if you don't know yet how many tokens to allocate.
If something goes wrong, you will get an error. Error will be one of these: If something goes wrong, you will get an error. Error will be one of these:

@ -66,7 +66,7 @@ enum jsmnerr {
* start start position in JSON data string * start start position in JSON data string
* end end position in JSON data string * end end position in JSON data string
*/ */
typedef struct { typedef struct jsmntok {
jsmntype_t type; jsmntype_t type;
int start; int start;
int end; int end;
@ -80,7 +80,7 @@ typedef struct {
* JSON parser. Contains an array of token blocks available. Also stores * JSON parser. Contains an array of token blocks available. Also stores
* the string being parsed now and current position in that string. * the string being parsed now and current position in that string.
*/ */
typedef struct { typedef struct jsmn_parser {
unsigned int pos; /* offset in the JSON string */ unsigned int pos; /* offset in the JSON string */
unsigned int toknext; /* next token to allocate */ unsigned int toknext; /* next token to allocate */
int toksuper; /* superior token node, e.g. parent object or array */ int toksuper; /* superior token node, e.g. parent object or array */
@ -154,6 +154,9 @@ static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
case ']': case ']':
case '}': case '}':
goto found; goto found;
default:
/* to quiet a warning from gcc*/
break;
} }
if (js[parser->pos] < 32 || js[parser->pos] >= 127) { if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
parser->pos = start; parser->pos = start;

@ -8,13 +8,13 @@ static int vtokeq(const char *s, jsmntok_t *t, unsigned long numtok,
if (numtok > 0) { if (numtok > 0) {
unsigned long i; unsigned long i;
int start, end, size; int start, end, size;
int type; jsmntype_t type;
char *value; char *value;
size = -1; size = -1;
value = NULL; value = NULL;
for (i = 0; i < numtok; i++) { for (i = 0; i < numtok; i++) {
type = va_arg(ap, int); type = va_arg(ap, jsmntype_t);
if (type == JSMN_STRING) { if (type == JSMN_STRING) {
value = va_arg(ap, char *); value = va_arg(ap, char *);
size = va_arg(ap, int); size = va_arg(ap, int);
@ -61,7 +61,7 @@ static int vtokeq(const char *s, jsmntok_t *t, unsigned long numtok,
return 1; return 1;
} }
static int tokeq(const char *s, jsmntok_t *tokens, int numtok, ...) { static int tokeq(const char *s, jsmntok_t *tokens, unsigned long numtok, ...) {
int ok; int ok;
va_list args; va_list args;
va_start(args, numtok); va_start(args, numtok);
@ -70,7 +70,7 @@ static int tokeq(const char *s, jsmntok_t *tokens, int numtok, ...) {
return ok; return ok;
} }
static int parse(const char *s, int status, int numtok, ...) { static int parse(const char *s, int status, unsigned long numtok, ...) {
int r; int r;
int ok = 1; int ok = 1;
va_list args; va_list args;

Loading…
Cancel
Save