|
|
@@ -311,19 +311,6 @@ static int compile_range(const char * const range, |
|
|
|
return ((s - range) + 1); |
|
|
|
} |
|
|
|
|
|
|
|
static bool catch_(const regex_t * const regex, |
|
|
|
int * const state) { |
|
|
|
|
|
|
|
for (size_t i = 0; i < regex->catch_table.element_count; i++){ |
|
|
|
const offshoot_t * const offshoot = *(offshoot_t**)vector_get(®ex->catch_table, i); |
|
|
|
if (offshoot->in == *state) { |
|
|
|
*state = offshoot->to; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
#define HALT_AND_CATCH_FIRE -1 |
|
|
|
|
|
|
|
void HOOK_ALL(int from, |
|
|
@@ -343,7 +330,7 @@ void HOOK_ALL(int from, |
|
|
|
vector_push(&cs->regex->delta_table, |
|
|
|
&delta); |
|
|
|
} |
|
|
|
if (cs->do_catch || cs->is_negative) { |
|
|
|
if (*cs->do_catch || *cs->is_negative) { |
|
|
|
offshoot_t * offshoot = malloc(sizeof(offshoot_t)); |
|
|
|
offshoot->in = *cs->state + from; |
|
|
|
offshoot->to = hook_to; |
|
|
@@ -383,6 +370,7 @@ regex_t * regex_compile(const char * const pattern) { |
|
|
|
assert(!is_quantifier(*pattern) && "Pattern starts with quantifier."); |
|
|
|
whitelist[0] = '\00'; |
|
|
|
do_catch = false; |
|
|
|
is_negative = false; |
|
|
|
width = 1; |
|
|
|
|
|
|
|
switch (*s) { |
|
|
@@ -454,9 +442,23 @@ int regex_free(regex_t * const regex) { |
|
|
|
// ----------------- |
|
|
|
// ### Searching ### |
|
|
|
// ----------------- |
|
|
|
static bool regex_assert(const regex_t * const regex, |
|
|
|
static bool catch_(const regex_t * const regex, |
|
|
|
int * const state) { |
|
|
|
|
|
|
|
for (size_t i = 0; i < regex->catch_table.element_count; i++){ |
|
|
|
const offshoot_t * const offshoot = *(offshoot_t**)vector_get(®ex->catch_table, i); |
|
|
|
if (offshoot->in == *state) { |
|
|
|
*state = offshoot->to; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
static int regex_assert(const regex_t * const regex, |
|
|
|
const char * const string, |
|
|
|
int state) { |
|
|
|
int state, |
|
|
|
int * width) { |
|
|
|
|
|
|
|
for (const char * s = string; *s != '\00'; s++) { |
|
|
|
// delta |
|
|
@@ -474,14 +476,14 @@ static bool regex_assert(const regex_t * const regex, |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
return (state == regex->accepting_state); |
|
|
|
} |
|
|
|
|
|
|
|
return (state == regex->accepting_state); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool regex_search( regex_t * regex, |
|
|
|
const char * const string) { |
|
|
|
int regex_match( regex_t * regex, |
|
|
|
const char * const string) { |
|
|
|
|
|
|
|
if (regex == NULL) { |
|
|
|
return false; |
|
|
@@ -490,5 +492,13 @@ bool regex_search( regex_t * regex, |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return regex_assert(regex, string, 0); |
|
|
|
int r = 0; |
|
|
|
return regex_assert(regex, string, 0, &r); |
|
|
|
} |
|
|
|
|
|
|
|
bool regex_search( regex_t * regex, |
|
|
|
const char * const string) { |
|
|
|
|
|
|
|
return (bool)regex_match(regex, string, 0); |
|
|
|
} |
|
|
|
|