Add OP_EXPECT_NODASH opcode

This commit is contained in:
c9s 2014-05-23 11:28:19 +08:00
parent 4d93d217a4
commit c1e5ea4393
3 changed files with 5 additions and 1 deletions

View file

@ -176,6 +176,6 @@ route * r3_tree_match_route(const node *n, match_entry * entry);
int r3_pattern_to_opcode(char * pattern, int pattern_len); int r3_pattern_to_opcode(char * pattern, int pattern_len);
enum { OP_EXPECT_DIGITS = 1, OP_EXPECT_WORDS, OP_EXPECT_NOSLASH }; enum { OP_EXPECT_DIGITS = 1, OP_EXPECT_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH };
#endif /* !R3_NODE_H */ #endif /* !R3_NODE_H */

View file

@ -23,6 +23,9 @@ int r3_pattern_to_opcode(char * pattern, int pattern_len) {
if ( strncmp(pattern, "[^/]+", pattern_len) == 0 ) { if ( strncmp(pattern, "[^/]+", pattern_len) == 0 ) {
return OP_EXPECT_NOSLASH; return OP_EXPECT_NOSLASH;
} }
if ( strncmp(pattern, "[^-]+", pattern_len) == 0 ) {
return OP_EXPECT_NODASH;
}
return 0; return 0;
} }

View file

@ -18,6 +18,7 @@ START_TEST (test_pattern_to_opcode)
ck_assert( r3_pattern_to_opcode("\\w+", sizeof("\\w+") - 1) == OP_EXPECT_WORDS ); ck_assert( r3_pattern_to_opcode("\\w+", sizeof("\\w+") - 1) == OP_EXPECT_WORDS );
ck_assert( r3_pattern_to_opcode("\\d+", sizeof("\\d+") - 1) == OP_EXPECT_DIGITS ); ck_assert( r3_pattern_to_opcode("\\d+", sizeof("\\d+") - 1) == OP_EXPECT_DIGITS );
ck_assert( r3_pattern_to_opcode("[^/]+", sizeof("[^/]+") - 1) == OP_EXPECT_NOSLASH ); ck_assert( r3_pattern_to_opcode("[^/]+", sizeof("[^/]+") - 1) == OP_EXPECT_NOSLASH );
ck_assert( r3_pattern_to_opcode("[^-]+", sizeof("[^-]+") - 1) == OP_EXPECT_NODASH );
} }
END_TEST END_TEST