static int testmaildirsearch(const char *chset, const char *needle, const char *haystack) { struct maildir_searchengine se; unicode_char *ucptr; size_t ucsize; size_t i; libmail_u_convert_handle_t h=libmail_u_convert_tou_init(chset, &ucptr, &ucsize, 1); if (h == NULL) { perror("libmail_u_convert_tou_init"); return 1; } if (libmail_u_convert(h, haystack, strlen(haystack))) { libmail_u_convert_deinit(h, NULL); perror("libmail_u_convert_tou"); return 1; } if (libmail_u_convert_deinit(h, NULL)) { perror("libmail_u_convert_deinit"); return 1; } maildir_search_init(&se); if (maildir_search_start_str_chset(&se, needle, chset)) { perror("maildir_search_start_str_chset"); maildir_search_destroy(&se); free(ucptr); return 1; } maildir_search_reset(&se); for (i=0; ucptr[i]; ++i) { maildir_search_step_unicode_lc(&se, ucptr[i]); if (maildir_search_found(&se)) { free(ucptr); maildir_search_destroy(&se); return 0; } } free(ucptr); maildir_search_destroy(&se); return 2; }
int maildir_search_start_unicode(struct maildir_searchengine *sei, const unicode_char *s) { unsigned i, j, *r; size_t n; for (n=0; s[n]; ++n) ; ++n; if (sei->string) free(sei->string); sei->string=malloc(n * sizeof(*s)); if (!sei->string) return (-1); sei->string_l=n-1; memcpy(sei->string, s, n * sizeof(*s)); if (sei->r) free(sei->r); sei->i=0; if ((sei->r=r=(unsigned *)malloc(sizeof(unsigned)*n)) == 0) return (-1); for (i=0; s[i]; i++) r[i]=0; for (i=0; s[i]; i++) for (j=0; s[i+j]; j++) if (s[j] != s[i+j]) { if (r[i+j] < j) r[i+j]=j; break; } maildir_search_reset(sei); return (0); }