Added a verification of the token type before converting to string

This commit is contained in:
Benoit Blanchon
2014-01-11 16:53:20 +01:00
parent 4713e90f12
commit 1475066edd
4 changed files with 23 additions and 15 deletions

View File

@ -6,14 +6,22 @@
#include "JsonObjectBase.h"
int JsonObjectBase::getNestedTokenCount(int tokenIndex)
int JsonObjectBase::getNestedTokenCount(jsmntok_t* token)
{
int count = 0;
for (int i = 0; i < tokens[tokenIndex].size; i++)
for (int i = 0; i < token->size; i++)
{
count += 1 + getNestedTokenCount(tokenIndex + 1 + i);
count += 1 + getNestedTokenCount(token + 1 + i);
}
return count;
}
char* JsonObjectBase::getTokenString(jsmntok_t* token)
{
if (token->type != JSMN_PRIMITIVE && token->type != JSMN_STRING)
return 0;
return json + token->start;
}