From 6f4e2f7a565fb779159a299efe6e1e5110c2f1a6 Mon Sep 17 00:00:00 2001 From: del6597 Date: Wed, 17 Jul 2013 00:05:47 -0400 Subject: [PATCH] Added a method for jsmn_estimate_tokens(const char *json); --- jsmn.c | 22 ++++++++++++++++++++++ jsmn.h | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/jsmn.c b/jsmn.c index 1b918f5..77117fc 100644 --- a/jsmn.c +++ b/jsmn.c @@ -1,4 +1,5 @@ #include +#include #include "jsmn.h" @@ -31,6 +32,27 @@ static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type, token->size = 0; } +/** + * Estimate the number of JSON tokens in the string given. + * It should return a number greater than or equal to the actual amount of items. + * If the JSON string is malformed an incorrect number will be returned. + * Of course if the malformed string is going to be parsed, then parsing + * will fail anyway. + */ +int jsmn_count_tokens(const char *json) { + int c = 1; + int i; + for(i=0;i