Skip to content

Commit 485d191

Browse files
committed
jimp: jimp_array_has_items -> jimp_array_item
1 parent e9c9c3c commit 485d191

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

jimp.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool parse_person(Jimp *jimp, Person *p)
4242
bool parse_people(Jimp *jimp, People *ps)
4343
{
4444
if (!jimp_array_begin(jimp)) return false;
45-
while (jimp_array_has_items(jimp)) {
45+
while (jimp_array_item(jimp)) {
4646
Person p = {0};
4747
if (!parse_person(jimp, &p)) return false;
4848
da_append(ps, p);
@@ -68,12 +68,12 @@ typedef struct {
6868

6969
int main()
7070
{
71-
const char *file_path = "profile.json";
72-
// const char *path = "numbers.json";
73-
// const char *path = "profiles.json";
74-
// const char *path = "empty.json";
75-
// const char *path = "one.json";
76-
// const char *path = "database.json";
71+
// const char *file_path = "profile.json";
72+
// const char *file_path = "numbers.json";
73+
// const char *file_path = "profiles.json";
74+
// const char *file_path = "empty.json";
75+
// const char *file_path = "one.json";
76+
const char *file_path = "database.json";
7777
String_Builder sb = {0};
7878
if (!read_entire_file(file_path, &sb)) return 1;
7979
Jimp jimp = {
@@ -82,20 +82,15 @@ int main()
8282
static char string_store[1024];
8383
stb_c_lexer_init(&jimp.l, sb.items, sb.items + sb.count, string_store, sizeof(string_store));
8484

85-
Person p = {0};
86-
if (!parse_person(&jimp, &p)) return 1;
87-
print_person(&p);
88-
89-
/*
9085
People ps = {0};
9186
Numbers xs = {0};
9287
if (!jimp_object_begin(&jimp)) return 1;
9388
while (jimp_object_member(&jimp)) {
94-
if (strcmp(jimp.key, "profile") == 0) {
89+
if (strcmp(jimp.member, "profile") == 0) {
9590
if (!parse_people(&jimp, &ps)) return 1;
96-
} else if (strcmp(jimp.key, "number") == 0) {
91+
} else if (strcmp(jimp.member, "number") == 0) {
9792
if (!jimp_array_begin(&jimp)) return 1;
98-
while (jimp_array_has_items(&jimp)) {
93+
while (jimp_array_item(&jimp)) {
9994
long x = 0;
10095
jimp_number(&jimp, &x);
10196
da_append(&xs, x);
@@ -117,7 +112,6 @@ int main()
117112
printf("%ld ", *x);
118113
}
119114
printf("\n");
120-
*/
121115

122116
return 0;
123117
}

jimp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ typedef struct {
99
const char *member;
1010
} Jimp;
1111

12+
// TODO: how do null-s fit into this entire system?
1213
bool jimp_bool(Jimp *jimp, bool *boolean);
1314
bool jimp_number(Jimp *jimp, long *number);
15+
// TODO: support for floats
1416
bool jimp_string(Jimp *jimp, const char **string);
1517
bool jimp_object_begin(Jimp *jimp);
1618
bool jimp_object_member(Jimp *jimp);
1719
bool jimp_object_end(Jimp *jimp);
1820
void jimp_unknown_member(Jimp *jimp);
1921
bool jimp_array_begin(Jimp *jimp);
22+
bool jimp_array_item(Jimp *jimp);
2023
bool jimp_array_end(Jimp *jimp);
21-
bool jimp_array_has_items(Jimp *jimp);
2224

2325
// TODO: should be private
2426
bool jimp_expect_token(Jimp *jimp, long token);
@@ -80,7 +82,7 @@ bool jimp_array_end(Jimp *jimp)
8082
return jimp_get_and_expect_token(jimp, ']');
8183
}
8284

83-
bool jimp_array_has_items(Jimp *jimp)
85+
bool jimp_array_item(Jimp *jimp)
8486
{
8587
char *point = jimp->l.parse_point;
8688
if (!stb_c_lexer_get_token(&jimp->l)) return false;

0 commit comments

Comments
 (0)