From e0a5c54b624dc4e6638560a306a7056944b7f24a Mon Sep 17 00:00:00 2001 From: anon Date: Sat, 23 Sep 2023 15:55:36 +0200 Subject: [PATCH] >most tests pass >hl completelly breaks --- source/jeger.c | 22 +++++++++++++--------- source/jeger.h | 5 ++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/jeger.c b/source/jeger.c index f7c4f3d..96266fe 100644 --- a/source/jeger.c +++ b/source/jeger.c @@ -734,11 +734,18 @@ bool regex_assert(const regex_t * const regex, if ((delta->in == state) && (delta->input == *s)) { + bool do_reset = false; was_found = true; + if (!match->_pos_ptr && delta->match_width) { + match->_pos_ptr = s; + do_reset = true; + } const int r = regex_assert(regex, s + delta->pattern_width, delta->to, match); if(r){ match->width += delta->match_width; return r; + } else if (do_reset) { + match->_pos_ptr = NULL; } } } @@ -750,9 +757,6 @@ bool regex_assert(const regex_t * const regex, if (my_catch && (!my_catch->pattern_width || !last_stand)) { state = my_catch->to; s += my_catch->pattern_width; - if (match->position < 1) { - match->position = my_catch->match_width; - } match->width += my_catch->match_width; goto LOOP; } @@ -786,15 +790,15 @@ match_t * regex_match(const regex_t * const regex, initial_state = (int)(!(is_start_of_string && (s == string))); *match = (match_t){ - .position = -1, - .width = 0, + ._pos_ptr = NULL, + .width = 0, }; if (regex_assert(regex, s, initial_state, match)) { - if(match->position == -1){ - match->position = (s - string); - }else{ - match->position += (s - string); + if (match->_pos_ptr) { + match->position = (match->_pos_ptr - string); + } else { + match->position = (s - string); } vector_push(&matches, match); diff --git a/source/jeger.h b/source/jeger.h index 5c6d622..090f49d 100644 --- a/source/jeger.h +++ b/source/jeger.h @@ -15,7 +15,10 @@ typedef struct { } regex_t; typedef struct { - int position; + union { + int position; + const char * _pos_ptr; + }; int width; } match_t;