From 035226e1fe71085c7c9c84dacd14448870fca9da Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 8 Mar 2000 06:25:19 +0000 Subject: 2000-03-08 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- regex.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index 60e23e038d..ac8ea0eea3 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 -- cgit v1.2.3