diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-11-09 09:11:52 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-11-09 09:11:52 +0000 |
commit | ee5ab9cc136baf18756abc6bd5d136a0231f973e (patch) | |
tree | abdc351cbffd7b67f63f41ea08f544819af0a28b /string.c | |
parent | dc8da69e7cbc54f020ef1182fd28e57bbaa40fc3 (diff) |
1.1c7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -802,8 +802,8 @@ str_aref(str, indx) return INT2FIX(RSTRING(str)->ptr[idx] & 0xff); case T_REGEXP: - if (str_match(str, indx)) - return reg_last_match(0); + if (reg_match(indx, str)) + return reg_last_match(backref_get()); return Qnil; case T_STRING: @@ -1551,7 +1551,7 @@ str_dump(str) } else { *q++ = '\\'; - sprintf(q, "%03o", c); + sprintf(q, "%03o", c&0xff); q += 3; } } @@ -2011,12 +2011,12 @@ str_split_method(argc, argv, str) VALUE spat; VALUE limit; int char_sep = -1; - int beg, end, lim, i; + int beg, end, i, lim = 0; VALUE result, tmp; if (rb_scan_args(argc, argv, "02", &spat, &limit) == 2) { lim = NUM2INT(limit); - if (lim == 0) limit = Qnil; + if (lim <= 0) limit = Qnil; else if (lim == 1) return ary_new3(1, str); i = 1; } @@ -2119,8 +2119,9 @@ str_split_method(argc, argv, str) last_null = 0; for (idx=1; idx < regs->num_regs; idx++) { - if (BEG(idx) == -1) continue; - if (BEG(idx) == END(idx)) + if (BEG(idx) == -1) + tmp = Qnil; + else if (BEG(idx) == END(idx)) tmp = str_new(0, 0); else tmp = str_subseq(str, BEG(idx), END(idx)-1); @@ -2129,9 +2130,14 @@ str_split_method(argc, argv, str) if (!NIL_P(limit) && lim <= ++i) break; } } - if (RSTRING(str)->len > beg) { + if (!NIL_P(limit) || RSTRING(str)->len > beg || lim < 0) { ary_push(result, str_subseq(str, beg, -1)); } + if (NIL_P(limit) && lim == 0) { + while (RARRAY(result)->len > 0 && + RSTRING(RARRAY(result)->ptr[RARRAY(result)->len-1])->len == 0) + ary_pop(result); + } return result; } |