mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +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;
|
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)
|
int matcher_run(struct matcher *m, const char *b)
|
||||||
{
|
{
|
||||||
struct dfa_state *cs = m->start;
|
struct dfa_state *cs = m->start;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
for (; *b; b++) {
|
if (!(cs = _step_matcher(HAT_CHAR, cs, &r)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (!(cs = cs->lookup[(int) (unsigned char) *b]))
|
for (; *b; b++)
|
||||||
break;
|
if (!(cs = _step_matcher(*b, cs, &r)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (cs->final && (cs->final > r))
|
_step_matcher(DOLLAR_CHAR, cs, &r);
|
||||||
r = cs->final;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
out:
|
||||||
/* subtract 1 to get back to zero index */
|
/* subtract 1 to get back to zero index */
|
||||||
return r - 1;
|
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 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.
|
* Get the next token from the regular expression.
|
||||||
* Returns: 1 success, 0 end of input, -1 error.
|
* 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 '|':
|
case '|':
|
||||||
case '^':
|
|
||||||
case '$':
|
|
||||||
ps->type = (int) *ptr;
|
ps->type = (int) *ptr;
|
||||||
ps->cursor = ptr + 1;
|
ps->cursor = ptr + 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '^':
|
||||||
|
_single_char(ps, HAT_CHAR, ptr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '$':
|
||||||
|
_single_char(ps, DOLLAR_CHAR, ptr);
|
||||||
|
break;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
/* The 'all but newline' character set */
|
/* The 'all but newline' character set */
|
||||||
ps->type = 0;
|
ps->type = 0;
|
||||||
|
@ -15,11 +15,17 @@ enum {
|
|||||||
PLUS,
|
PLUS,
|
||||||
OR,
|
OR,
|
||||||
QUEST,
|
QUEST,
|
||||||
CHARSET,
|
CHARSET
|
||||||
HAT,
|
|
||||||
DOLLAR
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 {
|
struct rx_node {
|
||||||
int type;
|
int type;
|
||||||
bitset_t charset;
|
bitset_t charset;
|
||||||
|
Loading…
Reference in New Issue
Block a user