From: Kevin Day Date: Thu, 3 Oct 2024 05:12:22 +0000 (-0500) Subject: Bugfix: Empty Objects are preserving leading white space when in original mode. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=2e555313f3c6e29022ace22ad94b0c535c49f11a;p=fll Bugfix: Empty Objects are preserving leading white space when in original mode. This (unfortunately) adds more logic to processing the case when `--original` is used and the Object is empty. This makes me wonder if I have to implement the opener range. I was not happy about adding the `close` for memory and space reasons. Adding this would introduce more inefficiencies. I may end up having to add support for processing different types of structures if I want to support the simple Object and Content without the `open` and `close` positions as well as with those positions. The focus in this commit is only on fixing the printing and does not introduce any of the behavior that I described here. --- diff --git a/level_3/fss_read/c/main/print/data.c b/level_3/fss_read/c/main/print/data.c index 16b042b..e529707 100644 --- a/level_3/fss_read/c/main/print/data.c +++ b/level_3/fss_read/c/main/print/data.c @@ -254,17 +254,19 @@ extern "C" { if (at >= main->setting.objects.used) return F_output_not; // The current FSS standards that have a only spaces to the left of a close so simply print all to the left. - if ((main->setting.feature & fss_read_feature_flag_object_align_d) && (main->setting.flag & fss_read_main_flag_content_d) && (!(main->setting.flag & fss_read_main_flag_original_d) || (main->setting.flag & fss_read_main_flag_trim_d))) { - if (at < main->setting.closes.used && main->setting.closes.array[at].start <= main->setting.closes.array[at].stop) { - f_range_t before = f_range_t_initialize; - - if (main->setting.closes.array[at].start) { - before.start = main->setting.closes.array[at].start; - before.stop = main->setting.closes.array[at].stop ? main->setting.closes.array[at].stop - 1 : 0; - } + if ((main->setting.feature & fss_read_feature_flag_object_align_d) && (main->setting.flag & fss_read_main_flag_content_d)) { + if (!(main->setting.flag & fss_read_main_flag_original_d) || (main->setting.flag & fss_read_main_flag_trim_d)) { + if (at < main->setting.closes.used && main->setting.closes.array[at].start <= main->setting.closes.array[at].stop) { + f_range_t before = f_range_t_initialize; + + if (main->setting.closes.array[at].start) { + before.start = main->setting.closes.array[at].start; + before.stop = main->setting.closes.array[at].stop ? main->setting.closes.array[at].stop - 1 : 0; + } - if (before.start <= before.stop) { - fll_print_except_dynamic_partial(main->setting.buffer, before, delimits, main->program.output.to); + if (before.start <= before.stop) { + fll_print_except_dynamic_partial(main->setting.buffer, before, delimits, main->program.output.to); + } } } } @@ -315,6 +317,29 @@ extern "C" { } } } + else if (main->setting.flag & fss_read_main_flag_content_d) { + + // An empty Object might still have white space. + if (main->setting.contents.array[at].used && main->setting.contents.array[at].array[0].start <= main->setting.contents.array[at].array[0].stop) { + + // Skip past the new line and the object opener. + if (main->setting.feature & fss_read_feature_flag_object_as_line_d) { + if (main->setting.contents.array[at].array[0].start && main->setting.contents.array[at].array[0].start - 1) { + before.stop = main->setting.contents.array[at].array[0].start - 2; + + if (main->setting.open_object.used) { + --before.stop; + } + + before.start = before.stop; + + while (before.start && main->setting.buffer.string[before.start] != f_string_eol_s.string[0]) --before.start; + + if (main->setting.buffer.string[before.start] == f_string_eol_s.string[0]) ++before.start; + } + } + } + } if (before.start <= before.stop) { fll_print_except_dynamic_partial(main->setting.buffer, before, delimits, main->program.output.to); diff --git a/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-original.expect b/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-original.expect index 4276d1b..46a6b63 100644 --- a/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-original.expect @@ -11,7 +11,7 @@ \# Valid Object : with content. -: + : Has no Object name (only white space) and is oddly spaced. мир : diff --git a/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-select-0-original.expect b/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-select-0-original.expect index 4276d1b..46a6b63 100644 --- a/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-select-0-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0002/expect/test-0003-object_space-object_and_content-select-0-original.expect @@ -11,7 +11,7 @@ \# Valid Object : with content. -: + : Has no Object name (only white space) and is oddly spaced. мир : diff --git a/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-original.expect b/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-original.expect index c4dc9a0..e89385d 100644 --- a/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-original.expect @@ -12,7 +12,7 @@ \# Valid Object { with content. } -{ + { Has no Object name (only white space) and is oddly spaced. } мир { diff --git a/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-select-0-original.expect b/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-select-0-original.expect index c4dc9a0..e89385d 100644 --- a/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-select-0-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0003/expect/test-0003-object_space-object_and_content-select-0-original.expect @@ -12,7 +12,7 @@ \# Valid Object { with content. } -{ + { Has no Object name (only white space) and is oddly spaced. } мир { diff --git a/level_3/fss_read/tests/runtime/fss_0008/expect/test-0003-object_space-object_and_content-select-0-original.expect b/level_3/fss_read/tests/runtime/fss_0008/expect/test-0003-object_space-object_and_content-select-0-original.expect index 27dbce4..2acd827 100644 --- a/level_3/fss_read/tests/runtime/fss_0008/expect/test-0003-object_space-object_and_content-select-0-original.expect +++ b/level_3/fss_read/tests/runtime/fss_0008/expect/test-0003-object_space-object_and_content-select-0-original.expect @@ -18,7 +18,7 @@ } and outside. } -{ + { Has no Object name (only white space) and is oddly spaced. } мир {