Region reg = arr.get(rnd.nextInt(arr.size())) ALL_REGIONS.add(reg.clone()); // this is just meant to be a sort of pseudo-code. Use a clone() method to create a new copy of the object and that copy to ALL_REGIONS.
public final Region getEagerRegion() { return msaRegion != null ? msaRegion : new Region(msaBegin, msaEnd); }
Region region = msaRegion; if (region != null) { region.clear(); } else { msaBegin = msaEnd = 0;
Region region = msaRegion; if (region != null) { region.clear(); } else { msaBegin = msaEnd = 0;
public final Region getEagerRegion() { return msaRegion != null ? msaRegion : new Region(msaBegin, msaEnd); }
@Override public MatcherResult toMatchResult() { if (begin < 0) throw new IllegalStateException("No match!"); return new MatcherResultImpl(encString.string, negativeLAGroups, namedGroups, position, begin, end, region != null ? region.clone() : null); }
public Region clone() { Region region = new Region(numRegs); System.arraycopy(beg, 0, region.beg, 0, beg.length); System.arraycopy(end, 0, region.end, 0, end.length); if (historyRoot != null) region.historyRoot = historyRoot.cloneTree(); return region; }
@JRubyMethod(visibility = PRIVATE) @Override public IRubyObject initialize_copy(IRubyObject other) { if (this == other) return this; if (!(other instanceof RubyStringScanner)) { throw getRuntime().newTypeError("wrong argument type " + other.getMetaClass() + " (expected StringScanner)"); } RubyStringScanner otherScanner = (RubyStringScanner)other; str = otherScanner.str; pos = otherScanner.pos; lastPos = otherScanner.lastPos; scannerFlags = otherScanner.scannerFlags; regs = otherScanner.regs != null ? otherScanner.regs.clone() : null; pattern = otherScanner.pattern; beg = otherScanner.beg; end = otherScanner.end; return this; }
public Region clone() { Region region = new Region(numRegs); System.arraycopy(beg, 0, region.beg, 0, beg.length); System.arraycopy(end, 0, region.end, 0, end.length); if (historyRoot != null) region.historyRoot = historyRoot.cloneTree(); return region; }
@JRubyMethod(visibility = PRIVATE) @Override public IRubyObject initialize_copy(IRubyObject other) { if (this == other) return this; if (!(other instanceof RubyStringScanner)) { throw getRuntime().newTypeError("wrong argument type " + other.getMetaClass() + " (expected StringScanner)"); } RubyStringScanner otherScanner = (RubyStringScanner)other; str = otherScanner.str; pos = otherScanner.pos; lastPos = otherScanner.lastPos; scannerFlags = otherScanner.scannerFlags; regs = otherScanner.regs != null ? otherScanner.regs.clone() : null; beg = otherScanner.beg; end = otherScanner.end; return this; }
public Matcher matcher(byte[]bytes, int p, int end) { return factory.create(this, numMem == 0 ? null : new Region(numMem + 1), bytes, p, end); }
@JRubyMethod(name = "initialize_copy", frame=true, visibility = Visibility.PRIVATE) @Override public IRubyObject initialize_copy(IRubyObject other) { if (this == other) return this; if (!(other instanceof RubyStringScanner)) { throw getRuntime().newTypeError("wrong argument type " + other.getMetaClass() + " (expected StringScanner)"); } RubyStringScanner otherScanner = (RubyStringScanner)other; str = otherScanner.str; pos = otherScanner.pos; lastPos = otherScanner.lastPos; scannerFlags = otherScanner.scannerFlags; regs = otherScanner.regs != null ? otherScanner.regs.clone() : null; beg = otherScanner.beg; end = otherScanner.end; return this; }
public Matcher matcher(byte[]bytes, int p, int end) { return factory.create(this, numMem == 0 ? null : new Region(numMem + 1), bytes, p, end); }
@JRubyMethod(visibility = PRIVATE) @Override public IRubyObject initialize_copy(IRubyObject other) { if (this == other) return this; if (!(other instanceof RubyStringScanner)) { throw getRuntime().newTypeError("wrong argument type " + other.getMetaClass() + " (expected StringScanner)"); } RubyStringScanner otherScanner = (RubyStringScanner)other; str = otherScanner.str; pos = otherScanner.pos; lastPos = otherScanner.lastPos; scannerFlags = otherScanner.scannerFlags; regs = otherScanner.regs != null ? otherScanner.regs.clone() : null; beg = otherScanner.beg; end = otherScanner.end; return this; }
private Region splitMatch(ExecutionContext context, String s, int q, Object r) { if ( r instanceof DynRegExp ) { return ((DynRegExp)r).match(s, q); } String rStr = (String) r; int rLen = rStr.length(); int sLen = s.length(); if ( q + rLen > sLen ) { return null; } for ( int i = 0 ; i < rLen ; ++i ) { if ( s.charAt(q+i) != rStr.charAt( i ) ) { return null; } } return new Region(0, q+rLen); }
@JRubyMethod(visibility = PRIVATE) @Override public IRubyObject initialize_copy(IRubyObject other) { if (this == other) return this; if (!(other instanceof RubyStringScanner)) { throw getRuntime().newTypeError("wrong argument type " + other.getMetaClass() + " (expected StringScanner)"); } RubyStringScanner otherScanner = (RubyStringScanner)other; str = otherScanner.str; pos = otherScanner.pos; lastPos = otherScanner.lastPos; scannerFlags = otherScanner.scannerFlags; regs = otherScanner.regs != null ? otherScanner.regs.clone() : null; pattern = otherScanner.pattern; beg = otherScanner.beg; end = otherScanner.end; return this; }
private void updateCharOffsetOnlyOneReg(ByteList value, Encoding encoding) { if (charOffsets == null || charOffsets.numRegs < 1) charOffsets = new Region(1); if (encoding.maxLength() == 1) { charOffsets.beg[0] = begin; charOffsets.end[0] = end; charOffsetUpdated = true; return; } Pair[] pairs = new Pair[2]; pairs[0] = new Pair(); pairs[0].bytePos = begin; pairs[1] = new Pair(); pairs[1].bytePos = end; updatePairs(value, encoding, pairs); Pair key = new Pair(); key.bytePos = begin; charOffsets.beg[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; key.bytePos = end; charOffsets.end[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; }
static final RubyMatchData createMatchData(ThreadContext context, RubyString str, Matcher matcher, Regex pattern) { Ruby runtime = context.runtime; final RubyMatchData match = new RubyMatchData(runtime); // FIXME: This is pretty gross; we should have a cleaner initialization // that doesn't depend on package-visible fields and ideally is atomic, // probably using an immutable structure we replace all at once. // The region must be cloned because a subsequent match will update the // region, resulting in the MatchData created here pointing at the // incorrect region (capture/group). Region region = matcher.getRegion(); // lazy, null when no groups defined match.regs = region == null ? null : region.clone(); match.begin = matcher.getBegin(); match.end = matcher.getEnd(); match.pattern = pattern; match.str = (RubyString)str.strDup(runtime).freeze(context); match.infectBy(str); return match; }
private void updateCharOffsetOnlyOneReg(ByteList value, Encoding encoding) { if (charOffsets == null || charOffsets.numRegs < 1) charOffsets = new Region(1); if (encoding.maxLength() == 1) { charOffsets.beg[0] = begin; charOffsets.end[0] = end; charOffsetUpdated = true; return; } Pair[] pairs = new Pair[2]; pairs[0] = new Pair(); pairs[0].bytePos = begin; pairs[1] = new Pair(); pairs[1].bytePos = end; updatePairs(value, encoding, pairs); Pair key = new Pair(); key.bytePos = begin; charOffsets.beg[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; key.bytePos = end; charOffsets.end[0] = pairs[Arrays.binarySearch(pairs, key)].charPos; }
static final RubyMatchData createMatchData(ThreadContext context, RubyString str, Matcher matcher, Regex pattern) { Ruby runtime = context.runtime; final RubyMatchData match = new RubyMatchData(runtime); // FIXME: This is pretty gross; we should have a cleaner initialization // that doesn't depend on package-visible fields and ideally is atomic, // probably using an immutable structure we replace all at once. // The region must be cloned because a subsequent match will update the // region, resulting in the MatchData created here pointing at the // incorrect region (capture/group). Region region = matcher.getRegion(); // lazy, null when no groups defined match.regs = region == null ? null : region.clone(); match.begin = matcher.getBegin(); match.end = matcher.getEnd(); match.pattern = pattern; match.str = (RubyString)str.strDup(runtime).freeze(context); match.infectBy(str); return match; }