Skip to content

Commit

Permalink
Add OP_EXPECT_MORE_ALPHA opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 23, 2014
1 parent 5f75677 commit 628f09a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion include/r3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
26 changes: 9 additions & 17 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// PCRE
#include <pcre.h>

// Judy array
// #include <Judy.h>

#include "r3.h"
#include "r3_str.h"
#include "str_array.h"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/check_slug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 628f09a

Please sign in to comment.