summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
commite3a8c626308cb8546baaf75e6133df304142f0c8 (patch)
tree4fb40e7eab065c70d5b2cdb44eb16bea01b12c15 /re.c
parentb596fbbc375ea58aa2b869cb6025b2bb101f96b9 (diff)
* io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
* io.c (rb_io_mode_modenum): ditto. * gc.c (rb_memerror): rename from mem_error, and exported. * gc.c (Init_GC): pre-allocate NoMemoryError instance. * object.c (convert_type): error message changed from "failed to convert" to "cannot convert", since it does not try to convert if an object does not respond to the converting method. * eval.c (block_pass): convert Method to Proc using rb_check_convert_type(). * object.c (rb_check_convert_type): always convert T_DATA * eval.c (rb_thread_cleanup): should not terminate main_thread by Fatal error. * regex.c (is_in_list): need to not exclude NUL and NEWLINE. * re.c (rb_reg_expr_str): wrong backslash escapement. * re.c (rb_reg_expr_str): do not escape embedded space characters. * marshal.c (w_object): T_DATA process patch from Joel VanderWerf <vjoel@PATH.Berkeley.EDU>. This is temporary hack; it remains undocumented, and it will be removed when marshaling is re-designed. * marshal.c (r_object): ditto. * numeric.c (num_step): Integer#step is moved to Numeric#step; Fixnum#step is merged into this method. * numeric.c (int_dotimes): Fixnum#times is merged. * numeric.c (int_upto): Fixnum#upto is merged. * numeric.c (int_downto): Fixnum#downto is merged. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c66
1 files changed, 22 insertions, 44 deletions
diff --git a/re.c b/re.c
index fa048cb210..c3da5f1015 100644
--- a/re.c
+++ b/re.c
@@ -90,8 +90,6 @@ rb_memcmp(p1, p2, len)
char *p1, *p2;
long len;
{
- int tmp;
-
if (!ruby_ignorecase) {
return memcmp(p1, p2, len);
}
@@ -230,7 +228,7 @@ rb_reg_expr_str(str, s, len)
need_escape = 1;
break;
}
- p++;
+ p += mbclen(*p);
}
if (!need_escape) {
rb_str_buf_cat(str, s, len);
@@ -238,13 +236,7 @@ rb_reg_expr_str(str, s, len)
else {
p = s;
while (p<pend) {
- if (*p == '\\') {
- rb_str_buf_cat(str, p++, 1);
- if (p<pend) {
- rb_str_buf_cat(str, p, 1);
- }
- }
- else if (*p == '/') {
+ if (*p == '/' && (s == p || p[-1] != '\\')) {
char c = '\\';
rb_str_buf_cat(str, &c, 1);
rb_str_buf_cat(str, p, 1);
@@ -257,35 +249,14 @@ rb_reg_expr_str(str, s, len)
else if (ISPRINT(*p)) {
rb_str_buf_cat(str, p, 1);
}
- else {
+ else if (!ISSPACE(*p)) {
char b[8];
- switch (*p) {
- case '\r':
- rb_str_buf_cat(str, "\\r", 2);
- break;
- case '\n':
- rb_str_buf_cat(str, "\\n", 2);
- break;
- case '\t':
- rb_str_buf_cat(str, "\\t", 2);
- break;
- case '\f':
- rb_str_buf_cat(str, "\\f", 2);
- break;
- case 007:
- rb_str_buf_cat(str, "\\a", 2);
- break;
- case 013:
- rb_str_buf_cat(str, "\\v", 2);
- break;
- case 033:
- rb_str_buf_cat(str, "\\e", 2);
- break;
- default:
- sprintf(b, "\\%03o", *p & 0377);
- rb_str_buf_cat(str, b, 4);
- break;
- }
+
+ sprintf(b, "\\%03o", *p & 0377);
+ rb_str_buf_cat(str, b, 4);
+ }
+ else {
+ rb_str_buf_cat(str, p, 1);
}
p++;
}
@@ -367,10 +338,11 @@ rb_reg_to_s(re)
options = RREGEXP(re)->ptr->options;
ptr = RREGEXP(re)->str;
len = RREGEXP(re)->len;
- if (len >= 4 && ptr[0] == '(' && ptr[1] == '?' && ptr[len-1] == ')') {
+ again:
+ if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
int err = 1;
ptr += 2;
- if ((len -= 3) > 0) {
+ if ((len -= 2) > 0) {
do {
if (*ptr == 'm') {
options |= RE_OPTION_MULTILINE;
@@ -402,11 +374,17 @@ rb_reg_to_s(re)
++ptr;
} while (--len > 0);
}
- if (*ptr == ':') {
- Regexp *rp = ALLOC(Regexp);
- MEMZERO((char *)rp, Regexp, 1);
+ if (*ptr == ')') {
+ --len;
+ ++ptr;
+ goto again;
+ }
+ if (*ptr == ':' && ptr[len-1] == ')') {
+ Regexp *rp;
kcode_set_option(re);
- err = re_compile_pattern(++ptr, --len, rp) != 0;
+ rp = ALLOC(Regexp);
+ MEMZERO((char *)rp, Regexp, 1);
+ err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
kcode_reset_option();
re_free_pattern(rp);
}