Browse Source

jimp: key -> member

rexim 1 month ago
parent
commit
531125c1d3
2 changed files with 8 additions and 8 deletions
  1. 4 4
      jimp.c
  2. 4 4
      jimp.h

+ 4 - 4
jimp.c

@@ -23,13 +23,13 @@ bool parse_person(Jimp *jimp, Person *p)
 {
     if (!jimp_object_begin(jimp)) return false;
     while (jimp_object_member(jimp)) {
-        if (strcmp(jimp->key, "name") == 0) {
+        if (strcmp(jimp->member, "name") == 0) {
             if (!jimp_string(jimp, &p->name))       return false;
-        } else if (strcmp(jimp->key, "age") == 0) {
+        } else if (strcmp(jimp->member, "age") == 0) {
             if (!jimp_number(jimp, &p->age))        return false;
-        } else if (strcmp(jimp->key, "location") == 0) {
+        } else if (strcmp(jimp->member, "location") == 0) {
             if (!jimp_string(jimp, &p->location))   return false;
-        } else if (strcmp(jimp->key, "body_count") == 0) {
+        } else if (strcmp(jimp->member, "body_count") == 0) {
             if (!jimp_number(jimp, &p->body_count)) return false;
         } else {
             jimp_unknown_member(jimp);

+ 4 - 4
jimp.h

@@ -6,7 +6,7 @@
 typedef struct {
     stb_lexer l;
     const char *path;
-    const char *key;
+    const char *member;
 } Jimp;
 
 bool jimp_bool(Jimp *jimp, bool *boolean);
@@ -97,7 +97,7 @@ void jimp_unknown_member(Jimp *jimp)
 {
     stb_lex_location loc = {0};
     stb_c_lexer_get_location(&jimp->l, jimp->l.where_firstchar, &loc);
-    fprintf(stderr, "%s:%d:%d: ERROR: Unexpected member `%s`\n", jimp->path, loc.line_number, loc.line_offset + 1, jimp->key);
+    fprintf(stderr, "%s:%d:%d: ERROR: Unexpected member `%s`\n", jimp->path, loc.line_number, loc.line_offset + 1, jimp->member);
 }
 
 bool jimp_object_begin(Jimp *jimp)
@@ -111,7 +111,7 @@ bool jimp_object_member(Jimp *jimp)
     if (!stb_c_lexer_get_token(&jimp->l)) return false;
     if (jimp->l.token == ',') {
         if (!jimp_get_and_expect_token(jimp, CLEX_dqstring)) return false;
-        jimp->key = strdup(jimp->l.string); // TODO: memory leak
+        jimp->member = strdup(jimp->l.string); // TODO: memory leak
         if (!jimp_get_and_expect_token(jimp, ':')) return false;
         return true;
     }
@@ -120,7 +120,7 @@ bool jimp_object_member(Jimp *jimp)
         return false;
     }
     if (!jimp_expect_token(jimp, CLEX_dqstring)) return false;
-    jimp->key = strdup(jimp->l.string); // TODO: memory leak
+    jimp->member = strdup(jimp->l.string); // TODO: memory leak
     if (!jimp_get_and_expect_token(jimp, ':')) return false;
     return true;
 }