summaryrefslogtreecommitdiff
path: root/regex.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-03-08 06:25:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-03-08 06:25:19 +0000
commit035226e1fe71085c7c9c84dacd14448870fca9da (patch)
tree5e20e8c2bdc5ed8f899ec55446e81f040a522ead /regex.c
parent4d215cd9d3e0c4ea8ba802aa87773d6578c45a15 (diff)
2000-03-08
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/regex.c b/regex.c
index 60e23e0..ac8ea0e 100644
--- a/regex.c
+++ b/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