From 750a9beaa44f65c80fed1aed49a6d25e12d97804 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 20 May 2014 23:30:36 +0800 Subject: [PATCH] _r3_tree_insert_pathl to r3_tree_insert_pathl_ --- CHANGES.md | 6 +++--- README.md | 8 ++++---- include/r3.h | 8 ++++---- src/node.c | 12 ++++++------ tests/check_tree.c | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b9287eb..630e277 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,15 +2,15 @@ API changes: -1. Removed the `route` argument from `r3_tree_insert_pathl`: +1. Removed the `route` argument from `r3_tree_insert_pathl_`: - node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data); + node * r3_tree_insert_pathl_(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_` has been moved to `_r3_tree_insert_pathl_` 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/README.md b/README.md index 9e842cb..1e75841 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ int route_data = 3; // insert the route path into the router tree r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path -r3_tree_insert_pathl(n, "/zoo", strlen("/zoo"), &route_data ); -r3_tree_insert_pathl(n, "/foo/bar", strlen("/foo/bar"), &route_data ); +r3_tree_insert_pathl_(n, "/zoo", strlen("/zoo"), &route_data ); +r3_tree_insert_pathl_(n, "/foo/bar", strlen("/foo/bar"), &route_data ); -r3_tree_insert_pathl(n ,"/post/{id}", strlen("/post/{id}") , &route_data ); +r3_tree_insert_pathl_(n ,"/post/{id}", strlen("/post/{id}") , &route_data ); -r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), &route_data ); +r3_tree_insert_pathl_(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), &route_data ); // let's compile the tree! r3_tree_compile(n); diff --git a/include/r3.h b/include/r3.h index a1b23f7..7c1d6bd 100644 --- a/include/r3.h +++ b/include/r3.h @@ -106,17 +106,17 @@ edge * r3_node_find_edge(node * n, char * pat); void r3_node_append_edge(node *n, edge *child); -node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data); +node * r3_tree_insert_pathl_(node *tree, 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) +#define r3_tree_insert_path(n,p,d) _r3_tree_insert_pathl_(n,p,strlen(p), NULL, d) // node * r3_tree_insert_route(node *tree, route * route, void * data); -#define r3_tree_insert_route(n,r,d) _r3_tree_insert_pathl(n, r->path, r->path_len, r, d) +#define r3_tree_insert_route(n,r,d) _r3_tree_insert_pathl_(n, r->path, r->path_len, r, d) /** * The private API to insert a path */ -node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route, void * data); +node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data); void r3_tree_dump(node * n, int level); diff --git a/src/node.c b/src/node.c index 9bd4b29..3e0d485 100644 --- a/src/node.c +++ b/src/node.c @@ -403,16 +403,16 @@ route * r3_route_createl(char * path, int path_len) { return info; } -node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data) +node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, void * data) { - return _r3_tree_insert_pathl(tree, path, path_len, NULL , data); + return _r3_tree_insert_pathl_(tree, path, path_len, NULL , data); } /** * Return the last inserted node. */ -node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route, void * data) +node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data) { node * n = tree; edge * e = NULL; @@ -461,7 +461,7 @@ node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route r3_node_add_child(n, strndup(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); + return _r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data); } else { node * child = r3_tree_create(3); r3_node_add_child(n, strndup(path, path_len) , child); @@ -482,7 +482,7 @@ node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route // there are something more we can insert if ( subpath_len > 0 ) { - return _r3_tree_insert_pathl(e->child, subpath, subpath_len, route, data); + return _r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data); } else { // there are no more path to insert @@ -510,7 +510,7 @@ node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route char * s2 = path + prefix_len; int s2_len = path_len - prefix_len; r3_edge_branch(e, prefix_len); - return _r3_tree_insert_pathl(e->child, s2 , s2_len, route , data); + return _r3_tree_insert_pathl_(e->child, s2 , s2_len, route , data); } else { printf("unexpected route."); return NULL; diff --git a/tests/check_tree.c b/tests/check_tree.c index 038feaa..6caf565 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -155,7 +155,7 @@ END_TEST -START_TEST (test_r3_tree_insert_pathl) +START_TEST (test_r3_tree_insert_pathl_) { node * n = r3_tree_create(10); @@ -713,7 +713,7 @@ Suite* r3_suite (void) { tcase_add_test(tcase, test_str_array); tcase_add_test(tcase, test_ltrim_slash); tcase_add_test(tcase, test_r3_node_find_edge); - tcase_add_test(tcase, test_r3_tree_insert_pathl); + tcase_add_test(tcase, test_r3_tree_insert_pathl_); tcase_add_test(tcase, test_compile); tcase_add_test(tcase, test_route_cmp); tcase_add_test(tcase, test_insert_route);