Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/libpkg/json.c
2065 views
1
/*-
2
* Copyright (c) 2024-2025 Baptiste Daroussin <[email protected]>
3
*
4
* SPDX-License-Identifier: BSD-2-Clause
5
*/
6
7
#define JSMN_PARENT_LINKS 1
8
#define JSMN_STRICT 1
9
#include <jsmn.h>
10
#include <libpkg/private/json.h>
11
#include <stdio.h>
12
13
jsmntok_t *
14
jsmn_next(jsmntok_t *tok) {
15
jsmntok_t *cur = tok;
16
int cnt = tok->size;
17
18
while (cnt--) {
19
cur++;
20
cur = jsmn_next(cur);
21
}
22
return (cur);
23
}
24
25
bool
26
jsmntok_stringeq(jsmntok_t *tok, const char *line, const char *str) {
27
return (strncmp(str, line + tok->start, jsmn_toklen(tok)) == 0);
28
}
29
30
int
31
jsmntok_nextchild(jsmntok_t *tok, int tokcount, int parent, int me)
32
{
33
for (int i = me + 1; i < tokcount; i++) {
34
if ((tok + i)->parent == parent)
35
return (i);
36
/* skip all the objet child, useful if this is an array
37
* or an object
38
*/
39
i += (tok + i)->size;
40
}
41
return (-1);
42
}
43
44