Skip to content

Instantly share code, notes, and snippets.

@pocke
Last active April 28, 2018 12:33
Show Gist options
  • Save pocke/08d4081efb828c111a724bf1b92a1963 to your computer and use it in GitHub Desktop.
Save pocke/08d4081efb828c111a724bf1b92a1963 to your computer and use it in GitHub Desktop.
static VALUE
str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE arg)
{
/* (snip) */
/* normal case */
n = rb_str_cmp(beg, end);
if (n > 0 || (excl && n == 0)) return beg;
after_end = rb_funcallv(end, succ, 0, 0);
current = rb_str_dup(beg);
while (!rb_str_equal(current, after_end)) {
VALUE next = Qnil;
if (excl || !rb_str_equal(current, end))
next = rb_funcallv(current, succ, 0, 0);
if ((*each)(current, arg)) break;
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)
break;
}
return beg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment