Extract variable to store json_object_get_type()
Replace switch with json_type_to_name()

Signed-off-by: Sergey Ponomarev <[email protected]>
---
 jshn.c | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

diff --git a/jshn.c b/jshn.c
index 43a82e0..6490fbc 100644
--- a/jshn.c
+++ b/jshn.c
@@ -106,38 +106,14 @@ static void write_key_string(const char *key)
 
 static int add_json_element(const char *key, json_object *obj)
 {
-       char *type;
+       enum json_type obj_json_type;
 
-       switch (json_object_get_type(obj)) {
-       case json_type_object:
-               type = "object";
-               break;
-       case json_type_array:
-               type = "array";
-               break;
-       case json_type_string:
-               type = "string";
-               break;
-       case json_type_boolean:
-               type = "boolean";
-               break;
-       case json_type_int:
-               type = "int";
-               break;
-       case json_type_double:
-               type = "double";
-               break;
-       case json_type_null:
-               type = "null";
-               break;
-       default:
-               return -1;
-       }
+       obj_json_type = json_object_get_type(obj);
 
-       fprintf(stdout, "json_add_%s '", type);
+       fprintf(stdout, "json_add_%s '", json_type_to_name(obj_json_type));
        write_key_string(key);
 
-       switch (json_object_get_type(obj)) {
+       switch (obj_json_type) {
        case json_type_object:
                fprintf(stdout, "';\n");
                add_json_object(obj);
-- 
2.27.0


_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to