refactoring matchl function
This commit is contained in:
parent
36a330292b
commit
8e39e58c88
1 changed files with 23 additions and 19 deletions
16
src/node.c
16
src/node.c
|
@ -280,9 +280,11 @@ node * r3_tree_matchl(const node * n, const char * path, int path_len, match_ent
|
||||||
unsigned short i;
|
unsigned short i;
|
||||||
unsigned short restlen;
|
unsigned short restlen;
|
||||||
|
|
||||||
if (n->compare_type == NODE_COMPARE_OPCODE) {
|
|
||||||
const char *pp;
|
const char *pp;
|
||||||
const char *pp_end = path + path_len;
|
const char *pp_end;
|
||||||
|
|
||||||
|
if (n->compare_type == NODE_COMPARE_OPCODE) {
|
||||||
|
pp_end = path + path_len;
|
||||||
|
|
||||||
i = n->edge_len;
|
i = n->edge_len;
|
||||||
while(i--) {
|
while(i--) {
|
||||||
|
@ -322,7 +324,7 @@ node * r3_tree_matchl(const node * n, const char * path, int path_len, match_ent
|
||||||
// if the pcre_pattern is found, and the pointer is not NULL, then it's
|
// if the pcre_pattern is found, and the pointer is not NULL, then it's
|
||||||
// pcre pattern node, we use pcre_exec to match the nodes
|
// pcre pattern node, we use pcre_exec to match the nodes
|
||||||
if (n->pcre_pattern) {
|
if (n->pcre_pattern) {
|
||||||
char *substring_start = NULL;
|
const char *substring_start = NULL;
|
||||||
int substring_length = 0;
|
int substring_length = 0;
|
||||||
int ov[ n->ov_cnt ];
|
int ov[ n->ov_cnt ];
|
||||||
char rc;
|
char rc;
|
||||||
|
@ -361,11 +363,14 @@ node * r3_tree_matchl(const node * n, const char * path, int path_len, match_ent
|
||||||
|
|
||||||
for (i = 1; i < rc; i++)
|
for (i = 1; i < rc; i++)
|
||||||
{
|
{
|
||||||
substring_start = ((char*) path) + ov[2*i];
|
substring_start = path + ov[2*i];
|
||||||
substring_length = ov[2*i+1] - ov[2*i];
|
substring_length = ov[2*i+1] - ov[2*i];
|
||||||
// info("%2d: %.*s\n", i, substring_length, substring_start);
|
// info("%2d: %.*s\n", i, substring_length, substring_start);
|
||||||
|
|
||||||
if ( substring_length > 0) {
|
if ( substring_length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
restlen = path_len - ov[1]; // fully match to the end
|
restlen = path_len - ov[1]; // fully match to the end
|
||||||
// info("matched item => restlen:%d edges:%d i:%d\n", restlen, n->edge_len, i);
|
// info("matched item => restlen:%d edges:%d i:%d\n", restlen, n->edge_len, i);
|
||||||
|
|
||||||
|
@ -381,7 +386,6 @@ node * r3_tree_matchl(const node * n, const char * path, int path_len, match_ent
|
||||||
// get the length of orginal string: $0
|
// get the length of orginal string: $0
|
||||||
return r3_tree_matchl( e->child, path + (ov[1] - ov[0]), restlen, entry);
|
return r3_tree_matchl( e->child, path + (ov[1] - ov[0]), restlen, entry);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// does not match
|
// does not match
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue