diff --git a/include/r3_str.h b/include/r3_str.h index c670387..3072fef 100644 --- a/include/r3_str.h +++ b/include/r3_str.h @@ -10,8 +10,6 @@ #include "r3.h" #include "config.h" -int slug_count(const char * p, int len, char ** errstr); - char * slug_compile(const char * str, int len); char * slug_find_pattern(const char *s1, int *len); diff --git a/src/slug.c b/src/slug.c index 004516a..54b4b30 100644 --- a/src/slug.c +++ b/src/slug.c @@ -143,3 +143,79 @@ r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **err } 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; +} + + diff --git a/src/slug.h b/src/slug.h index d1328c0..7a44ea8 100644 --- a/src/slug.h +++ b/src/slug.h @@ -49,7 +49,9 @@ 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) { +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; } diff --git a/src/str.c b/src/str.c index a1f4c25..6e02356 100644 --- a/src/str.c +++ b/src/str.c @@ -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 * s1 = offset;