private static String[] names(final Regex regex) { final String[] names = new String[regex.numberOfCaptures() + 1]; if (regex.numberOfNames() == 0) return names; for (final Iterator<NameEntry> iter = regex.namedBackrefIterator(); iter.hasNext();) { final NameEntry backref = iter.next(); final String name = new String(backref.name, backref.nameP, backref.nameEnd - backref.nameP, StandardCharsets.UTF_8); for (final int index : backref.getBackRefs()) { names[index] = name; } } return names; } }
private static String[] names(final Regex regex) { final String[] names = new String[regex.numberOfCaptures() + 1]; if (regex.numberOfNames() == 0) return names; for (final Iterator<NameEntry> iter = regex.namedBackrefIterator(); iter.hasNext();) { final NameEntry backref = iter.next(); final String name = new String(backref.name, backref.nameP, backref.nameEnd - backref.nameP, StandardCharsets.UTF_8); for (final int index : backref.getBackRefs()) { names[index] = name; } } return names; } }
@Override public boolean configure(Properties properties) { try { // Generate pattern using both ASCII and UTF-8 byte[] patternSrcBytesAscii = getBytesAscii(patternSrc); // the ascii pattern is generated only if the source pattern is pure ASCII if (patternSrcBytesAscii != null) { patternAscii = new Regex(patternSrcBytesAscii, 0, patternSrcBytesAscii.length, Option.NONE, USASCIIEncoding.INSTANCE); } else { patternAscii = null; } byte[] patternSrcBytesUtf8 = patternSrc.getBytes(StandardCharsets.UTF_8); patternUtf8 = new Regex(patternSrcBytesUtf8, 0, patternSrcBytesUtf8.length, Option.NONE, UTF8Encoding.INSTANCE); if (patternUtf8.numberOfCaptures() != patternUtf8.numberOfNames()) { logger.error("Can't have two captures with same name"); return false; } else { return super.configure(properties); } } catch (SyntaxException e) { logger.error("Error parsing regex:" + Helpers.resolveThrowableException(e)); logger.catching(Level.DEBUG, e); return false; } }
RubyMatchData match = rubyRegex.updateBackRef(context, this, frame, matcher); match.use(); if (regex.numberOfCaptures() == 0) { repl = objAsString(context, block.yield(context, substr(matcher.getBegin(), matcher.getEnd() - matcher.getBegin()))); } else { if (regex.numberOfCaptures() == 0) { beg = matcher.getBegin(); plen = matcher.getEnd() - beg;
RubyArray ary = runtime.newArray(); if (regex.numberOfCaptures() == 0) { while ((result = scanOnceNG(rubyRegex, matcher, range)) != null) ary.append(result); } else { RubyMatchData match = null; if (regex.numberOfCaptures() == 0) { while ((result = scanOnceNG(rubyRegex, matcher, range)) != null) { match = rubyRegex.updateBackRef(context, this, frame, matcher);
private IRubyObject scanNoIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, int begin, int range, int tuFlags) { Ruby runtime = context.runtime; RubyArray ary = runtime.newArray(); int end = 0; if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin()); substr.infectBy(tuFlags); ary.append(substr); } } else { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); ary.append(populateCapturesForScan(runtime, matcher, range, tuFlags, false)); } } if (ary.size() > 0) { RubyMatchData match = RubyRegexp.createMatchData(context, this, matcher, pattern); match.infectBy(tuFlags); context.setBackRef(match); } else { context.setBackRef(runtime.getNil()); } return ary; }
private IRubyObject scanNoIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, int begin, int range, int tuFlags) { Ruby runtime = context.runtime; RubyArray ary = runtime.newArray(); int end = 0; if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin()); substr.infectBy(tuFlags); ary.append(substr); } } else { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); ary.append(populateCapturesForScan(runtime, matcher, range, tuFlags, false)); } } if (ary.size() > 0) { RubyMatchData match = RubyRegexp.createMatchData(context, this, matcher, pattern); match.infectBy(tuFlags); context.setBackRef(match); } else { context.setBackRef(runtime.getNil()); } return ary; }
if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range);
if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range);
private IRubyObject scanIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, Block block, int begin, int range, int tuFlags) { Ruby runtime = context.runtime; byte[]bytes = value.getUnsafeBytes(); int size = value.getRealSize(); RubyMatchData match = null; int end = 0; if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); match = RubyRegexp.createMatchData(context, this, matcher, pattern); RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin()); substr.infectBy(tuFlags); match.infectBy(tuFlags); context.setBackRef(match); block.yield(context, substr); modifyCheck(bytes, size); } } else { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); match = RubyRegexp.createMatchData(context, this, matcher, pattern); match.infectBy(tuFlags); context.setBackRef(match); block.yield(context, populateCapturesForScan(runtime, matcher, range, tuFlags, false)); modifyCheck(bytes, size); } } context.setBackRef(match == null ? runtime.getNil() : match); return this; }
private IRubyObject scanIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, Block block, int begin, int range, int tuFlags) { Ruby runtime = context.runtime; byte[]bytes = value.getUnsafeBytes(); int size = value.getRealSize(); RubyMatchData match = null; int end = 0; if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); match = RubyRegexp.createMatchData(context, this, matcher, pattern); RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin()); substr.infectBy(tuFlags); match.infectBy(tuFlags); context.setBackRef(match); block.yield(context, substr); modifyCheck(bytes, size); } } else { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range); match = RubyRegexp.createMatchData(context, this, matcher, pattern); match.infectBy(tuFlags); context.setBackRef(match); block.yield(context, populateCapturesForScan(runtime, matcher, range, tuFlags, false)); modifyCheck(bytes, size); } } context.setBackRef(match == null ? runtime.getNil() : match); return this; }
if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range);
boolean captures = pattern.numberOfCaptures() != 0;
boolean captures = pattern.numberOfCaptures() != 0;
if (pattern.numberOfCaptures() == 0) { while (RubyRegexp.matcherSearch(runtime, matcher, begin + end, range, Option.NONE) >= 0) { end = positionEnd(matcher, enc, begin, range);
boolean captures = pattern.getPattern().numberOfCaptures() != 0;
Encoding enc = getEncodingForKCodeDefault(runtime, pattern, pat); boolean captures = pattern.numberOfCaptures() != 0;
Encoding enc = getEncodingForKCodeDefault(runtime, pattern, pat); boolean captures = pattern.numberOfCaptures() != 0;
boolean captures = pattern.getPattern().numberOfCaptures() != 0;
if (regex.numberOfCaptures() == 0) { // shorter path, no captures defined, no region will be returned while ((end = matcher.search(start, range, Option.NONE)) >= 0) { if (start == end + begin && matcher.getBegin() == matcher.getEnd()) {