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.
@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); }
@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; }
@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; }
@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; }
@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; }
@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; }
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; }
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; }
this.regs = region == null ? null : region.clone(); this.begin = matcher.getBegin(); this.end = matcher.getEnd();
this.regs = region == null ? null : region.clone(); this.begin = matcher.getBegin(); this.end = matcher.getEnd();