Rename compile_slug to slug_compile

This commit is contained in:
c9s 2014-05-20 23:25:55 +08:00
parent 99819c4bbb
commit 85001c6327
5 changed files with 10 additions and 9 deletions

View file

@ -12,7 +12,7 @@
int slug_count(char * p, int len); int slug_count(char * p, int len);
char * compile_slug(char * str, int len); char * slug_compile(char * str, int len);
bool contains_slug(char * str); bool contains_slug(char * str);

View file

@ -170,7 +170,7 @@ void r3_tree_compile_patterns(node * n) {
for ( int i = 0 ; i < n->edge_len ; i++ ) { for ( int i = 0 ; i < n->edge_len ; i++ ) {
e = n->edges[i]; e = n->edges[i];
if ( e->has_slug ) { if ( e->has_slug ) {
char * slug_pat = compile_slug(e->pattern, e->pattern_len); char * slug_pat = slug_compile(e->pattern, e->pattern_len);
strcat(p, slug_pat); strcat(p, slug_pat);
} else { } else {
strncat(p++,"(", 1); strncat(p++,"(", 1);

View file

@ -122,7 +122,7 @@ char * find_slug_pattern(char *s1, int *len) {
/** /**
* @param char * sep separator * @param char * sep separator
*/ */
char * compile_slug(char * str, int len) char * slug_compile(char * str, int len)
{ {
char *s1 = NULL, *o = NULL; char *s1 = NULL, *o = NULL;
char *pat = NULL; char *pat = NULL;

View file

@ -385,3 +385,4 @@
1400593210,13568445.16 1400593210,13568445.16
1400593219,13704926.07 1400593219,13704926.07
1400599508,13991454.07 1400599508,13991454.07
1400599553,13826120.84

1 1400242718 5649455.80
385 1400593210 13568445.16
386 1400593219 13704926.07
387 1400599508 13991454.07
388 1400599553 13826120.84

View file

@ -12,19 +12,19 @@
#include "r3_str.h" #include "r3_str.h"
#include "str_array.h" #include "str_array.h"
START_TEST (test_compile_slug) START_TEST (test_slug_compile)
{ {
char * path = "/user/{id}"; char * path = "/user/{id}";
ck_assert_str_eq( compile_slug(path, strlen(path) ) , "/user/([^/]+)" ); ck_assert_str_eq( slug_compile(path, strlen(path) ) , "/user/([^/]+)" );
char * path2 = "/what/{id}-foo"; char * path2 = "/what/{id}-foo";
ck_assert_str_eq( compile_slug(path2, strlen(path2) ) , "/what/([^/]+)-foo" ); ck_assert_str_eq( slug_compile(path2, strlen(path2) ) , "/what/([^/]+)-foo" );
char * path3 = "-{id}"; char * path3 = "-{id}";
ck_assert_str_eq(compile_slug(path3, strlen(path3)), "-([^/]+)" ); ck_assert_str_eq(slug_compile(path3, strlen(path3)), "-([^/]+)" );
char * path4 = "-{idx:\\d{3}}"; char * path4 = "-{idx:\\d{3}}";
ck_assert_str_eq(compile_slug(path4, strlen(path4)), "-(\\d{3})" ); ck_assert_str_eq(slug_compile(path4, strlen(path4)), "-(\\d{3})" );
} }
END_TEST END_TEST
@ -98,7 +98,7 @@ Suite* r3_suite (void) {
tcase_add_test(tcase, test_find_slug_placeholder); tcase_add_test(tcase, test_find_slug_placeholder);
tcase_add_test(tcase, test_find_slug_placeholder_with_broken_slug); tcase_add_test(tcase, test_find_slug_placeholder_with_broken_slug);
tcase_add_test(tcase, test_slug_count); tcase_add_test(tcase, test_slug_count);
tcase_add_test(tcase, test_compile_slug); tcase_add_test(tcase, test_slug_compile);
suite_add_tcase(suite, tcase); suite_add_tcase(suite, tcase);
return suite; return suite;