Fix pretty printing

This commit is contained in:
rexy712
2020-02-27 10:17:33 -08:00
parent ffac4718e8
commit 99cc9a5154

View File

@@ -173,9 +173,17 @@ static RJP_index irjp_write_value_pretty(char* dest, const RJP_value* val, int d
static RJP_index irjp_dump_array_pretty(const RJP_value* arr, char* dest, int depth){
RJP_array_iterator it;
rjp_init_array_iterator(&it, arr);
RJP_index pos = 2;
sprintf(dest, "[\n");
for(RJP_value* current = rjp_array_iterator_current(&it);current;current = rjp_array_iterator_next(&it)){
RJP_index pos = 0;
RJP_value* current = rjp_array_iterator_current(&it);
if(!current){
pos += sprintf(dest, "[]");
rjp_delete_array_iterator(&it);
return pos;
}
pos += sprintf(dest+pos, "[\n");
for(;current;current = rjp_array_iterator_next(&it)){
for(int i = 0;i < (depth+1);++i)
pos += sprintf(dest+pos, "\t");
pos += irjp_write_value_pretty(dest+pos, current, depth+1);
@@ -187,15 +195,23 @@ static RJP_index irjp_dump_array_pretty(const RJP_value* arr, char* dest, int de
for(int i = 0;i < depth;++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "]");
rjp_delete_array_iterator(&it);
return pos;
}
static RJP_index irjp_dump_object_pretty(const RJP_value* root, char* dest, int depth){
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
RJP_index pos = 2;
sprintf(dest, "{\n");
RJP_index pos = 0;
RJP_value* current = rjp_object_iterator_current(&it);
if(!current){
pos += sprintf(dest+pos, "{}");
rjp_delete_object_iterator(&it);
return pos;
}
pos += sprintf(dest, "{\n");
for(RJP_value* current = rjp_object_iterator_current(&it);current;current = rjp_object_iterator_next(&it)){
for(;current;current = rjp_object_iterator_next(&it)){
for(int i = 0;i < (depth+1);++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "\"%s\": ", rjp_member_key(current)->value);
@@ -208,6 +224,7 @@ static RJP_index irjp_dump_object_pretty(const RJP_value* root, char* dest, int
for(int i = 0;i < depth;++i)
pos += sprintf(dest+pos, "\t");
pos += sprintf(dest+pos, "}");
rjp_delete_object_iterator(&it);
return pos;
}
@@ -256,6 +273,7 @@ RJP_index rjp_dump_array(const RJP_value* arr, char* dest){
break;
}
pos += sprintf(dest+pos, "]");
rjp_delete_array_iterator(&it);
return pos;
}