From ff6b298b9dc3cb7a638deb23678f1b8d718f007e Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Sun, 17 Dec 2023 21:51:02 +0100 Subject: [PATCH] Fix horizontal line matching in 'remove' module --- src/remove.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/remove.c b/src/remove.c index a14fee6b..dde25fe7 100644 --- a/src/remove.c +++ b/src/remove.c @@ -531,7 +531,6 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx, shape_line_ctx_t *shapes_relevant = prepare_comp_shapes_horiz(hside, comp_type, shape_line_idx); debug_print_shapes_relevant(shapes_relevant); - uint32_t *cur_pos = NULL; bxstr_t *input_prepped1 = bxs_from_unicode(prepare_comp_input(input_line_idx, 0, comp_type, 0, NULL, NULL)); bxstr_t *input_prepped = bxs_rtrim(input_prepped1); bxs_free(input_prepped1); @@ -540,15 +539,23 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx, fprintf(stderr, " input_prepped = \"%s\"\n", out_input_prepped); BFREE(out_input_prepped); #endif - match_result_t *mrl = match_outer_shape(BLEF, input_prepped, shapes_relevant[0].text); - if (mrl != NULL) { - cur_pos = mrl->p + mrl->len; + + uint32_t *cur_pos = input_prepped->memory; + match_result_t *mrl = NULL; + if (!ctx->empty_side[BLEF]) { + mrl = match_outer_shape(BLEF, input_prepped, shapes_relevant[0].text); + if (mrl != NULL) { + cur_pos = mrl->p + mrl->len; + } } - uint32_t *end_pos = NULL; - match_result_t *mrr = match_outer_shape(BRIG, input_prepped, shapes_relevant[SHAPES_PER_SIDE - 1].text); - if (mrr != NULL) { - end_pos = mrr->p; + uint32_t *end_pos = bxs_last_char_ptr(input_prepped); + match_result_t *mrr = NULL; + if (!ctx->empty_side[BRIG]) { + mrr = match_outer_shape(BRIG, input_prepped, shapes_relevant[SHAPES_PER_SIDE - 1].text); + if (mrr != NULL) { + end_pos = mrr->p; + } } #ifdef DEBUG char *out_cur_pos = u32_strconv_to_output(cur_pos); @@ -559,9 +566,8 @@ static int match_horiz_line(remove_ctx_t *ctx, int hside, size_t input_line_idx, BFREE(out_end_pos); #endif - if (cur_pos && end_pos) { - result = hmm(shapes_relevant, cur_pos, 1, end_pos, mrl->shiftable ? 0 : 1, mrr->shiftable ? 0 : 1); - } + result = hmm(shapes_relevant, cur_pos, 1, end_pos, (mrl == NULL) || mrl->shiftable ? 0 : 1, + (mrr == NULL) || mrr->shiftable ? 0 : 1); BFREE(mrl); BFREE(mrr);