6 static const char *OP_and =
"&";
7 static const char *OP_or =
"|";
8 static const char *OP_not =
"!";
10 #define is_operator(c) ((c) == '|' || (c) == '&' || (c) == '!')
11 #define is_separator(c) (is_operator(c) || (c) == '(' || (c) == ')')
17 free((
char *)self->p);
18 strfilter_node__delete(self->l);
19 strfilter_node__delete(self->r);
27 strfilter_node__delete(self->root);
32 static const char *get_token(
const char *
s,
const char **
e)
51 if (*(p - 1) ==
'\\' || (*p ==
'!' && *(p - 1) ==
'[')) {
85 memset(&root, 0,
sizeof(root));
86 last_op = cur = &
root;
89 while (*s !=
'\0' && *s !=
')') {
92 if (!cur->
r || !last_op->
r)
94 cur = strfilter_node__alloc(OP_and, last_op->
r,
NULL);
101 if (!cur->
r || !
root.r)
103 cur = strfilter_node__alloc(OP_or,
root.r,
NULL);
112 cur->
r = strfilter_node__alloc(OP_not,
NULL,
NULL);
120 cur->
r = strfilter_node__new(s + 1, &s);
123 if (!cur->
r || *s !=
')')
133 cur->
r->p = strndup(s, e - s);
137 s = get_token(e, &e);
147 strfilter_node__delete(
root.r);
158 const char *ep =
NULL;
161 ret->
root = strfilter_node__new(rules, &ep);
163 if (!ret || !ret->
root || *ep !=
'\0') {
176 if (!
self || !self->p)
181 return strfilter_node__compare(self->l, str) ||
182 strfilter_node__compare(self->r, str);
184 return strfilter_node__compare(self->l, str) &&
185 strfilter_node__compare(self->r, str);
187 return !strfilter_node__compare(self->r, str);
198 return strfilter_node__compare(self->root, str);