backtracking fix; '\<test' == 'ttest' bug recreated
This commit is contained in:
parent
64fcc77fa1
commit
99127233db
@ -131,7 +131,11 @@ typedef struct {
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// ### Regex creation/destruction ###
|
// ### Regex creation/destruction ###
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
static const int HALT_AND_CATCH_FIRE = INT_MIN;
|
enum {
|
||||||
|
ASSERTION_FAILURE = 0,
|
||||||
|
ASSERTION_SUCCESS = 1,
|
||||||
|
HALT_AND_CATCH_FIRE = INT_MIN,
|
||||||
|
};
|
||||||
|
|
||||||
#define ASSERT_HALT(a) ((a == HALT_AND_CATCH_FIRE) ? HALT_AND_CATCH_FIRE : (cs->state + a))
|
#define ASSERT_HALT(a) ((a == HALT_AND_CATCH_FIRE) ? HALT_AND_CATCH_FIRE : (cs->state + a))
|
||||||
|
|
||||||
@ -707,12 +711,12 @@ const offshoot_t * catch_table_lookup(const regex_t * const regex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
bool regex_assert(const regex_t * const regex,
|
int regex_assert(const regex_t * const regex,
|
||||||
const char * const string,
|
const char * const string,
|
||||||
int state,
|
int state,
|
||||||
match_t * const match) {
|
match_t * const match) {
|
||||||
if (state == HALT_AND_CATCH_FIRE) {
|
if (state == HALT_AND_CATCH_FIRE) {
|
||||||
return false;
|
return HALT_AND_CATCH_FIRE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool last_stand = false;
|
bool last_stand = false;
|
||||||
@ -753,11 +757,16 @@ bool regex_assert(const regex_t * const regex,
|
|||||||
do_reset = true;
|
do_reset = true;
|
||||||
}
|
}
|
||||||
const int r = regex_assert(regex, s + delta->pattern_width, delta->to, match);
|
const int r = regex_assert(regex, s + delta->pattern_width, delta->to, match);
|
||||||
if(r){
|
if(r == ASSERTION_SUCCESS){
|
||||||
match->width += delta->match_width;
|
match->width += delta->match_width;
|
||||||
return r;
|
return r;
|
||||||
} else if (do_reset) {
|
} else {
|
||||||
match->_pos_ptr = NULL;
|
if (r == ASSERTION_FAILURE) {
|
||||||
|
was_found = false;
|
||||||
|
}
|
||||||
|
if (do_reset) {
|
||||||
|
match->_pos_ptr = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,7 +784,7 @@ bool regex_assert(const regex_t * const regex,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (state == regex->accepting_state);
|
return ((state == regex->accepting_state) ? ASSERTION_SUCCESS : ASSERTION_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
match_t * regex_match(const regex_t * const regex,
|
match_t * regex_match(const regex_t * const regex,
|
||||||
@ -806,7 +815,8 @@ match_t * regex_match(const regex_t * const regex,
|
|||||||
.width = 0,
|
.width = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (regex_assert(regex, s, initial_state, match)) {
|
if (regex_assert(regex, s, initial_state, match) == 1) {
|
||||||
|
//printf("true: %s\n", s);
|
||||||
if (match->_pos_ptr) {
|
if (match->_pos_ptr) {
|
||||||
match->position = (match->_pos_ptr - string);
|
match->position = (match->_pos_ptr - string);
|
||||||
} else {
|
} else {
|
||||||
@ -818,6 +828,7 @@ match_t * regex_match(const regex_t * const regex,
|
|||||||
s += ((match->width > 0) ? match->width : 1);
|
s += ((match->width > 0) ? match->width : 1);
|
||||||
match = (match_t *)malloc(sizeof(match_t));
|
match = (match_t *)malloc(sizeof(match_t));
|
||||||
} else {
|
} else {
|
||||||
|
//printf("false: %s\n", s);
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
} while (*s != '\0');
|
} while (*s != '\0');
|
||||||
|
Loading…
Reference in New Issue
Block a user