mirror of
https://github.com/outbackdingo/nDPId.git
synced 2026-01-27 18:19:39 +00:00
- Added possibility to specify the lenght of the input buffer (if not null-terminated).
- Added "extern C" to use it with CPP.
This commit is contained in:
10
jsmn.c
10
jsmn.c
@@ -1,4 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "jsmn.h"
|
||||
|
||||
@@ -143,13 +144,18 @@ static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
|
||||
/**
|
||||
* Parse JSON string and fill tokens.
|
||||
*/
|
||||
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens,
|
||||
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, int js_length, jsmntok_t *tokens,
|
||||
unsigned int num_tokens) {
|
||||
jsmnerr_t r;
|
||||
int i;
|
||||
jsmntok_t *token;
|
||||
|
||||
if (js_length <= 0)
|
||||
{
|
||||
js_length = INT_MAX;
|
||||
}
|
||||
|
||||
for (; js[parser->pos] != '\0'; parser->pos++) {
|
||||
for (; parser->pos < js_length && js[parser->pos] != '\0'; parser->pos++) {
|
||||
char c;
|
||||
jsmntype_t type;
|
||||
|
||||
|
||||
10
jsmn.h
10
jsmn.h
@@ -1,6 +1,10 @@
|
||||
#ifndef __JSMN_H_
|
||||
#define __JSMN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* JSON type identifier. Basic types are:
|
||||
* o Object
|
||||
@@ -61,7 +65,11 @@ void jsmn_init(jsmn_parser *parser);
|
||||
* Run JSON parser. It parses a JSON data string into and array of tokens, each describing
|
||||
* a single JSON object.
|
||||
*/
|
||||
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js,
|
||||
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, int js_length,
|
||||
jsmntok_t *tokens, unsigned int num_tokens);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __JSMN_H_ */
|
||||
|
||||
Reference in New Issue
Block a user