From 703a5dd3e0effdc808b9b59af21e5012f3d91942 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 28 Apr 2018 11:16:54 +0000 Subject: string.c: adjust to rb_str_upto_each * range.c (range_each_func): adjust the signature of the callback function to rb_str_upto_each, and exit the loop if the callback returned non-zero. * string.c (rb_str_upto_endless_each): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index f989466d32..c48f63be16 100644 --- a/string.c +++ b/string.c @@ -4192,8 +4192,6 @@ all_digits_p(const char *s, long len) return 1; } -static VALUE str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE); - static int str_upto_i(VALUE str, VALUE arg) { @@ -4240,11 +4238,11 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg) rb_scan_args(argc, argv, "11", &end, &exclusive); RETURN_ENUMERATOR(beg, argc, argv); - return str_upto_each(beg, end, RTEST(exclusive), str_upto_i, Qnil); + return rb_str_upto_each(beg, end, RTEST(exclusive), str_upto_i, Qnil); } -static VALUE -str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE arg) +VALUE +rb_str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE arg) { VALUE current, after_end; ID succ; @@ -4326,7 +4324,7 @@ str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE a } VALUE -rb_str_upto_endless_each(VALUE beg, VALUE (*each)(VALUE, VALUE), VALUE arg) +rb_str_upto_endless_each(VALUE beg, int (*each)(VALUE, VALUE), VALUE arg) { VALUE current; ID succ; @@ -4343,7 +4341,7 @@ rb_str_upto_endless_each(VALUE beg, VALUE (*each)(VALUE, VALUE), VALUE arg) rb_encoding *usascii = rb_usascii_encoding(); while (FIXABLE(bi)) { - (*each)(rb_enc_sprintf(usascii, "%.*ld", width, bi), arg); + if ((*each)(rb_enc_sprintf(usascii, "%.*ld", width, bi), arg)) break; bi++; } b = LONG2NUM(bi); @@ -4351,7 +4349,7 @@ rb_str_upto_endless_each(VALUE beg, VALUE (*each)(VALUE, VALUE), VALUE arg) args[0] = INT2FIX(width); while (1) { args[1] = b; - (*each)(rb_str_format(numberof(args), args, fmt), arg); + if ((*each)(rb_str_format(numberof(args), args, fmt), arg)) break; b = rb_funcallv(b, succ, 0, 0); } } @@ -4359,7 +4357,7 @@ rb_str_upto_endless_each(VALUE beg, VALUE (*each)(VALUE, VALUE), VALUE arg) current = rb_str_dup(beg); while (1) { VALUE next = rb_funcallv(current, succ, 0, 0); - (*each)(current, arg); + if ((*each)(current, arg)) break; current = next; StringValue(current); if (RSTRING_LEN(current) == 0) @@ -4417,7 +4415,7 @@ rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive) } #endif } - str_upto_each(beg, end, RTEST(exclusive), include_range_i, (VALUE)&val); + rb_str_upto_each(beg, end, RTEST(exclusive), include_range_i, (VALUE)&val); return NIL_P(val) ? Qtrue : Qfalse; } -- cgit v1.2.3