mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o Anchor support for the regex engine.
This commit is contained in:
parent
8c0aaf9326
commit
22a0881ded
@ -330,20 +330,33 @@ struct matcher *matcher_create(struct pool *mem, const char **patterns, int num)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct dfa_state *
|
||||
_step_matcher(unsigned char c, struct dfa_state *cs, int *r)
|
||||
{
|
||||
if (!(cs = cs->lookup[c]))
|
||||
return NULL;
|
||||
|
||||
if (cs->final && (cs->final > *r))
|
||||
*r = cs->final;
|
||||
|
||||
return cs;
|
||||
}
|
||||
|
||||
int matcher_run(struct matcher *m, const char *b)
|
||||
{
|
||||
struct dfa_state *cs = m->start;
|
||||
int r = 0;
|
||||
|
||||
for (; *b; b++) {
|
||||
if (!(cs = _step_matcher(HAT_CHAR, cs, &r)))
|
||||
goto out;
|
||||
|
||||
if (!(cs = cs->lookup[(int) (unsigned char) *b]))
|
||||
break;
|
||||
for (; *b; b++)
|
||||
if (!(cs = _step_matcher(*b, cs, &r)))
|
||||
goto out;
|
||||
|
||||
if (cs->final && (cs->final > r))
|
||||
r = cs->final;
|
||||
}
|
||||
_step_matcher(DOLLAR_CHAR, cs, &r);
|
||||
|
||||
out:
|
||||
/* subtract 1 to get back to zero index */
|
||||
return r - 1;
|
||||
}
|
||||
|
@ -22,6 +22,14 @@ struct parse_sp { /* scratch pad for the parsing process */
|
||||
|
||||
static struct rx_node *_or_term(struct parse_sp *ps);
|
||||
|
||||
static void _single_char(struct parse_sp *ps, unsigned int c, const char *ptr)
|
||||
{
|
||||
ps->type = 0;
|
||||
ps->cursor = ptr + 1;
|
||||
bit_clear_all(ps->charset);
|
||||
bit_set(ps->charset, c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the next token from the regular expression.
|
||||
* Returns: 1 success, 0 end of input, -1 error.
|
||||
@ -125,12 +133,18 @@ static int _get_token(struct parse_sp *ps)
|
||||
case '+':
|
||||
case '?':
|
||||
case '|':
|
||||
case '^':
|
||||
case '$':
|
||||
ps->type = (int) *ptr;
|
||||
ps->cursor = ptr + 1;
|
||||
break;
|
||||
|
||||
case '^':
|
||||
_single_char(ps, HAT_CHAR, ptr);
|
||||
break;
|
||||
|
||||
case '$':
|
||||
_single_char(ps, DOLLAR_CHAR, ptr);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
/* The 'all but newline' character set */
|
||||
ps->type = 0;
|
||||
|
@ -15,11 +15,17 @@ enum {
|
||||
PLUS,
|
||||
OR,
|
||||
QUEST,
|
||||
CHARSET,
|
||||
HAT,
|
||||
DOLLAR
|
||||
CHARSET
|
||||
};
|
||||
|
||||
/*
|
||||
* We're never going to be running the regex on non-printable
|
||||
* chars, so we can use a couple of these chars to represent the
|
||||
* start and end of a string.
|
||||
*/
|
||||
#define HAT_CHAR 0x2
|
||||
#define DOLLAR_CHAR 0x2
|
||||
|
||||
struct rx_node {
|
||||
int type;
|
||||
bitset_t charset;
|
||||
|
Loading…
Reference in New Issue
Block a user