Пример #1
0
PRIMITIVE VALUE
vm_get_special(char code)
{
    VALUE backref = rb_backref_get();
    if (backref == Qnil) {
	return Qnil;
    }

    VALUE val;
    switch (code) {
	case '&':
	    val = rb_reg_last_match(backref);
	    break;
	case '`':
	    val = rb_reg_match_pre(backref);
	    break;
	case '\'':
	    val = rb_reg_match_post(backref);
	    break;
	case '+':
	    val = rb_reg_match_last(backref);
	    break;
	default:
	    // Boundaries check is done in rb_reg_nth_match().
	    val = rb_reg_nth_match((int)code, backref);
	    break;
    }
    return val;
}
Пример #2
0
static inline VALUE
vm_getspecial(rb_thread_t *th, VALUE *lfp, rb_num_t key, rb_num_t type)
{
    VALUE val;

    if (type == 0) {
	val = lfp_svar_get(th, lfp, key);
    }
    else {
	VALUE backref = lfp_svar_get(th, lfp, 1);

	if (type & 0x01) {
	    switch (type >> 1) {
	      case '&':
		val = rb_reg_last_match(backref);
		break;
	      case '`':
		val = rb_reg_match_pre(backref);
		break;
	      case '\'':
		val = rb_reg_match_post(backref);
		break;
	      case '+':
		val = rb_reg_match_last(backref);
		break;
	      default:
		rb_bug("unexpected back-ref");
	    }
	}
	else {
	    val = rb_reg_nth_match((int)(type >> 1), backref);
	}
    }