Use rb_reg_nth_defined
instead of rb_match_nth_defined
This commit is contained in:
parent
eaad44adb2
commit
df5ae0a550
Notes:
git
2023-06-27 15:27:56 +00:00
@ -87,11 +87,6 @@ void rb_match_busy(VALUE md);
|
||||
* @retval RUBY_Qfalse There is a `n`-th capture and is empty.
|
||||
* @retval RUBY_Qtrue There is a `n`-th capture that has something.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @shyouhei wonders: why there are both rb_reg_match_defined() and
|
||||
* rb_match_nth_defined, which are largely the same things, but do not share
|
||||
* their implementations at all?
|
||||
*/
|
||||
VALUE rb_reg_nth_defined(int n, VALUE md);
|
||||
|
||||
|
@ -22,7 +22,6 @@ VALUE rb_reg_equal(VALUE re1, VALUE re2);
|
||||
void rb_backref_set_string(VALUE string, long pos, long len);
|
||||
void rb_match_unbusy(VALUE);
|
||||
int rb_match_count(VALUE match);
|
||||
int rb_match_nth_defined(int nth, VALUE match);
|
||||
VALUE rb_reg_new_ary(VALUE ary, int options);
|
||||
|
||||
#endif /* INTERNAL_RE_H */
|
||||
|
17
re.c
17
re.c
@ -1450,23 +1450,6 @@ rb_match_count(VALUE match)
|
||||
return regs->num_regs;
|
||||
}
|
||||
|
||||
int
|
||||
rb_match_nth_defined(int nth, VALUE match)
|
||||
{
|
||||
struct re_registers *regs;
|
||||
if (NIL_P(match)) return FALSE;
|
||||
regs = RMATCH_REGS(match);
|
||||
if (!regs) return FALSE;
|
||||
if (nth >= regs->num_regs) {
|
||||
return FALSE;
|
||||
}
|
||||
if (nth < 0) {
|
||||
nth += regs->num_regs;
|
||||
if (nth <= 0) return FALSE;
|
||||
}
|
||||
return (BEG(nth) != -1);
|
||||
}
|
||||
|
||||
static void
|
||||
match_set_string(VALUE m, VALUE string, long pos, long len)
|
||||
{
|
||||
|
@ -902,7 +902,7 @@ rb_f_global_variables(void)
|
||||
int i, nmatch = rb_match_count(backref);
|
||||
buf[0] = '$';
|
||||
for (i = 1; i <= nmatch; ++i) {
|
||||
if (!rb_match_nth_defined(i, backref)) continue;
|
||||
if (!RTEST(rb_reg_nth_defined(i, backref))) continue;
|
||||
if (i < 10) {
|
||||
/* probably reused, make static ID */
|
||||
buf[1] = (char)(i + '0');
|
||||
|
Loading…
x
Reference in New Issue
Block a user