diff --git a/include/r3_str.h b/include/r3_str.h index 1504486..c670387 100644 --- a/include/r3_str.h +++ b/include/r3_str.h @@ -14,8 +14,6 @@ int slug_count(const char * p, int len, char ** errstr); char * slug_compile(const char * str, int len); -bool contains_slug(const char * str); - char * slug_find_pattern(const char *s1, int *len); char * slug_find_placeholder(const char *s1, int *len); diff --git a/src/node.c b/src/node.c index 2bbbe7c..19262b2 100644 --- a/src/node.c +++ b/src/node.c @@ -10,6 +10,7 @@ #include "r3.h" #include "r3_str.h" +#include "slug.h" #include "zmalloc.h" @@ -629,7 +630,7 @@ bool r3_node_has_slug_edges(const node *n) { edge *e; for ( int i = 0 ; i < n->edge_len ; i++ ) { e = n->edges[i]; - e->has_slug = contains_slug(e->pattern); + e->has_slug = r3_path_contains_slug_char(e->pattern); if (e->has_slug) found = TRUE; } diff --git a/src/slug.c b/src/slug.c index 4c71b22..004516a 100644 --- a/src/slug.c +++ b/src/slug.c @@ -13,11 +13,6 @@ #include "slug.h" #include "zmalloc.h" -inline static int contains_slug_char(const char * str); - -inline static int contains_slug_char(const char * str) { - return strchr(str, '{') != NULL ? 1 : 0; -} r3_slug_t * r3_slug_new(char * path, int path_len) { @@ -46,7 +41,7 @@ void r3_slug_free(r3_slug_t * s) { * Return 0 means Empty * Return -1 means Error */ -int r3_slug_check(r3_slug_t *s, char **errstr) { +int r3_slug_check(r3_slug_t *s) { // if it's empty if (s->begin == NULL && s->len == 0) { return 0; @@ -88,7 +83,7 @@ r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **err } // there is no slug - if (!contains_slug_char(offset)) { + if (!r3_path_contains_slug_char(offset)) { return NULL; } diff --git a/src/slug.h b/src/slug.h index 4980b1b..d1328c0 100644 --- a/src/slug.h +++ b/src/slug.h @@ -41,7 +41,7 @@ typedef struct { r3_slug_t * r3_slug_new(char * path, int path_len); -int r3_slug_check(r3_slug_t *s, char **errstr); +int r3_slug_check(r3_slug_t *s); r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **errstr); @@ -49,4 +49,8 @@ char * r3_slug_to_str(const r3_slug_t *s); void r3_slug_free(r3_slug_t * s); +inline int r3_path_contains_slug_char(const char * str) { + return strchr(str, '{') != NULL ? 1 : 0; +} + #endif /* !SLUG_H */ diff --git a/src/str.c b/src/str.c index 5e708c4..a1f4c25 100644 --- a/src/str.c +++ b/src/str.c @@ -73,10 +73,6 @@ int slug_count(const char * needle, int len, char **errstr) { return cnt; } -bool contains_slug(const char * str) { - return strchr(str, '{') != NULL ? TRUE : FALSE; -} - char * inside_slug(const char * needle, int needle_len, char *offset, char **errstr) { char * s1 = offset; char * s2 = offset; diff --git a/tests/check_slug.c b/tests/check_slug.c index 04b49dd..743a53e 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -45,8 +45,7 @@ END_TEST START_TEST (test_contains_slug) { - char * path = "/user/{id}/{name}"; - ck_assert( contains_slug(path) ); + ck_assert( r3_path_contains_slug_char("/user/{id}/{name}") ); } END_TEST