MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / jl_parse_string

Function jl_parse_string

src/cli/config_json_like.c:253–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253static int jl_parse_string(jl_parser_t *parser, size_t *start_out, size_t *end_out) {
254 if (parser->pos >= parser->length) {
255 return -1;
256 }
257 unsigned char quote = (unsigned char)parser->text[parser->pos];
258 if (quote != '"' && (parser->strict || quote != '\'')) {
259 return -1;
260 }
261
262 size_t start = parser->pos++;
263 while (parser->pos < parser->length) {
264 unsigned char c = (unsigned char)parser->text[parser->pos++];
265 if (c == quote) {
266 if (start_out) {
267 *start_out = start;
268 }
269 if (end_out) {
270 *end_out = parser->pos;
271 }
272 return 0;
273 }
274 if (c < 0x20U) {
275 return -1;
276 }
277 if (c != '\\') {
278 if (!parser->strict && c == 0xE2U && parser->length - parser->pos >= 2U &&
279 (unsigned char)parser->text[parser->pos] == 0x80U &&
280 ((unsigned char)parser->text[parser->pos + 1U] == 0xA8U ||
281 (unsigned char)parser->text[parser->pos + 1U] == 0xA9U)) {
282 return -1;
283 }
284 continue;
285 }
286 if (parser->pos >= parser->length) {
287 return -1;
288 }
289
290 unsigned char escaped = (unsigned char)parser->text[parser->pos++];
291 if (escaped == 'u') {
292 if (parser->length - parser->pos < 4U) {
293 return -1;
294 }
295 for (size_t i = 0; i < 4U; i++) {
296 if (!jl_is_hex((unsigned char)parser->text[parser->pos + i])) {
297 return -1;
298 }
299 }
300 parser->pos += 4U;
301 continue;
302 }
303 if (!parser->strict && escaped == 'x') {
304 if (parser->length - parser->pos < 2U ||
305 !jl_is_hex((unsigned char)parser->text[parser->pos]) ||
306 !jl_is_hex((unsigned char)parser->text[parser->pos + 1U])) {
307 return -1;
308 }
309 parser->pos += 2U;
310 continue;

Callers 2

jl_parse_keyFunction · 0.85
jl_parse_valueFunction · 0.85

Calls 1

jl_is_hexFunction · 0.85

Tested by

no test coverage detected