| 1366 | } |
| 1367 | |
| 1368 | if (p == limit) { |
| 1369 | return utf8_expected_len((unsigned char)s[limit - 1]) > 1 ? |
| 1370 | limit - 1 : limit; |
| 1371 | } |
| 1372 | if (p == start && (((unsigned char)s[p] & 0xc0) == 0x80)) return start; |
| 1373 | |
| 1374 | size_t lead = p - 1; |
| 1375 | int need = utf8_expected_len((unsigned char)s[lead]); |
| 1376 | return (limit - lead) < (size_t)need ? lead : limit; |
| 1377 | } |
| 1378 | |
| 1379 | static bool parse_stream_options(const char **p, bool *include_usage) { |
| 1380 | json_ws(p); |
| 1381 | if (**p != '{') return json_skip_value(p); |
| 1382 | (*p)++; |
| 1383 | json_ws(p); |
| 1384 | while (**p && **p != '}') { |
| 1385 | char *key = NULL; |
| 1386 | if (!json_string(p, &key)) return false; |
| 1387 | json_ws(p); |
| 1388 | if (**p != ':') { |
| 1389 | free(key); |
| 1390 | return false; |
| 1391 | } |
| 1392 | (*p)++; |
| 1393 | if (!strcmp(key, "include_usage")) { |
| 1394 | if (!json_bool(p, include_usage)) { |
| 1395 | free(key); |
| 1396 | return false; |
| 1397 | } |
| 1398 | } else if (!json_skip_value(p)) { |
| 1399 | free(key); |
| 1400 | return false; |
| 1401 | } |
| 1402 | free(key); |
| 1403 | json_ws(p); |
| 1404 | if (**p == ',') (*p)++; |
| 1405 | json_ws(p); |
| 1406 | } |
| 1407 | if (**p != '}') return false; |
| 1408 | (*p)++; |
| 1409 | return true; |
| 1410 | } |
| 1411 | |
| 1412 | static bool parse_function_call(const char **p, tool_call *tc) { |
| 1413 | json_ws(p); |
| 1414 | if (**p != '{') return false; |
| 1415 | (*p)++; |
| 1416 | json_ws(p); |
| 1417 | while (**p && **p != '}') { |
| 1418 | char *key = NULL; |
no test coverage detected