json_lex(JsonLexContext *lex)
{
char *s;
- int len;
+ char *const end = lex->input + lex->input_length;
JsonParseErrorType result;
/* Skip leading whitespace. */
s = lex->token_terminator;
- len = s - lex->input;
- while (len < lex->input_length &&
- (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))
+ while (s < end && (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))
{
if (*s++ == '\n')
{
++lex->line_number;
lex->line_start = s;
}
- len++;
}
lex->token_start = s;
/* Determine token type. */
- if (len >= lex->input_length)
+ if (s >= end)
{
lex->token_start = NULL;
lex->prev_token_terminator = lex->token_terminator;
* the whole word as an unexpected token, rather than just
* some unintuitive prefix thereof.
*/
- for (p = s; p - s < lex->input_length - len && JSON_ALPHANUMERIC_CHAR(*p); p++)
+ for (p = s; p < end && JSON_ALPHANUMERIC_CHAR(*p); p++)
/* skip */ ;
/*
json_lex_string(JsonLexContext *lex)
{
char *s;
- int len;
+ char *const end = lex->input + lex->input_length;
int hi_surrogate = -1;
if (lex->strval != NULL)
Assert(lex->input_length > 0);
s = lex->token_start;
- len = lex->token_start - lex->input;
for (;;)
{
s++;
- len++;
/* Premature end of the string. */
- if (len >= lex->input_length)
+ if (s >= end)
{
lex->token_terminator = s;
return JSON_INVALID_TOKEN;
{
/* OK, we have an escape character. */
s++;
- len++;
- if (len >= lex->input_length)
+ if (s >= end)
{
lex->token_terminator = s;
return JSON_INVALID_TOKEN;
for (i = 1; i <= 4; i++)
{
s++;
- len++;
- if (len >= lex->input_length)
+ if (s >= end)
{
lex->token_terminator = s;
return JSON_INVALID_TOKEN;