Module: MatchAt

Defined in:
lib/match_at.rb,
ext/match_at/match_at.c

Overview

This library is a Refinements. By use-ing it your namespace has String#match_at.

Constant Summary collapse

VERSION =
1

Class Method Summary collapse

Class Method Details

.match_at(str, rexp, pos) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/match_at/match_at.c', line 38

VALUE
match_at(VALUE mod, VALUE str, VALUE rexp, VALUE pos)
{
    OnigRegion region = { 0 };
    VALUE ret         = Qnil;

    if (do_match(str, rexp, pos, &region)) {
        int err;
        ret = rb_funcall(rb_cMatch, rb_intern("allocate"), 0);
        err = rb_reg_region_copy(RMATCH_REGS(ret), &region);
        if (err) {
            rb_memerror();
        }
        else {
            RMATCH(ret)->regexp = rexp;
            RMATCH(ret)->str    = rb_str_new_frozen(str); /* copy */
            OBJ_INFECT(ret, rexp);
            OBJ_INFECT(ret, str);
            /* no backref introduced, OK write barrier. */
        }
    }
    onig_region_free(&region, 0);
    return ret;
}

.match_at?(str, rexp, pos) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'ext/match_at/match_at.c', line 32

VALUE
match_at_p(VALUE mod, VALUE str, VALUE rexp, VALUE pos)
{
    return do_match(str, rexp, pos, NULL) ? Qtrue : Qfalse;
}