>most tests pass >hl completelly breaks

This commit is contained in:
anon 2023-09-23 15:55:36 +02:00
parent 9ca9006a9a
commit e0a5c54b62
2 changed files with 17 additions and 10 deletions

View File

@ -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);

View File

@ -15,7 +15,10 @@ typedef struct {
} regex_t;
typedef struct {
int position;
union {
int position;
const char * _pos_ptr;
};
int width;
} match_t;