static int TestReuseRegex() { regex* re = regex_create("asd.", NULL); mu_assert("should match", regex_matches(re, "asdf", NULL)); mu_assert("should match again", regex_matches(re, "asdf", NULL)); mu_assert("should not", !regex_matches(re, "", NULL)); regex_destroy(re); return 1; }
int match(char* re_str, char* str) { re_error er; regex* re = regex_create(re_str, &er); //print_program(&(re->prog)); if(re == NULL) return 0; int m = regex_matches(re, str, NULL); regex_destroy(re); return m; }
int regex_check(const char *regex_string, const char *word) { int res = 0; // tRegex *regex = regex_new(regex_string); if(!regex) return 0; res = regex_check_re(regex, word); regex_destroy(regex); return res; }
int check_precompiled_regex(){ int i = 0; for (i = 0; i < 100000; ++i) { BSON_ASSERT(compare_rgx_good()); } for (i = 0; i < 100000; ++i) { BSON_ASSERT(compare_rgx_good_case_insensitive()); } regex_destroy(); }
int main() { //regex_log_func = printf; char *regex_string = "(a+";// "(http://)?(.)*,com(,br)?";//"ab(a)+(ab)*"; char *word = "ab";//"google,com,br,br";//"abaababab"; tRegex *regex = regex_new(regex_string); printf("regex: %s\n",regex_string); printf("word: %s\n",word); printf("base: %s\n",regex->base); printf("incond: %d\ncond_count: %d\n",regex->incond, regex->cond_count); int i; for(i=0;i<regex->cond_count;i++) { tCond *cond = regex->cond_list[i]; printf("cond #%d:\n",i); printf("\tsimbolos_count: %d\n",cond->simbolos_count); printf("\tsimbolos: %s\n",cond->simbolos); printf("\toperador: %c\n",cond->operador); printf("\tbase_index: %d\n",cond->base_index); } for(i=0;i<regex->cond_count;i++) printf("cond #%d start count: %d\n",i,regex->case_list[i]); char *try = regex_next_try(regex, strlen(word)); while(try) { printf("try: %s - res: ",try); printf("%s!\n", (regex_compare(try,word) ? "match!" : "doesn't match!" ) ); free(try); //exit(1); try = regex_next_try(regex, strlen(word)); } regex_destroy(regex); return 0; }