Skip to content

Commit

Permalink
Simplify the codes
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Mar 13, 2020
1 parent 3ab3529 commit c7d4b9e
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions routes/yaf_route_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,34 @@ static int yaf_route_rewrite_match(yaf_route_t *router, const zend_string *uri,

m = Z_STRVAL_P(match);
l = Z_STRLEN_P(match);
while ((pos = memchr(m, YAF_ROUTER_URL_DELIMIETER, l))) {
size_t seg_len = pos - m;
if (seg_len) {
if (*m == '*') {
smart_str_appendl(&pattern, "(?P<__yaf_route_rest>.*)", sizeof("(?P<__yaf_route_rest>.*)") -1);
break;
while (l) {
if (*m == '*') {
smart_str_appendl(&pattern, "(?P<__yaf_route_rest>.*)", sizeof("(?P<__yaf_route_rest>.*)") -1);
break;
} else {
uint32_t len;
pos = memchr(m, YAF_ROUTER_URL_DELIMIETER, l);
if (pos) {
len = pos - m;
l -= len;
} else {
len = l;
l = 0;
}
if (*m == ':') {
smart_str_appendl(&pattern, "(?P<", sizeof("(?P<") -1 );
smart_str_appendl(&pattern, m + 1, seg_len - 1);
smart_str_appendl(&pattern, m + 1, len - 1);
smart_str_appendl(&pattern, ">[^", sizeof(">[^") - 1);
smart_str_appendc(&pattern, YAF_ROUTER_URL_DELIMIETER);
smart_str_appendl(&pattern, "]+)", sizeof("]+)") - 1);
} else {
smart_str_appendl(&pattern, m, seg_len);
smart_str_appendl(&pattern, m, len);
}
if (pos) {
smart_str_appendc(&pattern, YAF_ROUTER_URL_DELIMIETER);
m = ++pos;
l--;
}
}
pos++;
smart_str_appendc(&pattern, YAF_ROUTER_URL_DELIMIETER);
l -= pos - m;
m = pos;

}

if (l) {
if (*m == '*') {
smart_str_appendl(&pattern, "(?P<__yaf_route_rest>.*)", sizeof("(?P<__yaf_route_rest>.*)") -1);
} else if (*m == ':') {
smart_str_appendl(&pattern, "(?P<", sizeof("(?P<") -1 );
smart_str_appendl(&pattern, m, l - 1);
smart_str_appendl(&pattern, ">[^", sizeof(">[^") - 1);
smart_str_appendc(&pattern, YAF_ROUTER_URL_DELIMIETER);
smart_str_appendl(&pattern, "]+)", sizeof("]+)") - 1);
} else {
smart_str_appendl(&pattern, m, l);
}
}

Expand Down

0 comments on commit c7d4b9e

Please sign in to comment.