From 670f073a340f2b6ea2a759f3edd37822c7972663 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 31 Aug 2024 21:34:04 -0500 Subject: [PATCH] Bugfix: FSS Embedded List Read is not applying delimits when printing in line mode. Make sure delimits are properly applied. The `--line` mode is printing the line character by character. Add a loop to check if the given character is to be printed or not based on the delimits array. --- level_3/fss_embedded_list_read/c/private-read.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/level_3/fss_embedded_list_read/c/private-read.c b/level_3/fss_embedded_list_read/c/private-read.c index bdd5a2c..c6300a5 100644 --- a/level_3/fss_embedded_list_read/c/private-read.c +++ b/level_3/fss_embedded_list_read/c/private-read.c @@ -557,6 +557,7 @@ extern "C" { if (data->main->parameters.array[fss_embedded_list_read_parameter_line_e].result == f_console_result_additional_e) { f_array_length_t line_current = 0; + f_array_length_t delimit = 0; uint8_t newline_missing = F_true; flockfile(data->main->output.to.stream); @@ -610,6 +611,16 @@ extern "C" { break; } + if (delimit < contents_delimits->used) { + while (contents_delimits->array[delimit] < j) ++delimit; + + if (delimit < contents_delimits->used && j == contents_delimits->array[delimit]) { + ++delimit; + + continue; + } + } + f_print_character(data->buffer.string[j], data->main->output.to.stream); } // for } @@ -802,8 +813,7 @@ extern "C" { void fss_embedded_list_read_process_delimits(fss_embedded_list_read_data_t * const data, f_fss_delimits_t *objects_delimits, f_fss_delimits_t *contents_delimits) { if (!data->nest.used) return; - - if ((!objects_delimits->used && !contents_delimits->used) || data->delimit_mode == fss_embedded_list_read_delimit_mode_all_e) return; + if (!objects_delimits->used && !contents_delimits->used || data->delimit_mode == fss_embedded_list_read_delimit_mode_all_e) return; if (data->delimit_mode == fss_embedded_list_read_delimit_mode_depth_lesser_e && data->nest.used < data->delimit_depth) return; if (data->delimit_mode == fss_embedded_list_read_delimit_mode_depth_greater_e && data->delimit_depth == 0) return; @@ -843,7 +853,7 @@ extern "C" { fss_embedded_list_read_process_delimits_objects(data, data->delimit_depth, original_contents_delimits, original_contents_used, contents_delimits); } else { - fss_embedded_list_read_process_delimits_objects(data, data->delimit_depth, original_objects_delimits, original_objects_used, objects_delimits); + fss_embedded_list_read_process_delimits_objects(data, 0, original_objects_delimits, original_objects_used, objects_delimits); } fss_embedded_list_read_process_delimits_contents(data, data->delimit_depth, original_contents_delimits, original_contents_used, contents_delimits); @@ -862,7 +872,14 @@ extern "C" { } // for } else if (data->delimit_mode == fss_embedded_list_read_delimit_mode_depth_greater_e) { - for (f_array_length_t i = data->delimit_depth; i < data->nest.used; ++i) { + + // Only depth 0 objects are stored in objects_delimits. + if (!data->delimit_depth) { + fss_embedded_list_read_process_delimits_objects(data, 0, original_objects_delimits, original_objects_used, objects_delimits); + fss_embedded_list_read_process_delimits_contents(data, 0, original_contents_delimits, original_contents_used, contents_delimits); + } + + for (f_array_length_t i = data->delimit_depth + 1; i < data->nest.used; ++i) { fss_embedded_list_read_process_delimits_objects(data, i, original_contents_delimits, original_contents_used, contents_delimits); fss_embedded_list_read_process_delimits_contents(data, i, original_contents_delimits, original_contents_used, contents_delimits); -- 1.8.3.1