mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
2000-03-08
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d215cd9d3
commit
035226e1fe
8 changed files with 111 additions and 27 deletions
66
regex.c
66
regex.c
|
@ -1067,7 +1067,7 @@ calculate_must_string(start, end)
|
|||
return must;
|
||||
}
|
||||
|
||||
static int
|
||||
static unsigned int
|
||||
read_backslash(c)
|
||||
int c;
|
||||
{
|
||||
|
@ -1099,6 +1099,47 @@ read_backslash(c)
|
|||
return c;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
read_special(p, pend, pp)
|
||||
const char *p, *pend, **pp;
|
||||
{
|
||||
int c;
|
||||
|
||||
PATFETCH_RAW(c);
|
||||
switch (c) {
|
||||
case 'M':
|
||||
PATFETCH_RAW(c);
|
||||
if (c != '-') return -1;
|
||||
PATFETCH_RAW(c);
|
||||
*pp = p;
|
||||
if (c == '\\') {
|
||||
return read_special(p, pend, pp) | 0x80;
|
||||
}
|
||||
else if (c == -1) return ~0;
|
||||
else {
|
||||
return ((c & 0xff) | 0x80);
|
||||
}
|
||||
|
||||
case 'C':
|
||||
PATFETCH_RAW(c);
|
||||
if (c != '-') return ~0;
|
||||
case 'c':
|
||||
PATFETCH_RAW(c);
|
||||
*pp = p;
|
||||
if (c == '\\') {
|
||||
c = read_special(p, pend, pp);
|
||||
}
|
||||
else if (c == '?') return 0177;
|
||||
else if (c == -1) return ~0;
|
||||
return c & 0x9f;
|
||||
default:
|
||||
return read_backslash(c);
|
||||
}
|
||||
|
||||
end_of_pattern:
|
||||
return ~0;
|
||||
}
|
||||
|
||||
/* re_compile_pattern takes a regular-expression string
|
||||
and converts it into a buffer full of byte commands for matching.
|
||||
|
||||
|
@ -1470,6 +1511,16 @@ re_compile_pattern(pattern, size, bufp)
|
|||
had_num_literal = 1;
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
case 'C':
|
||||
case 'c':
|
||||
p0 = --p;
|
||||
c = read_special(p, pend, &p0);
|
||||
if (c > 255) goto invalid_escape;
|
||||
p = p0;
|
||||
had_num_literal = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
c = read_backslash(c);
|
||||
if (ismbchar(c)) {
|
||||
|
@ -2173,6 +2224,16 @@ re_compile_pattern(pattern, size, bufp)
|
|||
BUFPUSH(c1);
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
case 'C':
|
||||
case 'c':
|
||||
p0 = --p;
|
||||
c = read_special(p, pend, &p0);
|
||||
if (c > 255) goto invalid_escape;
|
||||
p = p0;
|
||||
had_num_literal = 1;
|
||||
goto numeric_char;
|
||||
|
||||
default:
|
||||
c = read_backslash(c);
|
||||
goto normal_char;
|
||||
|
@ -2335,6 +2396,9 @@ re_compile_pattern(pattern, size, bufp)
|
|||
|
||||
nested_meta:
|
||||
FREE_AND_RETURN(stackb, "nested *?+ in regexp");
|
||||
|
||||
invalid_escape:
|
||||
FREE_AND_RETURN(stackb, "Invalid escape character syntax");
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue