* Fills next available token with JSON primitive. */
| 134 | * Fills next available token with JSON primitive. |
| 135 | */ |
| 136 | static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, |
| 137 | const size_t len, jsmntok_t *tokens, |
| 138 | const size_t num_tokens) { |
| 139 | jsmntok_t *token; |
| 140 | int start; |
| 141 | |
| 142 | start = parser->pos; |
| 143 | |
| 144 | for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { |
| 145 | switch (js[parser->pos]) { |
| 146 | #ifndef JSMN_STRICT |
| 147 | /* In strict mode primitive must be followed by "," or "}" or "]" */ |
| 148 | case ':': |
| 149 | #endif |
| 150 | case '\t': |
| 151 | case '\r': |
| 152 | case '\n': |
| 153 | case ' ': |
| 154 | case ',': |
| 155 | case ']': |
| 156 | case '}': |
| 157 | goto found; |
| 158 | default: |
| 159 | /* to quiet a warning from gcc*/ |
| 160 | break; |
| 161 | } |
| 162 | if (js[parser->pos] < 32 || js[parser->pos] >= 127) { |
| 163 | parser->pos = start; |
| 164 | return JSMN_ERROR_INVAL; |
| 165 | } |
| 166 | } |
| 167 | #ifdef JSMN_STRICT |
| 168 | /* In strict mode primitive must be followed by a comma/object/array */ |
| 169 | parser->pos = start; |
| 170 | return JSMN_ERROR_PART; |
| 171 | #endif |
| 172 | |
| 173 | found: |
| 174 | if (tokens == NULL) { |
| 175 | parser->pos--; |
| 176 | return 0; |
| 177 | } |
| 178 | token = jsmn_alloc_token(parser, tokens, num_tokens); |
| 179 | if (token == NULL) { |
| 180 | parser->pos = start; |
| 181 | return JSMN_ERROR_NOMEM; |
| 182 | } |
| 183 | jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); |
| 184 | #ifdef JSMN_PARENT_LINKS |
| 185 | token->parent = parser->toksuper; |
| 186 | #endif |
| 187 | parser->pos--; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Fills next token with JSON string. |
no test coverage detected