string_match.c (1778B)
1 /* 2 * Claws Mail -- regexp pattern matching utilities 3 * Copyright (C) 2001 Thomas Link, Hiroyuki Yamamoto 4 * Modified by Melvin Hadasht. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * 19 */ 20 21 #include <glib.h> 22 #ifdef ENABLE_NLS 23 #include <glib/gi18n.h> 24 #else 25 #define _(a) (a) 26 #define N_(a) (a) 27 #endif 28 #include <string.h> 29 30 #include "string_match.h" 31 #include "utils.h" 32 33 gchar *string_remove_match(gchar *buf, gint buflen, gchar * txt, regex_t *preg) 34 { 35 regmatch_t match; 36 int notfound; 37 gint i, j ,k; 38 39 if (!preg) 40 return txt; 41 if (*txt != 0x00) { 42 i = 0; 43 j = 0; 44 do { 45 notfound = regexec(preg, txt+j, 1, &match, (j ? REG_NOTBOL : 0)); 46 if (notfound) { 47 while (txt[j] && i < buflen -1) 48 buf[i++] = txt[j++]; 49 } else { 50 if ( match.rm_so == match.rm_eo) 51 buf[i++] = txt[j++]; 52 else { 53 k = j; 54 while (txt[j] && j != k + match.rm_so) 55 buf[i++] = txt[j++]; 56 if (txt[j]) 57 j = k + match.rm_eo; 58 } 59 } 60 } while (txt[j] && i < buflen - 1); 61 buf[i] = 0x00; 62 if (buf[0] == 0x00) { 63 strncpy(buf, _("(Subject cleared by RegExp)"), 64 buflen - 1); 65 buf[buflen - 1] = 0x00; 66 } 67 return buf; 68 } 69 return txt; 70 } 71