mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_upto): make next object before yield its block.
fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2c2fb9c5ec
commit
a1fc9cd582
3 changed files with 23 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Nov 4 00:05:36 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_upto): make next object before yield its block.
|
||||||
|
fix: can modify original begin string of String#upto.
|
||||||
|
[ruby-dev:26384] [ruby-dev:39626]
|
||||||
|
|
||||||
Mon Nov 2 18:33:21 2009 wanabe <s.wanabe@gmail.com>
|
Mon Nov 2 18:33:21 2009 wanabe <s.wanabe@gmail.com>
|
||||||
|
|
||||||
* cont.c (fiber_free): don't free unallocated local_storage. see #1325.
|
* cont.c (fiber_free): don't free unallocated local_storage. see #1325.
|
||||||
|
|
9
string.c
9
string.c
|
@ -2952,11 +2952,14 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg)
|
||||||
if (n > 0 || (excl && n == 0)) return beg;
|
if (n > 0 || (excl && n == 0)) return beg;
|
||||||
|
|
||||||
after_end = rb_funcall(end, succ, 0, 0);
|
after_end = rb_funcall(end, succ, 0, 0);
|
||||||
current = beg;
|
current = rb_str_dup(beg);
|
||||||
while (!rb_str_equal(current, after_end)) {
|
while (!rb_str_equal(current, after_end)) {
|
||||||
|
VALUE next = Qnil;
|
||||||
|
if (excl || !rb_str_equal(current, end))
|
||||||
|
next = rb_funcall(current, succ, 0, 0);
|
||||||
rb_yield(current);
|
rb_yield(current);
|
||||||
if (!excl && rb_str_equal(current, end)) break;
|
if (NIL_P(next)) break;
|
||||||
current = rb_funcall(current, succ, 0, 0);
|
current = next;
|
||||||
StringValue(current);
|
StringValue(current);
|
||||||
if (excl && rb_str_equal(current, end)) break;
|
if (excl && rb_str_equal(current, end)) break;
|
||||||
if (RSTRING_LEN(current) > RSTRING_LEN(end) || RSTRING_LEN(current) == 0)
|
if (RSTRING_LEN(current) > RSTRING_LEN(end) || RSTRING_LEN(current) == 0)
|
||||||
|
|
|
@ -1602,6 +1602,17 @@ class TestString < Test::Unit::TestCase
|
||||||
assert_equal(24, count, "[ruby-dev:39361]")
|
assert_equal(24, count, "[ruby-dev:39361]")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_upto_nonalnum
|
||||||
|
first = S("\u3041")
|
||||||
|
last = S("\u3093")
|
||||||
|
count = 0
|
||||||
|
assert_equal(first, first.upto(last) {|s|
|
||||||
|
count += 1
|
||||||
|
s.replace(last)
|
||||||
|
})
|
||||||
|
assert_equal(83, count, "[ruby-dev:39626]")
|
||||||
|
end
|
||||||
|
|
||||||
def test_mod_check
|
def test_mod_check
|
||||||
assert_raise(RuntimeError) {
|
assert_raise(RuntimeError) {
|
||||||
s = ""
|
s = ""
|
||||||
|
|
Loading…
Add table
Reference in a new issue