diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:41:50 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-01 09:41:50 +0000 |
commit | 4fa0cdea7838a12afac492ee58af7f30660c6a8f (patch) | |
tree | 30895168554835060498505a41c9f5e72c4cddea /re.c | |
parent | ca55fe4f0d1477f9b2b14793468c370ebbb96ea7 (diff) |
* numeric.c (num_step): better iteration condition for float
values; suggested by Masahiro TANAKA <masa@ir.isas.ac.jp>.
* range.c (range_step): step (for Range#step method) <= 0 makes no
sence, thus ArgError will be raised.
* range.c (range_each): Range#each method is special case for
Range#step(1)
* file.c (rb_find_file): load must be done from an abolute path if
$SAFE >= 4.
* enum.c (enum_partition): new method. [new]
* re.c (rb_reg_s_quote): quote whitespaces for /x cases.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -861,7 +861,8 @@ match_to_a(match) for (i=0; i<regs->num_regs; i++) { if (regs->beg[i] == -1) { rb_ary_push(ary, Qnil); - } else { + } + else { VALUE str = rb_str_new(ptr+regs->beg[i], regs->end[i]-regs->beg[i]); if (taint) OBJ_TAINT(str); rb_ary_push(ary, str); @@ -1170,6 +1171,7 @@ rb_reg_s_quote(argc, argv) int kcode_saved = reg_kcode; char *s, *send, *t; VALUE tmp; + int c; rb_scan_args(argc, argv, "11", &str, &kcode); if (!NIL_P(kcode)) { @@ -1184,24 +1186,41 @@ rb_reg_s_quote(argc, argv) t = RSTRING(tmp)->ptr; for (; s < send; s++) { - if (ismbchar(*s)) { - int n = mbclen(*s); + c = *s; + if (ismbchar(c)) { + int n = mbclen(c); while (n-- && s < send) *t++ = *s++; s--; continue; } - if (*s == '[' || *s == ']' - || *s == '{' || *s == '}' - || *s == '(' || *s == ')' - || *s == '|' || *s == '-' - || *s == '*' || *s == '.' || *s == '\\' - || *s == '?' || *s == '+' - || *s == '^' || *s == '$') { + switch (c) { + case '\t': + c = 't'; *t++ = '\\'; + break; + case '\f': + c = 'f'; + *t++ = '\\'; + break; + case '\r': + c = 'r'; + *t++ = '\\'; + break; + case '\n': + c = 'n'; + *t++ = '\\'; + break; + case '[': case ']': case '{': case '}': + case '(': case ')': case '|': case '-': + case '*': case '.': case '\\': + case '?': case '+': case '^': case '$': + case ' ': + *t++ = '\\'; + break; } - *t++ = *s; + *t++ = c; } kcode_reset_option(); rb_str_resize(tmp, t - RSTRING(tmp)->ptr); |