regex lenghts work

This commit is contained in:
anon 2023-08-26 22:39:07 +02:00
parent 6fc917b7b7
commit 4d179689d5
3 changed files with 11 additions and 9 deletions

View File

@ -187,9 +187,10 @@ int token_fits(const token_t * const token,
const char * const to,
const int string_offset,
int * match_offset) {
UNUSED(match_offset);
//return regex_match(pattern, to, string_offset, match_offset);
return regex_search(token->syntax, to + string_offset);
return regex_match(token->syntax, to + string_offset);
}
void render_string(const char * const string,

View File

@ -458,7 +458,7 @@ static bool catch_(const regex_t * const regex,
static int regex_assert(const regex_t * const regex,
const char * const string,
int state,
int * width) {
int width) {
for (const char * s = string; *s != '\00'; s++) {
// delta
@ -466,8 +466,9 @@ static int regex_assert(const regex_t * const regex,
const delta_t * const delta = *(delta_t**)vector_get(&regex->delta_table, i);
if ((delta->in == state)
&& (delta->input == *s)) {
if(regex_assert(regex, s + delta->width, delta->to)){
return true;
int r = regex_assert(regex, s + delta->width, delta->to, width + 1);
if(r){
return r;
}
}
}
@ -476,7 +477,7 @@ static int regex_assert(const regex_t * const regex,
continue;
}
return (state == regex->accepting_state);
return (state == regex->accepting_state) ? width : false;
}
return false;
@ -492,13 +493,12 @@ int regex_match( regex_t * regex,
return true;
}
int r = 0;
return regex_assert(regex, string, 0, &r);
return regex_assert(regex, string, 0, 0);
}
bool regex_search( regex_t * regex,
const char * const string) {
return (bool)regex_match(regex, string, 0);
return (bool)regex_match(regex, string);
}

View File

@ -14,8 +14,9 @@ typedef struct {
} regex_t;
extern regex_t * regex_compile(const char * const pattern);
extern bool regex_search(regex_t * regex, const char * const string);
extern int regex_free(regex_t * const regex);
extern bool regex_search(regex_t * regex, const char * const string);
extern int regex_match(regex_t * regex, const char * const string);
extern bool is_magic(const char c);