From 04d8977b21ce8223c3aef38fc9a86462c724b438 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 14:47:46 +0800 Subject: [PATCH] r3_tree_insert_pathl_ex function --- CHANGES.md | 6 +++--- include/r3.h | 4 ++-- src/node.c | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b8420a0..c784eda 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,15 +18,15 @@ by Yo-An Lin API changes: -1. Removed the `route` argument from `r3_tree_insert_pathl_`: +1. Removed the `route` argument from `r3_tree_insert_pathl_ex`: - node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, void * data); + node * r3_tree_insert_pathl_ex(node *tree, char *path, int path_len, void * data); This reduce the interface complexity, e.g., r3_tree_insert_path(n, "/user2/{id:\\d+}", &var2); -2. The original `r3_tree_insert_pathl_` has been moved to `r3_tree_insert_pathl_` as a private API. +2. The original `r3_tree_insert_pathl_ex` has been moved to `r3_tree_insert_pathl_ex` as a private API. 3. Moved `r3_tree_matchl` to `r3_tree_matchl` since it require the length of the path string. diff --git a/include/r3.h b/include/r3.h index d91f4a5..a8568d4 100644 --- a/include/r3.h +++ b/include/r3.h @@ -115,7 +115,7 @@ node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * d route * r3_tree_insert_routel(node *tree, int method, const char *path, int path_len, void *data); -#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_(n,p,strlen(p), NULL, d, NULL) +#define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_ex(n,p,strlen(p), NULL, d, NULL) #define r3_tree_insert_route(n,method,path,data) r3_tree_insert_routel(n, method, path, strlen(path), data) @@ -123,7 +123,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path /** * The private API to insert a path */ -node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr); +node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr); void r3_tree_dump(const node * n, int level); diff --git a/src/node.c b/src/node.c index ed46a55..31ef3c8 100644 --- a/src/node.c +++ b/src/node.c @@ -468,7 +468,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path route *r = r3_route_createl(path, path_len); CHECK_PTR(r); r->request_method = method; // ALLOW GET OR POST METHOD - r3_tree_insert_pathl_(tree, path, path_len, r, data, NULL); + r3_tree_insert_pathl_ex(tree, path, path_len, r, data, NULL); return r; } @@ -476,7 +476,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data) { - return r3_tree_insert_pathl_(tree, path, path_len, NULL , data, NULL); + return r3_tree_insert_pathl_ex(tree, path, path_len, NULL , data, NULL); } @@ -552,7 +552,7 @@ edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix /** * Return the last inserted node. */ -node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * route, void * data, char **errstr) +node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char **errstr) { node * n = tree; @@ -602,7 +602,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * r3_node_connect(n, zstrndup(path, (int)(p - path)), child); // and insert the rest part to the child - return r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data, errstr); + return r3_tree_insert_pathl_ex(child, p, path_len - (int)(p - path), route, data, errstr); } else { if (slug_cnt == 1) { @@ -644,7 +644,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * int restlen = path_len - ((slug_p - path) + slug_len); if (restlen) { - return r3_tree_insert_pathl_(c2, slug_p + slug_len, restlen, route, data, errstr); + return r3_tree_insert_pathl_ex(c2, slug_p + slug_len, restlen, route, data, errstr); } c2->data = data; @@ -673,7 +673,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * // there are something more we can insert if ( subpath_len > 0 ) { - return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data, errstr); + return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, route, data, errstr); } else { // there are no more path to insert @@ -696,7 +696,7 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route * * we should split the end point and make a branch here... */ r3_edge_branch(e, prefix_len); - return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route , data, errstr); + return r3_tree_insert_pathl_ex(e->child, subpath, subpath_len, route , data, errstr); } else { fprintf(stderr, "unexpected route."); return NULL;