private void populateCapturesForSplit(Ruby runtime, RubyArray result, Matcher matcher, boolean is19) { Region region = matcher.getRegion(); for (int i = 1; i < region.numRegs; i++) { int beg = region.beg[i]; if (beg == -1) continue; result.append(is19 ? makeShared19(runtime, beg, region.end[i] - beg) : makeShared(runtime, beg, region.end[i] - beg)); } }
private boolean update(int r) { begin = matcher.getBegin(); end = matcher.getEnd(); region = matcher.getRegion(); position = position.relativeTo(begin, end); return r > Matcher.FAILED; }
private void populateCapturesForSplit(Ruby runtime, RubyArray result, Matcher matcher, boolean is19) { Region region = matcher.getRegion(); for (int i = 1; i < region.numRegs; i++) { int beg = region.beg[i]; if (beg == -1) continue; result.append(is19 ? makeShared19(runtime, beg, region.end[i] - beg) : makeShared(runtime, beg, region.end[i] - beg)); } }
static RubyString regsub(ThreadContext context, RubyString str, RubyString src, Regex pattern, Matcher matcher) { return regsub(context, str, src, pattern, matcher.getRegion(), matcher.getBegin(), matcher.getEnd()); }
static RubyString regsub(ThreadContext context, RubyString str, RubyString src, Regex pattern, Matcher matcher) { return regsub(context, str, src, pattern, matcher.getRegion(), matcher.getBegin(), matcher.getEnd()); }
final Region regions = m.getRegion(); if (regions != null) { for (int i = 1; i < regions.numRegs; ++i) {
final Region regions = m.getRegion(); if (regions != null) { for (int i = 1; i < regions.numRegs; ++i) {
protected void handleFileEncodingComment(ByteList encodingLine) throws IOException { int realSize = encodingLine.getRealSize(); int begin = encodingLine.getBegin(); Matcher matcher = encodingRegexp.matcher(encodingLine.getUnsafeBytes(), begin, begin + realSize); int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.IGNORECASE); if (result < 0) return; int begs[] = matcher.getRegion().beg; int ends[] = matcher.getRegion().end; setEncoding(new ByteList(encodingLine.getUnsafeBytes(), begs[1], ends[1] - begs[1])); }
protected void handleFileEncodingComment(ByteList encodingLine) throws IOException { int realSize = encodingLine.getRealSize(); int begin = encodingLine.getBegin(); Matcher matcher = encodingRegexp.matcher(encodingLine.getUnsafeBytes(), begin, begin + realSize); int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.IGNORECASE); if (result < 0) return; int begs[] = matcher.getRegion().beg; int ends[] = matcher.getRegion().end; setEncoding(new ByteList(encodingLine.getUnsafeBytes(), begs[1], ends[1] - begs[1])); }
protected boolean parseMagicComment(ByteList magicLine) throws IOException { int length = magicLine.length(); if (length <= 7) return false; int beg = magicCommentMarker(magicLine, 0); if (beg < 0) return false; int end = magicCommentMarker(magicLine, beg); if (end < 0) return false; // We only use a regex if -*- ... -*- is found. Not too hot a path? int realSize = magicLine.getRealSize(); int begin = magicLine.getBegin(); Matcher matcher = magicRegexp.matcher(magicLine.getUnsafeBytes(), begin, begin + realSize); int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.NONE); if (result < 0) return false; // Regexp is guarateed to have three matches int begs[] = matcher.getRegion().beg; int ends[] = matcher.getRegion().end; String name = magicLine.subSequence(begs[1], ends[1]).toString(); if (!name.equalsIgnoreCase("encoding")) return false; setEncoding(new ByteList(magicLine.getUnsafeBytes(), begs[2], ends[2] - begs[2])); return true; }
protected boolean parseMagicComment(ByteList magicLine) throws IOException { int length = magicLine.length(); if (length <= 7) return false; int beg = magicCommentMarker(magicLine, 0); if (beg < 0) return false; int end = magicCommentMarker(magicLine, beg); if (end < 0) return false; // We only use a regex if -*- ... -*- is found. Not too hot a path? int realSize = magicLine.getRealSize(); int begin = magicLine.getBegin(); Matcher matcher = magicRegexp.matcher(magicLine.getUnsafeBytes(), begin, begin + realSize); int result = RubyRegexp.matcherSearch(parserSupport.getConfiguration().getRuntime(), matcher, begin, begin + realSize, Option.NONE); if (result < 0) return false; // Regexp is guarateed to have three matches int begs[] = matcher.getRegion().beg; int ends[] = matcher.getRegion().end; String name = magicLine.subSequence(begs[1], ends[1]).toString(); if (!name.equalsIgnoreCase("encoding")) return false; setEncoding(new ByteList(magicLine.getUnsafeBytes(), begs[2], ends[2] - begs[2])); return true; }
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; }
private IRubyObject populateCapturesForScan(Ruby runtime, Matcher matcher, int range, int tuFlags, boolean is19) { Region region = matcher.getRegion(); RubyArray result = getRuntime().newArray(region.numRegs); for (int i=1; i<region.numRegs; i++) { int beg = region.beg[i]; if (beg == -1) { result.append(runtime.getNil()); } else { RubyString substr = is19 ? makeShared19(runtime, beg, region.end[i] - beg) : makeShared(runtime, beg, region.end[i] - beg); substr.infectBy(tuFlags); result.append(substr); } } return result; }
private IRubyObject populateCapturesForScan(Ruby runtime, Matcher matcher, int range, int tuFlags, boolean is19) { Region region = matcher.getRegion(); RubyArray result = getRuntime().newArray(region.numRegs); for (int i=1; i<region.numRegs; i++) { int beg = region.beg[i]; if (beg == -1) { result.append(runtime.getNil()); } else { RubyString substr = is19 ? makeShared19(runtime, beg, region.end[i] - beg) : makeShared(runtime, beg, region.end[i] - beg); substr.infectBy(tuFlags); result.append(substr); } } return result; }
private IRubyObject scanOnce(RubyRegexp regex, Matcher matcher, int range) { if (matcher.search(matcher.value + value.begin, range, Option.NONE) >= 0) { Region region = matcher.getRegion(); int end = region.end[0]; if (region.beg[0] == end) { if (value.realSize > end) { matcher.value = end + regex.getPattern().getEncoding().length(value.bytes[value.begin + end]); } else { matcher.value = end + 1; } } else { matcher.value = end; } RubyArray result = getRuntime().newArray(region.numRegs); for (int i=1; i<region.numRegs; i++) { int beg = region.beg[i]; if (beg == -1) { result.append(getRuntime().getNil()); } else { result.append(substr(beg, region.end[i] - beg).infectBy(regex)); } } return result; } return null; }
final RubyMatchData updateBackRef(ThreadContext context, RubyString str, Frame frame, Matcher matcher) { Ruby runtime = context.getRuntime(); IRubyObject backref = frame.getBackRef(); final RubyMatchData match; if (backref == null || backref.isNil() || ((RubyMatchData)backref).used()) { match = new RubyMatchData(runtime); } else { match = (RubyMatchData)backref; match.setTaint(runtime.getSafeLevel() >= 3); } match.regs = matcher.getRegion(); // lazy, null when no groups defined match.begin = matcher.getBegin(); match.end = matcher.getEnd(); match.str = (RubyString)str.strDup(runtime).freeze(context); match.pattern = pattern; frame.setBackRef(match); match.infectBy(this); match.infectBy(str); return match; }
regs = matcher.getRegion(); if (regs == null) { beg = matcher.getBegin();
regs = matcher.getRegion(); if (regs == null) { beg = matcher.getBegin();
regs = matcher.getRegion(); if (regs == null) { beg = matcher.getBegin();