Browse Source

jimp: jimp_array_has_items -> jimp_array_item

rexim 1 month ago
parent
commit
485d191699
2 changed files with 14 additions and 18 deletions
  1. 10 16
      jimp.c
  2. 4 2
      jimp.h

+ 10 - 16
jimp.c

@@ -42,7 +42,7 @@ bool parse_person(Jimp *jimp, Person *p)
 bool parse_people(Jimp *jimp, People *ps)
 {
     if (!jimp_array_begin(jimp)) return false;
-    while (jimp_array_has_items(jimp)) {
+    while (jimp_array_item(jimp)) {
         Person p = {0};
         if (!parse_person(jimp, &p)) return false;
         da_append(ps, p);
@@ -68,12 +68,12 @@ typedef struct {
 
 int main()
 {
-    const char *file_path = "profile.json";
-    // const char *path = "numbers.json";
-    // const char *path = "profiles.json";
-    // const char *path = "empty.json";
-    // const char *path = "one.json";
-    // const char *path = "database.json";
+    // const char *file_path = "profile.json";
+    // const char *file_path = "numbers.json";
+    // const char *file_path = "profiles.json";
+    // const char *file_path = "empty.json";
+    // const char *file_path = "one.json";
+    const char *file_path = "database.json";
     String_Builder sb = {0};
     if (!read_entire_file(file_path, &sb)) return 1;
     Jimp jimp = {
@@ -82,20 +82,15 @@ int main()
     static char string_store[1024];
     stb_c_lexer_init(&jimp.l, sb.items, sb.items + sb.count, string_store, sizeof(string_store));
 
-    Person p = {0};
-    if (!parse_person(&jimp, &p)) return 1;
-    print_person(&p);
-
-    /*
     People ps = {0};
     Numbers xs = {0};
     if (!jimp_object_begin(&jimp)) return 1;
     while (jimp_object_member(&jimp)) {
-        if (strcmp(jimp.key, "profile") == 0) {
+        if (strcmp(jimp.member, "profile") == 0) {
             if (!parse_people(&jimp, &ps)) return 1;
-        } else if (strcmp(jimp.key, "number") == 0) {
+        } else if (strcmp(jimp.member, "number") == 0) {
             if (!jimp_array_begin(&jimp)) return 1;
-            while (jimp_array_has_items(&jimp)) {
+            while (jimp_array_item(&jimp)) {
                 long x = 0;
                 jimp_number(&jimp, &x);
                 da_append(&xs, x);
@@ -117,7 +112,6 @@ int main()
         printf("%ld ", *x);
     }
     printf("\n");
-    */
 
     return 0;
 }

+ 4 - 2
jimp.h

@@ -9,16 +9,18 @@ typedef struct {
     const char *member;
 } Jimp;
 
+// TODO: how do null-s fit into this entire system?
 bool jimp_bool(Jimp *jimp, bool *boolean);
 bool jimp_number(Jimp *jimp, long *number);
+// TODO: support for floats
 bool jimp_string(Jimp *jimp, const char **string);
 bool jimp_object_begin(Jimp *jimp);
 bool jimp_object_member(Jimp *jimp);
 bool jimp_object_end(Jimp *jimp);
 void jimp_unknown_member(Jimp *jimp);
 bool jimp_array_begin(Jimp *jimp);
+bool jimp_array_item(Jimp *jimp);
 bool jimp_array_end(Jimp *jimp);
-bool jimp_array_has_items(Jimp *jimp);
 
 // TODO: should be private
 bool jimp_expect_token(Jimp *jimp, long token);
@@ -80,7 +82,7 @@ bool jimp_array_end(Jimp *jimp)
     return jimp_get_and_expect_token(jimp, ']');
 }
 
-bool jimp_array_has_items(Jimp *jimp)
+bool jimp_array_item(Jimp *jimp)
 {
     char *point = jimp->l.parse_point;
     if (!stb_c_lexer_get_token(&jimp->l)) return false;