4444
4545#define ROOT_PROPERTY_NAME ("") // A name used to represent the beginning of the JSON. !NO OTHER PROPERTY MUST OBTAIN THIS NAME EXCEPT ROOT~
4646
47+ #define OBJECT_STR_STATE_INIT_LEN 1000 // The initial length of the state string (see strintify function)
4748
4849
4950// Indicated whether the currently incomplete attribute is an object.
@@ -65,6 +66,20 @@ struct incomplete_property
6566 } i_data ;
6667};
6768
69+ /**
70+ * Used to describe an incomplete object or array in the process
71+ * of stringtifing the object/array stored in the RAM
72+ */
73+ struct incomplete_property_str
74+ {
75+ char * i_state ; // How much of the object/array is complete.
76+ union
77+ {
78+ cjlib_json_object * object ;
79+ cjlib_json_array * array ;
80+ } i_data ;
81+ };
82+
6883static void incomplete_property_init (struct incomplete_property * src )
6984{
7085 (void ) memset (src , 0x0 , sizeof (struct incomplete_property ));
@@ -561,11 +576,20 @@ int cjlib_json_read(struct cjlib_json *restrict dst)
561576 incomplete_property_init (& tmp_data );
562577 incomplete_property_init (& curr_incomplete_data );
563578
564- curr_incomplete_data .i_name = strdup (ROOT_PROPERTY_NAME ); // cause is the root object.
579+ curr_incomplete_data = (struct incomplete_property ) {
580+ .i_name = strdup (ROOT_PROPERTY_NAME ), // cause is the root object
581+ .i_type = CJLIB_OBJECT ,
582+ .i_data .object = dst -> c_dict
583+ };
584+
585+ // curr_incomplete_data.i_name = strdup(ROOT_PROPERTY_NAME);
586+
587+ // curr_incomplete_data.i_data.object = dst->c_dict;
588+ // curr_incomplete_data.i_type = CJLIB_OBJECT;
589+
590+
565591 if (NULL == curr_incomplete_data .i_name ) goto read_err ;
566592
567- curr_incomplete_data .i_data .object = dst -> c_dict ;
568- curr_incomplete_data .i_type = CJLIB_OBJECT ;
569593
570594 // Push the first incomplete object into the stack.
571595 if (-1 == cjlib_stack_push ((void * ) & curr_incomplete_data , sizeof (struct incomplete_property ),
@@ -696,14 +720,25 @@ int cjlib_json_read(struct cjlib_json *restrict dst)
696720 return -1 ;
697721}
698722
699- const char * cjlib_json_object_stringtify (const cjlib_json_object * restrict src )
723+ const char * cjlib_json_object_stringtify (const cjlib_json_object * src )
700724{
701- struct cjlib_queue object_data_q ;
725+ struct cjlib_queue object_data_q ;
726+ struct cjlib_stack incomplete_data_stc ;
727+ struct incomplete_property_str curr_incomp_p ;
728+
702729 cjlib_queue_init (& object_data_q );
730+ cjlib_stack_init (& incomplete_data_stc );
703731
704- if (-1 == cjlib_dict_postorder (& object_data_q , (cjlib_json_object * ) src )) return NULL ;
732+ curr_incomp_p = (struct incomplete_property_str ) {
733+ .i_state = (char * ) malloc (OBJECT_STR_STATE_INIT_LEN ),
734+ .i_data .object =
735+ };
736+
737+
738+ do {
739+
740+ } while (!cjlib_queue_is_empty (& object_data_q ))
705741
706- // TODO - implement the algorithm.
707742
708743 return NULL ;
709744}
0 commit comments