MCPcopy Index your code
hub / github.com/IBM/Project_CodeNet / jsmn_parse_primitive

Function jsmn_parse_primitive

tools/json-graph/src/jsmn.h:136–189  ·  view source on GitHub ↗

* Fills next available token with JSON primitive. */

Source from the content-addressed store, hash-verified

134 * Fills next available token with JSON primitive.
135 */
136static 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
173found:
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.

Callers 1

jsmn_parseFunction · 0.85

Calls 2

jsmn_alloc_tokenFunction · 0.85
jsmn_fill_tokenFunction · 0.85

Tested by

no test coverage detected