diff options
| author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-03 15:16:55 +0000 |
|---|---|---|
| committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-03 15:16:55 +0000 |
| commit | 683ad14e2c1bdd5b5ecec8437d67449558d97a99 (patch) | |
| tree | 3b44257bdccbbdbb379406c5e2f7ab300b809428 /string.c | |
| parent | 3d2de45d264b0b82c4ba72ce54600361e38aaba5 (diff) | |
| download | ruby-683ad14e2c1bdd5b5ecec8437d67449558d97a99.tar.gz ruby-683ad14e2c1bdd5b5ecec8437d67449558d97a99.tar.xz ruby-683ad14e2c1bdd5b5ecec8437d67449558d97a99.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@25632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -2952,11 +2952,14 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg) if (n > 0 || (excl && n == 0)) return beg; after_end = rb_funcall(end, succ, 0, 0); - current = beg; + current = rb_str_dup(beg); 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); - if (!excl && rb_str_equal(current, end)) break; - current = rb_funcall(current, succ, 0, 0); + if (NIL_P(next)) break; + current = next; StringValue(current); if (excl && rb_str_equal(current, end)) break; if (RSTRING_LEN(current) > RSTRING_LEN(end) || RSTRING_LEN(current) == 0) |
