summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-28 08:51:07 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-28 08:51:07 +0000
commit187a7b0b055722d923f07e82135512eb3d953ca6 (patch)
tree87866ba13fc8c20031a00fadfa749a1b9718cee5 /string.c
parent94e93023747354f12e97a899cd33fef154b9a387 (diff)
* range.c (range_step): Fix brokenness when a non-integer numeric
value is specified as step. [rubyspec] (range_step): Make use of String#step internally if a string (or string-alike) range is given. * string.c (rb_str_upto_m, Init_String): Add an optional second argument to specify if the last value should be included. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/string.c b/string.c
index c23f650496..7e26edb5b2 100644
--- a/string.c
+++ b/string.c
@@ -1492,12 +1492,13 @@ rb_str_upto(beg, end, excl)
/*
* call-seq:
- * str.upto(other_str) {|s| block } => str
+ * str.upto(other_str, exclusive=false) {|s| block } => str
*
* Iterates through successive values, starting at <i>str</i> and
* ending at <i>other_str</i> inclusive, passing each value in turn to
* the block. The <code>String#succ</code> method is used to generate
- * each value.
+ * each value. If optional second argument exclusive is omitted or is <code>false</code>,
+ * the last value will be included; otherwise it will be excluded.
*
* "a8".upto("b6") {|s| print s, ' ' }
* for s in "a8".."b6"
@@ -1511,10 +1512,15 @@ rb_str_upto(beg, end, excl)
*/
static VALUE
-rb_str_upto_m(beg, end)
- VALUE beg, end;
+rb_str_upto_m(argc, argv, beg)
+ int argc;
+ VALUE argv, beg;
{
- return rb_str_upto(beg, end, Qfalse);
+ VALUE end, exclusive;
+
+ rb_scan_args(argc, argv, "11", &end, &exclusive);
+
+ return rb_str_upto(beg, end, RTEST(exclusive));
}
static VALUE
@@ -4929,7 +4935,7 @@ Init_String()
rb_define_method(rb_cString, "succ!", rb_str_succ_bang, 0);
rb_define_method(rb_cString, "next", rb_str_succ, 0);
rb_define_method(rb_cString, "next!", rb_str_succ_bang, 0);
- rb_define_method(rb_cString, "upto", rb_str_upto_m, 1);
+ rb_define_method(rb_cString, "upto", rb_str_upto_m, -1);
rb_define_method(rb_cString, "index", rb_str_index_m, -1);
rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1);
rb_define_method(rb_cString, "replace", rb_str_replace, 1);