Skip to content

Commit 39225b0

Browse files
committed
Fix the double quotes issue
1 parent 2183d7a commit 39225b0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/cjlib.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ int cjlib_json_read(struct cjlib_json *restrict dst)
761761
static inline char *wrap_complete_entry(const char *entry_state, char opening_symbol,
762762
char closing_symbol)
763763
{
764-
size_t additional_size = 3; // The size of {} or [].
764+
size_t additional_size = 2; // The size of {} or [].
765765
size_t wrapped_size = strlen(entry_state) + additional_size;
766766

767767
char *wrapped_state = (char *) malloc(wrapped_size + 1);
768768
if (NULL == wrapped_state) return NULL;
769769

770-
(void) sprintf(wrapped_state, "%c%s%c,", opening_symbol, entry_state, closing_symbol);
770+
(void) sprintf(wrapped_state, "%c%s%c", opening_symbol, entry_state, closing_symbol);
771771

772772
return wrapped_state;
773773
}
@@ -928,8 +928,7 @@ static inline int convert_list_to_queue(struct cjlib_queue *restrict dst, const
928928
const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
929929
{
930930
/**
931-
* TODO - 1. Why only a few kies are wrapped with double quotes, while the majority isn't
932-
* 2. Why some fields don't appear in the stringtifying version? (look type field in the JSON).
931+
* TODO - 1. Why some fields don't appear in the stringtifying version? (look type field in the JSON).
933932
*/
934933
struct incomplete_property_str curr_incomp; // The currently expanding data.
935934
struct cjlib_stack incomplete_st; // The stack of incomplete data.
@@ -940,12 +939,15 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
940939
char *tmp_state = NULL; // Used to control the memory (see default case in the switch below)
941940
char *tmp_key = NULL; // Used to temporary store the key of the complete JSON object/array.
942941
char *value_str = NULL; // Used to temporary store the strintify data (see default case in the switch below)
943-
942+
944943
char opening_symbol_obj = CURLY_BRACKETS_OPEN;
945944
char opening_symbol_arr = SQUARE_BRACKETS_OPEN;
946945
char closing_symbol_obj = CURLY_BRACKETS_CLOSE;
947946
char closing_symbol_arr = SQUARE_BRACKETS_CLOSE;
948947

948+
char opening_symbol_str = DOUBLE_QUOTES;
949+
char closing_symbol_str = DOUBLE_QUOTES;
950+
949951
char opening_symbol;
950952
char closing_symbol;
951953

@@ -1006,7 +1008,8 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
10061008
case CJLIB_ARRAY:
10071009
cjlib_stack_push(&curr_incomp, sizeof(struct incomplete_property_str), &incomplete_st);
10081010

1009-
if (-1 == switch_from_incomplete_arr_str_data(&curr_incomp, CJLIB_ARRAY, examine_entry_data, CJLIB_DICT_NODE_KEY(examine_entry))) return NULL;
1011+
if (-1 == switch_from_incomplete_arr_str_data(&curr_incomp, CJLIB_ARRAY, examine_entry_data,
1012+
CJLIB_DICT_NODE_KEY(examine_entry))) return NULL;
10101013

10111014
convert_list_to_queue(curr_incomp.i_pending_data_q, curr_incomp.i_data.array);
10121015
break;
@@ -1015,8 +1018,12 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *src)
10151018

10161019
if (CJLIB_OBJECT == curr_incomp.i_type) {
10171020
value_str = simple_key_value_paired_stringtify(CJLIB_DICT_NODE_DATA(examine_entry));
1021+
tmp_key = wrap_complete_entry(CJLIB_DICT_NODE_KEY(examine_entry),opening_symbol_str, closing_symbol_str);
10181022
curr_incomp.i_state = incomplete_property_str_expand_state(curr_incomp.i_state, value_str,
1019-
CJLIB_DICT_NODE_KEY(examine_entry));
1023+
tmp_key);
1024+
1025+
free(tmp_key);
1026+
tmp_key = NULL;
10201027
} else {
10211028
value_str = simple_key_value_paired_stringtify(examine_entry_data);
10221029
curr_incomp.i_state = incomplete_property_str_expand_state(curr_incomp.i_state, value_str, NULL);

0 commit comments

Comments
 (0)