src/c/json.c
static int iot_json_parse_primitive (iot_json_parser * parser, const char *js, size_t len, iot_json_tok_t * tokens, uint32_t num_tokens)
{
  iot_json_tok_t * token;
  uint32_t start = parser->pos;

  for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
  {
    switch (js[parser->pos])
    {
#ifndef JSON_STRICT
      /* In strict mode primitive must be followed by "," or "}" or "]" */
      case ':':
#endif
      case '\t':
      case '\r':
      case '\n':
      case ' ':
      case ',':
      case ']':
      case '}': goto FOUND;
      default: break;
    }
    if (js[parser->pos] < 32 || js[parser->pos] >= 127)
    {
      parser->pos = start;
      return IOT_JSON_ERROR_INVAL;
    }
  }
#ifdef JSON_STRICT
  /* In strict mode primitive must be followed by a comma/object/array */
  parser->pos = start;
  return JSON_ERROR_PART;
#endif

FOUND:
  if (tokens == NULL)
  {
    parser->pos--;
    return 0;
  }
  token = iot_json_alloc_token (parser, tokens, num_tokens);
  if (token == NULL)
  {
    parser->pos = start;
    return IOT_JSON_ERROR_NOMEM;
  }
  iot_json_fill_token (token, IOT_JSON_PRIMITIVE, start, parser->pos);
  token->parent = parser->toksuper;
  parser->pos--;
  return 0;
}
/**
 * Fills next available token with JSON primitive.
 */
Fills next available token with JSON primitive.
Fills next available token with JSON primitive .
static int iot_json_parse_primitive (iot_json_parser * parser, const char *js, size_t len, iot_json_tok_t * tokens, uint32_t num_tokens)
{
  iot_json_tok_t * token;
  uint32_t start = parser->pos;
  for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
  {
    switch (js[parser->pos])
    {
#ifndef JSON_STRICT
      case ':':
#endif
      case '\t':
      case '\r':
      case '\n':
      case ' ':
      case ',':
      case ']':
      case '}': goto FOUND;
      default: break;
    }
    if (js[parser->pos] < 32 || js[parser->pos] >= 127)
    {
      parser->pos = start;
      return IOT_JSON_ERROR_INVAL;
    }
  }
#ifdef JSON_STRICT
  parser->pos = start;
  return JSON_ERROR_PART;
#endif
FOUND:
  if (tokens == NULL)
  {
    parser->pos--;
    return 0;
  }
  token = iot_json_alloc_token (parser, tokens, num_tokens);
  if (token == NULL)
  {
    parser->pos = start;
    return IOT_JSON_ERROR_NOMEM;
  }
  iot_json_fill_token (token, IOT_JSON_PRIMITIVE, start, parser->pos);
  token->parent = parser->toksuper;
  parser->pos--;
  return 0;
}
static int iot_json_parse_primitive ( iot_json_parser * parser , const char * js , size_t len , iot_json_tok_t * tokens , uint32_t num_tokens ) { iot_json_tok_t * token ; uint32_t start = parser -> pos ; for ( ; parser -> pos < len && js [ parser -> pos ] != ' \0 ' ; parser -> pos ++ ) { switch ( js [ parser -> pos ] ) { #ifndef JSON_STRICT case ' ' : #endif case ' \t ' : case ' \r ' : case ' \n ' : case ' ' : case ' ' : case ' ' : case ' ' : goto FOUND ; default : break ; } if ( js [ parser -> pos ] < 32 || js [ parser -> pos ] >= 127 ) { parser -> pos = start ; return IOT_JSON_ERROR_INVAL ; } } #ifdef JSON_STRICT parser -> pos = start ; return JSON_ERROR_PART ; #endif FOUND : if ( tokens == NULL ) { parser -> pos -- ; return 0 ; } token = iot_json_alloc_token ( parser , tokens , num_tokens ) ; if ( token == NULL ) { parser -> pos = start ; return IOT_JSON_ERROR_NOMEM ; } iot_json_fill_token ( token , IOT_JSON_PRIMITIVE , start , parser -> pos ) ; token -> parent = parser -> toksuper ; parser -> pos -- ; return 0 ; }
Fills next available token with JSON primitive.
Fills next available token with JSON primitive .
/* In strict mode primitive must be followed by "," or "}" or "]" */ /* In strict mode primitive must be followed by a comma/object/array */