static int go_search_replace_compile (GOSearchReplace *sr) { const char *pattern; char *tmp; int flags = 0; int res; g_return_val_if_fail (sr && sr->search_text, GO_REG_EEND); kill_compiled (sr); if (sr->is_regexp) { pattern = sr->search_text; tmp = NULL; sr->plain_replace = (sr->replace_text && g_utf8_strchr (sr->replace_text, -1, '$') == NULL && g_utf8_strchr (sr->replace_text, -1, '\\') == NULL); } else { /* * Create a regular expression equivalent to the search * string. (Thus hoping the regular expression search * routines are pretty good.) */ GString *regexp = g_string_new (NULL); go_regexp_quote (regexp, sr->search_text); pattern = tmp = g_string_free (regexp, FALSE); sr->plain_replace = TRUE; } if (sr->ignore_case) flags |= GO_REG_ICASE; sr->comp_search = g_new0 (GORegexp, 1); res = go_regcomp (sr->comp_search, pattern, flags); g_free (tmp); return res; }
int gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags, gboolean full) { GString *res = g_string_new (NULL); int retval; if (full) g_string_append_c (res, '^'); while (*pattern) { switch (*pattern) { case '*': g_string_append (res, ".*"); pattern++; break; case '?': g_string_append_c (res, '.'); pattern++; break; case '~': if (pattern[1] == '*' || pattern[1] == '?' || pattern[1] == '~') pattern++; /* Fall through */ default: pattern = go_regexp_quote1 (res, pattern); } } if (full) g_string_append_c (res, '$'); retval = go_regcomp (preg, res->str, cflags); g_string_free (res, TRUE); return retval; }