Browse Source

Using enum for json types for better debugging

Sergey Lyubka 11 years ago
parent
commit
25b6295ae9
2 changed files with 16 additions and 14 deletions
  1. 1 1
      frozen.c
  2. 15 13
      frozen.h

+ 1 - 1
frozen.c

@@ -86,7 +86,7 @@ static int get_escape_len(const char *s, int len) {
   }
 }
 
-static int capture_ptr(struct frozen *f, const char *ptr, int type) {
+static int capture_ptr(struct frozen *f, const char *ptr, enum json_type type) {
   if (f->tokens == 0 || f->max_tokens == 0) return 0;
   if (f->num_tokens >= f->max_tokens) return JSON_TOKEN_ARRAY_TOO_SMALL;
   f->tokens[f->num_tokens].ptr = ptr;

+ 15 - 13
frozen.h

@@ -22,20 +22,22 @@
 extern "C" {
 #endif // __cplusplus
 
+enum json_type {
+  JSON_TYPE_EOF     = 0,      // End of parsed tokens marker
+  JSON_TYPE_STRING  = 1,
+  JSON_TYPE_NUMBER  = 2,
+  JSON_TYPE_OBJECT  = 3,
+  JSON_TYPE_TRUE    = 4,
+  JSON_TYPE_FALSE   = 5,
+  JSON_TYPE_NULL    = 6,
+  JSON_TYPE_ARRAY   = 7
+};
+
 struct json_token {
-  const char *ptr;    // Points to the beginning of the token
-  int len;            // Token length
-  int num_desc;       // For arrays and object, total number of descendants
-  int type;           // Type of the token, possible values below
-
-#define JSON_TYPE_EOF     0   // End of parsed tokens marker
-#define JSON_TYPE_STRING  1
-#define JSON_TYPE_NUMBER  2
-#define JSON_TYPE_OBJECT  3
-#define JSON_TYPE_TRUE    4
-#define JSON_TYPE_FALSE   5
-#define JSON_TYPE_NULL    6
-#define JSON_TYPE_ARRAY   7
+  const char *ptr;      // Points to the beginning of the token
+  int len;              // Token length
+  int num_desc;         // For arrays and object, total number of descendants
+  enum json_type type;  // Type of the token, possible values below
 };
 
 // Error codes