r3_path_contains_slug_char function

This commit is contained in:
c9s 2014-06-02 06:27:35 +08:00
parent 3512bf033a
commit 0eb9cad11c
6 changed files with 10 additions and 17 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 */

View file

@ -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;

View file

@ -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