regex lenghts work
This commit is contained in:
parent
6fc917b7b7
commit
4d179689d5
@ -187,9 +187,10 @@ int token_fits(const token_t * const token,
|
|||||||
const char * const to,
|
const char * const to,
|
||||||
const int string_offset,
|
const int string_offset,
|
||||||
int * match_offset) {
|
int * match_offset) {
|
||||||
|
UNUSED(match_offset);
|
||||||
|
|
||||||
//return regex_match(pattern, to, string_offset, 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,
|
void render_string(const char * const string,
|
||||||
|
@ -458,7 +458,7 @@ static bool catch_(const regex_t * const regex,
|
|||||||
static int regex_assert(const regex_t * const regex,
|
static int regex_assert(const regex_t * const regex,
|
||||||
const char * const string,
|
const char * const string,
|
||||||
int state,
|
int state,
|
||||||
int * width) {
|
int width) {
|
||||||
|
|
||||||
for (const char * s = string; *s != '\00'; s++) {
|
for (const char * s = string; *s != '\00'; s++) {
|
||||||
// delta
|
// delta
|
||||||
@ -466,8 +466,9 @@ static int regex_assert(const regex_t * const regex,
|
|||||||
const delta_t * const delta = *(delta_t**)vector_get(®ex->delta_table, i);
|
const delta_t * const delta = *(delta_t**)vector_get(®ex->delta_table, i);
|
||||||
if ((delta->in == state)
|
if ((delta->in == state)
|
||||||
&& (delta->input == *s)) {
|
&& (delta->input == *s)) {
|
||||||
if(regex_assert(regex, s + delta->width, delta->to)){
|
int r = regex_assert(regex, s + delta->width, delta->to, width + 1);
|
||||||
return true;
|
if(r){
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -476,7 +477,7 @@ static int regex_assert(const regex_t * const regex,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (state == regex->accepting_state);
|
return (state == regex->accepting_state) ? width : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -492,13 +493,12 @@ int regex_match( regex_t * regex,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = 0;
|
return regex_assert(regex, string, 0, 0);
|
||||||
return regex_assert(regex, string, 0, &r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool regex_search( regex_t * regex,
|
bool regex_search( regex_t * regex,
|
||||||
const char * const string) {
|
const char * const string) {
|
||||||
|
|
||||||
return (bool)regex_match(regex, string, 0);
|
return (bool)regex_match(regex, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@ typedef struct {
|
|||||||
} regex_t;
|
} regex_t;
|
||||||
|
|
||||||
extern regex_t * regex_compile(const char * const pattern);
|
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 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);
|
extern bool is_magic(const char c);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user