Add OP_EXPECT_MORE_ALPHA opcode

This commit is contained in:
c9s 2014-05-23 22:58:20 +08:00
parent 5f75677369
commit 628f09a8f4
4 changed files with 23 additions and 22 deletions

View file

@ -181,6 +181,6 @@ int r3_pattern_to_opcode(char * pattern, int pattern_len);
enum { NODE_COMPARE_STR, NODE_COMPARE_PCRE, NODE_COMPARE_OPCODE };
enum { OP_EXPECT_DIGITS = 1, OP_EXPECT_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH };
enum { OP_EXPECT_MORE_DIGITS = 1, OP_EXPECT_MORE_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH, OP_EXPECT_MORE_ALPHA };
#endif /* !R3_NODE_H */

View file

@ -8,9 +8,6 @@
// PCRE
#include <pcre.h>
// Judy array
// #include <Judy.h>
#include "r3.h"
#include "r3_str.h"
#include "str_array.h"
@ -270,24 +267,19 @@ node * r3_tree_matchl(const node * n, char * path, int path_len, match_entry * e
e = n->edges[i];
switch(e->opcode) {
case OP_EXPECT_NOSLASH:
while (*pp != '/' && pp < pp_end) {
pp++;
}
while (*pp != '/' && pp < pp_end) pp++;
break;
case OP_EXPECT_DIGITS:
while ( isdigit(*pp) && pp < pp_end) {
pp++;
}
case OP_EXPECT_MORE_ALPHA:
while ( isalpha(*pp) && pp < pp_end) pp++;
break;
case OP_EXPECT_WORDS:
while ( (isdigit(*pp) || isalpha(*pp)) && pp < pp_end) {
pp++;
}
case OP_EXPECT_MORE_DIGITS:
while ( isdigit(*pp) && pp < pp_end) pp++;
break;
case OP_EXPECT_MORE_WORDS:
while ( (isdigit(*pp) || isalpha(*pp)) && pp < pp_end) pp++;
break;
case OP_EXPECT_NODASH:
while (*pp != '-' && pp < pp_end) {
pp++;
}
while (*pp != '-' && pp < pp_end) pp++;
break;
}
// check match

View file

@ -15,10 +15,19 @@
int r3_pattern_to_opcode(char * pattern, int len) {
if ( strncmp(pattern, "\\w+",len) == 0 ) {
return OP_EXPECT_WORDS;
return OP_EXPECT_MORE_WORDS;
}
if ( strncmp(pattern, "[0-9a-z]+",len) == 0 || strncmp(pattern, "[a-z0-9]+",len) == 0 ) {
return OP_EXPECT_MORE_WORDS;
}
if ( strncmp(pattern, "[a-z]+",len) == 0 ) {
return OP_EXPECT_MORE_ALPHA;
}
if ( strncmp(pattern, "\\d+", len) == 0 ) {
return OP_EXPECT_DIGITS;
return OP_EXPECT_MORE_DIGITS;
}
if ( strncmp(pattern, "[0-9]+", len) == 0 ) {
return OP_EXPECT_MORE_DIGITS;
}
if ( strncmp(pattern, "[^/]+", len) == 0 ) {
return OP_EXPECT_NOSLASH;

View file

@ -15,8 +15,8 @@
START_TEST (test_pattern_to_opcode)
{
ck_assert( r3_pattern_to_opcode("\\w+", strlen("\\w+")) == OP_EXPECT_WORDS );
ck_assert( r3_pattern_to_opcode("\\d+", strlen("\\d+")) == OP_EXPECT_DIGITS );
ck_assert( r3_pattern_to_opcode("\\w+", strlen("\\w+")) == OP_EXPECT_MORE_WORDS );
ck_assert( r3_pattern_to_opcode("\\d+", strlen("\\d+")) == OP_EXPECT_MORE_DIGITS );
ck_assert( r3_pattern_to_opcode("[^/]+",strlen("[^/]+")) == OP_EXPECT_NOSLASH );
ck_assert( r3_pattern_to_opcode("[^-]+",strlen("[^-]+")) == OP_EXPECT_NODASH );
}