Skip to content

Commit

Permalink
changes parson
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <[email protected]>
  • Loading branch information
NishantBansal2003 committed Nov 13, 2024
1 parent 785037a commit 81ec78b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/external/parson/parson.c
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,11 @@ JSON_Status json_object_set_string(JSON_Object *object, const char *name,
}
return status;
}
JSON_Status json_object_set_string_parson(JSON_Object *object, const char *name,
const char *string)
{
return json_object_set_string(object, name, string);
}

JSON_Status json_object_set_string_with_len(JSON_Object *object,
const char *name,
Expand Down
2 changes: 2 additions & 0 deletions lib/external/parson/parson.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ JSON_Status json_object_set_value(JSON_Object *object, const char *name,
JSON_Value *value);
JSON_Status json_object_set_string(JSON_Object *object, const char *name,
const char *string);
JSON_Status json_object_set_string_parson(JSON_Object *object, const char *name,
const char *string);
JSON_Status json_object_set_string_with_len(
JSON_Object *object, const char *name, const char *string,
size_t len); /* length shouldn't include last null character */
Expand Down
14 changes: 7 additions & 7 deletions lib/raster/json_color_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ static void set_color(int r, int g, int b, ColorFormat clr_frmt,
snprintf(color_string, sizeof(color_string), "rgb(%d, %d, %d)", r, g,
b);
color_string[sizeof(color_string) - 1] = '\0';
json_object_set_string(color_object, "rgb", color_string);
json_object_set_string_parson(color_object, "rgb", color_string);
break;

case HEX:
snprintf(color_string, sizeof(color_string), "#%02X%02X%02X", r, g, b);
color_string[sizeof(color_string) - 1] = '\0';
json_object_set_string(color_object, "hex", color_string);
json_object_set_string_parson(color_object, "hex", color_string);
break;

case HSV:
rgb_to_hsv(r, g, b, &h, &s, &v);
snprintf(color_string, sizeof(color_string), "hsv(%d, %d, %d)", (int)h,
(int)s, (int)v);
color_string[sizeof(color_string) - 1] = '\0';
json_object_set_string(color_object, "hsv", color_string);
json_object_set_string_parson(color_object, "hsv", color_string);
break;

case TRIPLET:
snprintf(color_string, sizeof(color_string), "%d:%d:%d", r, g, b);
color_string[sizeof(color_string) - 1] = '\0';
json_object_set_string(color_object, "triplet", color_string);
json_object_set_string_parson(color_object, "triplet", color_string);
break;
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ static void write_json_rule(DCELL *val, DCELL *min, DCELL *max, int r, int g,
snprintf(formatted_value, sizeof(formatted_value), "%g", *val);
formatted_value[sizeof(formatted_value) - 1] = '\0';

json_object_set_string(color_object, "value", formatted_value);
json_object_set_string_parson(color_object, "value", formatted_value);

set_color(r, g, b, clr_frmt, color_object);

Expand Down Expand Up @@ -236,7 +236,7 @@ void Rast_print_json_colors(struct Colors *colors, DCELL min, DCELL max,
_("Failed to initialize JSON object. Out of memory?"));
}
JSON_Object *nv_object = json_object(nv_value);
json_object_set_string(nv_object, "value", "nv");
json_object_set_string_parson(nv_object, "value", "nv");
set_color(r, g, b, clr_frmt, nv_object);
json_array_append_value(root_array, nv_value);

Expand All @@ -250,7 +250,7 @@ void Rast_print_json_colors(struct Colors *colors, DCELL min, DCELL max,
_("Failed to initialize JSON object. Out of memory?"));
}
JSON_Object *default_object = json_object(default_value);
json_object_set_string(default_object, "value", "default");
json_object_set_string_parson(default_object, "value", "default");
set_color(r, g, b, clr_frmt, default_object);
json_array_append_value(root_array, default_value);
}
Expand Down

0 comments on commit 81ec78b

Please sign in to comment.