static inline

This commit is contained in:
c9s 2014-06-02 06:32:30 +08:00
parent 0eb9cad11c
commit a6be7f5061
4 changed files with 79 additions and 36 deletions

View file

@ -10,8 +10,6 @@
#include "r3.h" #include "r3.h"
#include "config.h" #include "config.h"
int slug_count(const char * p, int len, char ** errstr);
char * slug_compile(const char * str, int len); char * slug_compile(const char * str, int len);
char * slug_find_pattern(const char *s1, int *len); char * slug_find_pattern(const char *s1, int *len);

View file

@ -143,3 +143,79 @@ r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **err
} }
return s; return s;
} }
/*
int slug_count2(char * needle, int needle_len, char **errstr) {
// r3_slug_t * s = r3_slug_parse(needle, needle_len, needle);
int cnt = 0;
int state = 0;
char * p = (char*) needle;
while( (p-needle) < len) {
if (*p == '\\' ) {
p++; p++;
}
if (state == 1 && *p == '}') {
cnt++;
}
if ( *p == '{' ) {
state++;
} else if ( *p == '}' ) {
state--;
}
p++;
};
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
if (state != 0) {
if (errstr) {
asprintf(errstr, "incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
}
return 0;
}
return cnt;
}
*/
/**
* provide a quick way to count slugs, simply search for '{'
*/
int slug_count(const char * needle, int len, char **errstr) {
int cnt = 0;
int state = 0;
char * p = (char*) needle;
while( (p-needle) < len) {
if (*p == '\\' ) {
p++; p++;
}
if (state == 1 && *p == '}') {
cnt++;
}
if ( *p == '{' ) {
state++;
} else if ( *p == '}' ) {
state--;
}
p++;
};
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
if (state != 0) {
if (errstr) {
asprintf(errstr, "incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
}
return 0;
}
return cnt;
}

View file

@ -49,7 +49,9 @@ char * r3_slug_to_str(const r3_slug_t *s);
void r3_slug_free(r3_slug_t * s); void r3_slug_free(r3_slug_t * s);
inline int r3_path_contains_slug_char(const char * str) { int slug_count(const char * needle, int len, char **errstr);
static inline int r3_path_contains_slug_char(const char * str) {
return strchr(str, '{') != NULL ? 1 : 0; return strchr(str, '{') != NULL ? 1 : 0;
} }

View file

@ -39,39 +39,6 @@ int r3_pattern_to_opcode(const char * pattern, int len) {
/**
* provide a quick way to count slugs, simply search for '{'
*/
int slug_count(const char * needle, int len, char **errstr) {
int cnt = 0;
int state = 0;
char * p = (char*) needle;
while( (p-needle) < len) {
if (*p == '\\' ) {
p++; p++;
}
if (state == 1 && *p == '}') {
cnt++;
}
if ( *p == '{' ) {
state++;
} else if ( *p == '}' ) {
state--;
}
p++;
};
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
if (state != 0) {
if (errstr) {
asprintf(errstr, "incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
}
return 0;
}
return cnt;
}
char * inside_slug(const char * needle, int needle_len, char *offset, char **errstr) { char * inside_slug(const char * needle, int needle_len, char *offset, char **errstr) {
char * s1 = offset; char * s1 = offset;