]> git.kaiwu.me - klib.git/commitdiff
removed *error from kson_parse()
authorHeng Li <lh3@me.com>
Sun, 30 Nov 2014 05:40:26 +0000 (00:40 -0500)
committerHeng Li <lh3@me.com>
Sun, 30 Nov 2014 05:40:26 +0000 (00:40 -0500)
Few would be interested in this error code

kson.c
kson.h

diff --git a/kson.c b/kson.c
index c6c71445f2032f9fb0af65b97629dc78c88e6318..d86b8a27107bbb927e8b2a70d3056927e27c4961 100644 (file)
--- a/kson.c
+++ b/kson.c
@@ -118,12 +118,13 @@ void kson_destroy(kson_t *kson)
        free(kson->nodes); free(kson);
 }
 
-kson_t *kson_parse(const char *json, int *error)
+kson_t *kson_parse(const char *json)
 {
        kson_t *kson;
+       int error;
        kson = (kson_t*)calloc(1, sizeof(kson_t));
-       kson->nodes = kson_parse_core(json, &kson->n_nodes, error, 0);
-       if (*error) {
+       kson->nodes = kson_parse_core(json, &kson->n_nodes, &error, 0);
+       if (error) {
                kson_destroy(kson);
                return 0;
        }
@@ -200,7 +201,6 @@ void kson_format(const kson_node_t *root)
 int main(int argc, char *argv[])
 {
        kson_t *kson = 0;
-       int error;
        if (argc > 1) {
                FILE *fp;
                int len = 0, max = 0, tmp, i;
@@ -218,7 +218,7 @@ int main(int argc, char *argv[])
                        }
                        fclose(fp);
                        // parse
-                       kson = kson_parse(json, &error);
+                       kson = kson_parse(json);
                        free(json);
                        if (kson) {
                                kson_format(kson->nodes);
@@ -237,17 +237,17 @@ int main(int argc, char *argv[])
                                                else printf("Value: %s\n", p->v.str);
                                        } else printf("Failed to find the slot\n");
                                }
-                       } else printf("Error code: %d\n", error);
+                       } else printf("Failed to parse\n");
                }
        } else {
-               kson = kson_parse("{'a' : 1,'b':[0,'isn\\'t',true],'d':[{\n\n\n}]}", &error);
-               if (error == 0) {
+               kson = kson_parse("{'a' : 1,'b':[0,'isn\\'t',true],'d':[{\n\n\n}]}");
+               if (kson) {
                        const kson_node_t *p = kson_query(kson->nodes, 2, "b", 1);
                        if (p) printf("*** %s\n", p->v.str);
                        else printf("!!! not found\n");
                        kson_format(kson->nodes);
                } else {
-                       printf("Error code: %d\n", error);
+                       printf("Failed to parse\n");
                }
        }
        kson_destroy(kson);
diff --git a/kson.h b/kson.h
index 577e80aabf5c8325ae1d244ba9ea35f8bbf48a1a..d81988707fcb98f0c3f9ce5508c6213ddfe01005 100644 (file)
--- a/kson.h
+++ b/kson.h
@@ -32,21 +32,9 @@ typedef struct {
 extern "C" {
 #endif
 
-       /**
-        * Parse a JSON string
-        *
-        * @param json    JSON string
-        * @param error   error code
-        *
-        * @return a pointer to kson_t if *error==0; or NULL otherwise
-        */
-       kson_t *kson_parse(const char *json, int *error);
-
-       /** Destroy a kson_t object */
+       kson_t *kson_parse(const char *json);
        void kson_destroy(kson_t *kson);
-
        const kson_node_t *kson_query(const kson_node_t *root, int max_depth, ...);
-
        void kson_format(const kson_node_t *root);
 
 #ifdef __cplusplus