Beispiel #1
0
 static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
   MatchData* md = state->new_object<MatchData>(G(matchdata));
   md->source(state, string->string_dup(state));
   md->regexp(state, regexp);
   Tuple* tup = Tuple::from(state, 2,
                            Fixnum::from(region->beg[0] + pos),
                            Fixnum::from(region->end[0] + pos));
   md->full(state, tup);
   md->region(state, _md_region_to_tuple(state, region, pos));
   return md;
 }
Beispiel #2
0
  static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
    MatchData* md = state->new_object<MatchData>(G(matchdata));
    md->source(state, string->string_dup(state));
    md->regexp(state, regexp);
    // Unsure if the first region (the full match) can be less than 0 (meaning
    // the match was length length but did still match). We have to support
    // that for the > 0 case, so we'll do the same for 0.
    //

    if(region->beg[0] < 0) {
      Tuple* tup = Tuple::from(state, 2,
                               Fixnum::from(region->beg[0]),
                               Fixnum::from(region->end[0]));
      md->full(state, tup);
    } else {
      Tuple* tup = Tuple::from(state, 2,
                               Fixnum::from(region->beg[0] + pos),
                               Fixnum::from(region->end[0] + pos));
      md->full(state, tup);
    }
    md->region(state, _md_region_to_tuple(state, region, pos));
    return md;
  }