mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
String#lines with a block is deprecated style.
This commit is contained in:
@@ -320,36 +320,16 @@ static mrb_value
|
||||
mrb_str_lines(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value result;
|
||||
mrb_value blk;
|
||||
int ai;
|
||||
mrb_int len;
|
||||
mrb_value arg;
|
||||
char *b = RSTRING_PTR(self);
|
||||
char *p = b, *t;
|
||||
char *e = b + RSTRING_LEN(self);
|
||||
|
||||
mrb_get_args(mrb, "&", &blk);
|
||||
mrb_get_args(mrb, "");
|
||||
|
||||
result = mrb_ary_new(mrb);
|
||||
ai = mrb_gc_arena_save(mrb);
|
||||
if (!mrb_nil_p(blk)) {
|
||||
while (p < e) {
|
||||
t = p;
|
||||
while (p < e && *p != '\n') p++;
|
||||
if (*p == '\n') p++;
|
||||
len = (mrb_int) (p - t);
|
||||
arg = mrb_str_new(mrb, t, len);
|
||||
mrb_yield_argv(mrb, blk, 1, &arg);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
if (b != RSTRING_PTR(self)) {
|
||||
ptrdiff_t diff = p - b;
|
||||
b = RSTRING_PTR(self);
|
||||
p = b + diff;
|
||||
}
|
||||
e = b + RSTRING_LEN(self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
while (p < e) {
|
||||
t = p;
|
||||
while (p < e && *p != '\n') p++;
|
||||
|
||||
Reference in New Issue
Block a user