[w3m-dev 03464] Re: case insensitive regexp search

(rewrite [w3m-dev 03462] by Hiroyuki Ito <hito@crl.go.jp>)
* regex.c (matchWhich): add int
	(newRegex0): igncase
	(regmatch1): matchWhich with re->mode & RE_IGNCASE
	(matchWhich): add igncase
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2002-11-22 15:56:43 +00:00
parent cdc65fdf22
commit bd44683efa
2 changed files with 28 additions and 6 deletions

View File

@@ -1,3 +1,12 @@
2002-11-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03464] Re: case insensitive regexp search
(rewrite [w3m-dev 03462] by Hiroyuki Ito <hito@crl.go.jp>)
* regex.c (matchWhich): add int
(newRegex0): igncase
(regmatch1): matchWhich with re->mode & RE_IGNCASE
(matchWhich): add igncase
2002-11-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> 2002-11-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03459] background download when external viewer * [w3m-dev 03459] background download when external viewer
@@ -5040,4 +5049,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1 * release-0-2-1
* import w3m-0.2.1 * import w3m-0.2.1
$Id: ChangeLog,v 1.548 2002/11/22 15:49:42 ukai Exp $ $Id: ChangeLog,v 1.549 2002/11/22 15:56:43 ukai Exp $

23
regex.c
View File

@@ -1,4 +1,4 @@
/* $Id: regex.c,v 1.16 2002/01/21 17:57:28 ukai Exp $ */ /* $Id: regex.c,v 1.17 2002/11/22 15:56:43 ukai Exp $ */
/* /*
* regex: Regular expression pattern match library * regex: Regular expression pattern match library
* *
@@ -68,7 +68,7 @@ static Regex DefaultRegex;
static int regmatch(regexchar *, char *, char *, int, char **); static int regmatch(regexchar *, char *, char *, int, char **);
static int regmatch1(regexchar *, longchar); static int regmatch1(regexchar *, longchar);
static int matchWhich(longchar *, longchar); static int matchWhich(longchar *, longchar, int);
/* /*
* regexCompile: compile regular expression * regexCompile: compile regular expression
@@ -190,6 +190,8 @@ newRegex0(char **ex, int igncase, Regex *regex, char **msg, int level)
*(st_ptr++) = '\0'; *(st_ptr++) = '\0';
re->p.pattern = r; re->p.pattern = r;
RE_SET_MODE(re, m); RE_SET_MODE(re, m);
if (igncase)
re->mode |= RE_IGNCASE;
re++; re++;
break; break;
case '|': case '|':
@@ -634,15 +636,15 @@ regmatch1(regexchar * re, longchar c)
else else
return (*re->p.pattern == c); return (*re->p.pattern == c);
case RE_WHICH: case RE_WHICH:
return matchWhich(re->p.pattern, c); return matchWhich(re->p.pattern, c, re->mode & RE_IGNCASE);
case RE_EXCEPT: case RE_EXCEPT:
return !matchWhich(re->p.pattern, c); return !matchWhich(re->p.pattern, c, re->mode & RE_IGNCASE);
} }
return 0; return 0;
} }
static int static int
matchWhich(longchar * pattern, longchar c) matchWhich(longchar * pattern, longchar c, int igncase)
{ {
longchar *p = pattern; longchar *p = pattern;
int ans = 0; int ans = 0;
@@ -657,6 +659,12 @@ matchWhich(longchar * pattern, longchar c)
ans = 1; ans = 1;
break; break;
} }
else if (igncase && c < 127 && IS_ALPHA(c) &&
((*p <= c && tolower(c) <= *(p + 2)) ||
(*p <= c && toupper(c) <= *(p + 2)))) {
ans = 1;
break;
}
p += 3; p += 3;
} }
else { else {
@@ -664,6 +672,11 @@ matchWhich(longchar * pattern, longchar c)
ans = 1; ans = 1;
break; break;
} }
else if (igncase && c < 127 && IS_ALPHA(c) &&
(*p == tolower(c) || *p == toupper(c))) {
ans = 1;
break;
}
p++; p++;
} }
} }