[PATCH 5/6] jshn.c: add_json_element():

Sergey Ponomarev stokito at gmail.com
Tue Feb 23 08:36:57 EST 2021


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

Signed-off-by: Sergey Ponomarev <stokito at gmail.com>
---
 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




More information about the openwrt-devel mailing list