@@ -3241,6 +3241,27 @@ static int sg_parse_fields(const char *args, const char *out[], int max_out, yyj
32413241 return n ;
32423242}
32433243
3244+ /* Append a property as one compact-output cell. Compound values stay one
3245+ * column by using their compact JSON representation; the cell emitter quotes
3246+ * and escapes that representation as needed. */
3247+ static void sg_toon_property_cell (cbm_sb_t * sb , yyjson_val * v ) {
3248+ if (v && yyjson_is_str (v )) {
3249+ cbm_tree_cell_str (sb , yyjson_get_str (v ), false);
3250+ } else if (v && yyjson_is_bool (v )) {
3251+ cbm_tree_cell_bool (sb , yyjson_get_bool (v ), false);
3252+ } else if (v && yyjson_is_int (v )) {
3253+ cbm_tree_cell_int (sb , yyjson_get_int (v ), false);
3254+ } else if (v && yyjson_is_real (v )) {
3255+ cbm_tree_cell_real (sb , yyjson_get_real (v ), false);
3256+ } else if (v && !yyjson_is_null (v )) {
3257+ char * json = yyjson_val_write (v , 0 , NULL );
3258+ cbm_tree_cell_str (sb , json ? json : "" , false);
3259+ free (json );
3260+ } else {
3261+ cbm_tree_cell_str (sb , "" , false);
3262+ }
3263+ }
3264+
32443265/* Append one row's extra-field cells, pulled from the node's properties. */
32453266static void sg_toon_extra_cells (cbm_sb_t * sb , const char * props_json , const char * const * fields ,
32463267 int nfields ) {
@@ -3249,17 +3270,7 @@ static void sg_toon_extra_cells(cbm_sb_t *sb, const char *props_json, const char
32493270 yyjson_val * pr = pd ? yyjson_doc_get_root (pd ) : NULL ;
32503271 for (int f = 0 ; f < nfields ; f ++ ) {
32513272 yyjson_val * v = (pr && yyjson_is_obj (pr )) ? yyjson_obj_get (pr , fields [f ]) : NULL ;
3252- if (v && yyjson_is_str (v )) {
3253- cbm_tree_cell_str (sb , yyjson_get_str (v ), false);
3254- } else if (v && yyjson_is_bool (v )) {
3255- cbm_tree_cell_bool (sb , yyjson_get_bool (v ), false);
3256- } else if (v && yyjson_is_int (v )) {
3257- cbm_tree_cell_int (sb , yyjson_get_int (v ), false);
3258- } else if (v && yyjson_is_real (v )) {
3259- cbm_tree_cell_real (sb , yyjson_get_real (v ), false);
3260- } else {
3261- cbm_tree_cell_str (sb , "" , false);
3262- }
3273+ sg_toon_property_cell (sb , v );
32633274 }
32643275 if (pd ) {
32653276 yyjson_doc_free (pd );
@@ -3391,17 +3402,7 @@ static void emit_search_results_tree(cbm_sb_t *sb, cbm_search_output_t *out, int
33913402 yyjson_val * pr = pd ? yyjson_doc_get_root (pd ) : NULL ;
33923403 for (int f = 0 ; f < nfields ; f ++ ) {
33933404 yyjson_val * v = (pr && yyjson_is_obj (pr )) ? yyjson_obj_get (pr , fields [f ]) : NULL ;
3394- if (v && yyjson_is_str (v )) {
3395- cbm_tree_cell_str (sb , yyjson_get_str (v ), false);
3396- } else if (v && yyjson_is_int (v )) {
3397- cbm_tree_cell_int (sb , yyjson_get_int (v ), false);
3398- } else if (v && yyjson_is_real (v )) {
3399- cbm_tree_cell_real (sb , yyjson_get_real (v ), false);
3400- } else if (v && yyjson_is_bool (v )) {
3401- cbm_tree_cell_bool (sb , yyjson_get_bool (v ), false);
3402- } else {
3403- cbm_tree_cell_str (sb , "" , false); /* emits "-" */
3404- }
3405+ sg_toon_property_cell (sb , v );
34053406 }
34063407 if (pd ) {
34073408 yyjson_doc_free (pd );
@@ -3483,14 +3484,10 @@ static void emit_search_results_tree_json(yyjson_mut_doc *doc, yyjson_mut_val *r
34833484 yyjson_val * pr = pd ? yyjson_doc_get_root (pd ) : NULL ;
34843485 for (int f = 0 ; f < nfields ; f ++ ) {
34853486 yyjson_val * v = (pr && yyjson_is_obj (pr )) ? yyjson_obj_get (pr , fields [f ]) : NULL ;
3486- if (v && yyjson_is_str (v )) {
3487- yyjson_mut_arr_add_strcpy (doc , row , yyjson_get_str (v ));
3488- } else if (v && yyjson_is_int (v )) {
3489- yyjson_mut_arr_add_int (doc , row , yyjson_get_int (v ));
3490- } else if (v && yyjson_is_real (v )) {
3491- yyjson_mut_arr_add_real (doc , row , yyjson_get_real (v ));
3492- } else if (v && yyjson_is_bool (v )) {
3493- yyjson_mut_arr_add_bool (doc , row , yyjson_get_bool (v ));
3487+ yyjson_mut_val * copy =
3488+ (v && !yyjson_is_null (v )) ? yyjson_val_mut_copy (doc , v ) : NULL ;
3489+ if (copy ) {
3490+ yyjson_mut_arr_add_val (row , copy );
34943491 } else {
34953492 yyjson_mut_arr_add_null (doc , row );
34963493 }
0 commit comments