Last active
April 28, 2018 12:33
-
-
Save pocke/08d4081efb828c111a724bf1b92a1963 to your computer and use it in GitHub Desktop.
For ("\0".."π").to_a https://github.com/ruby/ruby/blob/f114089585d486920f53c0c4cb92d73dc4ed577c/string.c#L4246-L4326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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