public static Object[] getCaptures(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); // There should always be at least one value because the entire matched string must be in the // values array. // Thus, there is no risk of an ArrayIndexOutOfBoundsException here. return ArrayUtils.extractRange( Layouts.MATCH_DATA.getFields(matchData).values, 1, Layouts.MATCH_DATA.getFields(matchData).values.length); }
public static int getBackrefNumber(DynamicObject matchData, ByteList value) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.REGEXP .getRegex(Layouts.MATCH_DATA.getFields(matchData).regexp) .nameToBackrefNumber( value.getUnsafeBytes(), value.getBegin(), value.getBegin() + value.getRealSize(), Layouts.MATCH_DATA.getFields(matchData).region); }
public static Object begin(DynamicObject matchData, int index) { assert RubyGuards.isRubyMatchData(matchData); final int b = (Layouts.MATCH_DATA.getFields(matchData).region == null) ? Layouts.MATCH_DATA.getFields(matchData).begin : Layouts.MATCH_DATA.getFields(matchData).region.beg[index]; if (b < 0) { return BasicObjectNodes.getContext(matchData).getCoreLibrary().getNilObject(); } updateCharOffset(matchData); return Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[index]; }
public static void updateCharOffset(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return; ByteList value = Layouts.STRING.getByteList(Layouts.MATCH_DATA.getFields(matchData).source); Encoding enc = value.getEncoding(); if (Layouts.MATCH_DATA.getFields(matchData).region == null) { updateCharOffsetOnlyOneReg(matchData, value, enc); } else { updateCharOffsetManyRegs(matchData, value, enc); } Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true; }
public static Object end(DynamicObject matchData, int index) { assert RubyGuards.isRubyMatchData(matchData); int e = (Layouts.MATCH_DATA.getFields(matchData).region == null) ? Layouts.MATCH_DATA.getFields(matchData).end : Layouts.MATCH_DATA.getFields(matchData).region.end[index]; if (e < 0) { return BasicObjectNodes.getContext(matchData).getCoreLibrary().getNilObject(); } final CodeRangeable sourceWrapped = StringNodes.getCodeRangeable(Layouts.MATCH_DATA.getFields(matchData).source); if (!StringSupport.isSingleByteOptimizable( sourceWrapped, sourceWrapped.getByteList().getEncoding())) { updateCharOffset(matchData); e = Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[index]; } return e; }
public static DynamicObject createRubyMatchData( DynamicObject rubyClass, DynamicObject source, DynamicObject regexp, Region region, Object[] values, DynamicObject pre, DynamicObject post, DynamicObject global, int begin, int end) { return Layouts.MATCH_DATA.createMatchData( Layouts.CLASS.getInstanceFactory(rubyClass), new MatchDataFields(source, regexp, region, values, pre, post, global, begin, end)); }
public static Object[] getValues(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Arrays.copyOf( Layouts.MATCH_DATA.getFields(matchData).values, Layouts.MATCH_DATA.getFields(matchData).values.length); }
public static void updateCharOffsetManyRegs( DynamicObject matchData, ByteList value, Encoding encoding) { assert RubyGuards.isRubyMatchData(matchData); if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return; final Region regs = Layouts.MATCH_DATA.getFields(matchData).region; int numRegs = regs.numRegs; if (Layouts.MATCH_DATA.getFields(matchData).charOffsets == null || Layouts.MATCH_DATA.getFields(matchData).charOffsets.numRegs < numRegs) Layouts.MATCH_DATA.getFields(matchData).charOffsets = new Region(numRegs); if (encoding.maxLength() == 1) { for (int i = 0; i < numRegs; i++) { Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] = regs.beg[i]; Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = regs.end[i]; } Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true; return; } Pair[] pairs = new Pair[numRegs * 2]; for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair(); int numPos = 0; for (int i = 0; i < numRegs; i++) { if (regs.beg[i] < 0) continue; pairs[numPos++].bytePos = regs.beg[i]; pairs[numPos++].bytePos = regs.end[i]; } updatePairs(value, encoding, pairs); Pair key = new Pair(); for (int i = 0; i < regs.numRegs; i++) { if (regs.beg[i] < 0) { Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] = Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = -1; continue; } key.bytePos = regs.beg[i]; Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] = pairs[Arrays.binarySearch(pairs, key)].charPos; key.bytePos = regs.end[i]; Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = pairs[Arrays.binarySearch(pairs, key)].charPos; } Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true; }
public static void updateCharOffsetOnlyOneReg( DynamicObject matchData, ByteList value, Encoding encoding) { assert RubyGuards.isRubyMatchData(matchData); if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return; if (Layouts.MATCH_DATA.getFields(matchData).charOffsets == null || Layouts.MATCH_DATA.getFields(matchData).charOffsets.numRegs < 1) Layouts.MATCH_DATA.getFields(matchData).charOffsets = new Region(1); if (encoding.maxLength() == 1) { Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] = Layouts.MATCH_DATA.getFields(matchData).begin; Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] = Layouts.MATCH_DATA.getFields(matchData).end; Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true; return; } Pair[] pairs = new Pair[2]; if (Layouts.MATCH_DATA.getFields(matchData).begin >= 0) { pairs[0] = new Pair(); pairs[0].bytePos = Layouts.MATCH_DATA.getFields(matchData).begin; pairs[1] = new Pair(); pairs[1].bytePos = Layouts.MATCH_DATA.getFields(matchData).end; } updatePairs(value, encoding, pairs); if (Layouts.MATCH_DATA.getFields(matchData).begin < 0) { Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] = Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] = -1; return; } Pair key = new Pair(); key.bytePos = Layouts.MATCH_DATA.getFields(matchData).begin; Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; key.bytePos = Layouts.MATCH_DATA.getFields(matchData).end; Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true; }
public static int getFullEnd(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).end; }
public static void setFullTuple(DynamicObject matchData, Object fullTuple) { assert RubyGuards.isRubyMatchData(matchData); Layouts.MATCH_DATA.getFields(matchData).fullTuple = fullTuple; }
public static Object getFullTuple(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).fullTuple; }
public static DynamicObject getRegexp(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).regexp; }
public static DynamicObject getSource(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).source; }
public static DynamicObject getGlobal(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).global; }
public static int getNumberOfRegions(DynamicObject matchData) { assert RubyGuards.isRubyMatchData(matchData); return Layouts.MATCH_DATA.getFields(matchData).region.numRegs; }