Skip to content

Commit 075f1bb

Browse files
k0kubunjacob-shops
authored andcommitted
[ruby/strscan] Resurrect a method that has not been obsolete
(ruby/strscan#169) Partially revert ruby/strscan#168 because strscan_rest_p did not have `rb_warning("StringScanner#rest? is obsolete")`. It is actively used by the latest tzinfo.gem, and we shouldn't remove it without deprecating it. ruby/strscan@f3fdf21189
1 parent afaa971 commit 075f1bb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ext/strscan/strscan.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static VALUE strscan_scan_base10_integer _((VALUE self));
122122
static VALUE strscan_unscan _((VALUE self));
123123
static VALUE strscan_bol_p _((VALUE self));
124124
static VALUE strscan_eos_p _((VALUE self));
125+
static VALUE strscan_rest_p _((VALUE self));
125126
static VALUE strscan_matched_p _((VALUE self));
126127
static VALUE strscan_matched _((VALUE self));
127128
static VALUE strscan_matched_size _((VALUE self));
@@ -1471,6 +1472,29 @@ strscan_eos_p(VALUE self)
14711472
return EOS_P(p) ? Qtrue : Qfalse;
14721473
}
14731474

1475+
/*
1476+
* call-seq:
1477+
* rest?
1478+
*
1479+
* Returns true if and only if there is more data in the string. See #eos?.
1480+
* This method is obsolete; use #eos? instead.
1481+
*
1482+
* s = StringScanner.new('test string')
1483+
* # These two are opposites
1484+
* s.eos? # => false
1485+
* s.rest? # => true
1486+
*/
1487+
1488+
/* :nodoc: */
1489+
static VALUE
1490+
strscan_rest_p(VALUE self)
1491+
{
1492+
struct strscanner *p;
1493+
1494+
GET_SCANNER(self, p);
1495+
return EOS_P(p) ? Qfalse : Qtrue;
1496+
}
1497+
14741498
/*
14751499
* :markup: markdown
14761500
* :include: strscan/link_refs.txt
@@ -2237,6 +2261,7 @@ Init_strscan(void)
22372261
rb_define_method(StringScanner, "beginning_of_line?", strscan_bol_p, 0);
22382262
rb_alias(StringScanner, rb_intern("bol?"), rb_intern("beginning_of_line?"));
22392263
rb_define_method(StringScanner, "eos?", strscan_eos_p, 0);
2264+
rb_define_method(StringScanner, "rest?", strscan_rest_p, 0);
22402265

22412266
rb_define_method(StringScanner, "matched?", strscan_matched_p, 0);
22422267
rb_define_method(StringScanner, "matched", strscan_matched, 0);

0 commit comments

Comments
 (0)