@Override public int compareTo(byte[] value, int offset, int length) { // Use subsequence match instead of full sequence match to adhere to the // principle of least surprise. Matcher m = pattern.matcher(value); return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0; }
@Override public int compareTo(byte[] value, int offset, int length) { // Use subsequence match instead of full sequence match to adhere to the // principle of least surprise. Matcher m = pattern.matcher(value); return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0; }
int totalBytesNeeded = 0; while (true) { int nextCur = matcher.search(cur, srcRange, Option.DEFAULT); if (nextCur < 0) { totalBytesNeeded += srcRange - cur;
private boolean substr(byte[] srcBytes, int offset, int range, ImmutableBytesWritable outPtr) { Matcher matcher = pattern.matcher(srcBytes, 0, range); boolean ret = matcher.search(offset, range, Option.DEFAULT) >= 0; if (ret) { int len = matcher.getEnd() - matcher.getBegin(); outPtr.set(srcBytes, matcher.getBegin(), len); } else { outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY); } return ret; }
boolean append; while (true) { int nextCur = matcher.search(cur, srcRange, Option.DEFAULT); if (nextCur < 0) { builder.appendValue(srcBytes, cur, srcRange - cur);
@Override public boolean test(final CharSequence string) { return regex.matcher(string.toString().getBytes(StandardCharsets.UTF_8)) .search(0, string.length(), Option.NONE) > Matcher.FAILED; }
protected void bench(String _reg, String _str, int warmup, int times) throws Exception { byte[] reg = _reg.getBytes(); byte[] str = _str.getBytes(); Regex p = new Regex(reg,0,reg.length,Option.DEFAULT,ASCIIEncoding.INSTANCE,Syntax.DEFAULT); System.err.println("::: /" + _reg + "/ =~ \"" + _str + "\", " + warmup + " * " + times + " times"); for(int j=0;j<warmup;j++) { long before = System.currentTimeMillis(); for(int i = 0; i < times; i++) { p.matcher(str, 0, str.length).search(0, str.length, Option.NONE); } long time = System.currentTimeMillis() - before; System.err.println(": " + time + "ms"); } }
protected void bench(String _reg, String _str, int warmup, int times) throws Exception { byte[] reg = _reg.getBytes(); byte[] str = _str.getBytes(); Regex p = new Regex(reg,0,reg.length,Option.DEFAULT,ASCIIEncoding.INSTANCE,Syntax.DEFAULT); System.err.println("::: /" + _reg + "/ =~ \"" + _str + "\", " + warmup + " * " + times + " times"); for(int j=0;j<warmup;j++) { long before = System.currentTimeMillis(); for(int i = 0; i < times; i++) { p.matcher(str, 0, str.length).search(0, str.length, Option.NONE); } long time = System.currentTimeMillis() - before; System.err.println(": " + time + "ms"); } }
public Region match(String str, int from) { byte[] strBytes = str.getBytes(); Matcher matcher = this.pattern.matcher(strBytes, 0, strBytes.length); if (matcher.search(from, strBytes.length, 0) >= 0) { return matcher.getEagerRegion(); } return null; }
protected void benchBestOf(String _reg, String _str, int warmup, int times) throws Exception { byte[] reg = _reg.getBytes(); byte[] str = _str.getBytes(); Regex p = new Regex(reg,0,reg.length,Option.DEFAULT,ASCIIEncoding.INSTANCE,Syntax.DEFAULT); System.err.println("::: /" + _reg + "/ =~ \"" + _str + "\", " + warmup + " * " + times + " times"); long best = Long.MAX_VALUE; for(int j=0;j<warmup;j++) { long before = System.currentTimeMillis(); for(int i = 0; i < times; i++) { p.matcher(str, 0, str.length).search(0, str.length, Option.NONE); } long time = System.currentTimeMillis() - before; if(time < best) { best = time; } System.err.print("."); } System.err.println(": " + best + "ms"); } }
@Override public int compareTo(byte[] value, int offset, int length) { // Use subsequence match instead of full sequence match to adhere to the // principle of least surprise. Matcher m = pattern.matcher(value); return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0; }
@Override public int compareTo(byte[] value, int offset, int length) { // Use subsequence match instead of full sequence match to adhere to the // principle of least surprise. Matcher m = pattern.matcher(value); return m.search(offset, length, pattern.getOptions()) < 0 ? 1 : 0; }
@Override public boolean find(int start) { return update(matcher.search(byteIndex(start), byteLength, Option.NONE)); }
/** * Checks whether a specific text matches the defined grok expression. * * @param text the string to match * @return true if grok expression matches text, false otherwise. */ public boolean match(String text) { Matcher matcher = compiledExpression.matcher(text.getBytes(StandardCharsets.UTF_8)); int result; try { threadWatchdog.register(); result = matcher.search(0, text.length(), Option.DEFAULT); } finally { threadWatchdog.unregister(); } return (result != -1); }
private int performSearch(boolean reverse, int pos, ByteList value, Frame frame, Ruby runtime, ThreadContext context, RubyString str) { check(); int realSize = value.realSize; int begin = value.begin; int range = reverse ? -pos : realSize - pos; Matcher matcher = pattern.matcher(value.bytes, begin, begin + realSize); int result = matcher.search(begin + pos, begin + pos + range, Option.NONE); if (result < 0) { frame.setBackRef(runtime.getNil()); return result; } updateBackRef(context, str, frame, matcher); return result; }
public static int matcherSearch(ThreadContext context, Matcher matcher, int start, int range, int option) { if (!context.runtime.getInstanceConfig().isInterruptibleRegexps()) return matcher.search(start, range, option); try { RubyThread thread = context.getThread(); SearchMatchTask task = new SearchMatchTask(thread, start, range, option, false); return thread.executeTask(context, matcher, task); } catch (InterruptedException e) { throw context.runtime.newInterruptedRegexpError("Regexp Interrupted"); } }
public static int matcherSearch(ThreadContext context, Matcher matcher, int start, int range, int option) { if (!context.runtime.getInstanceConfig().isInterruptibleRegexps()) return matcher.search(start, range, option); try { RubyThread thread = context.getThread(); SearchMatchTask task = new SearchMatchTask(thread, start, range, option, false); return thread.executeTask(context, matcher, task); } catch (InterruptedException e) { throw context.runtime.newInterruptedRegexpError("Regexp Interrupted"); } }
private boolean substr(byte[] srcBytes, int offset, int range, ImmutableBytesWritable outPtr) { Matcher matcher = pattern.matcher(srcBytes, 0, range); boolean ret = matcher.search(offset, range, Option.DEFAULT) >= 0; if (ret) { int len = matcher.getEnd() - matcher.getBegin(); outPtr.set(srcBytes, matcher.getBegin(), len); } else { outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY); } return ret; }
private boolean substr(byte[] srcBytes, int offset, int range, ImmutableBytesWritable outPtr) { Matcher matcher = pattern.matcher(srcBytes, 0, range); boolean ret = matcher.search(offset, range, Option.DEFAULT) >= 0; if (ret) { int len = matcher.getEnd() - matcher.getBegin(); outPtr.set(srcBytes, matcher.getBegin(), len); } else { outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY); } return ret; }
private IRubyObject scanOnceNG(RubyRegexp regex, Matcher matcher, int range) { if (matcher.search(matcher.value + value.begin, range, Option.NONE) >= 0) { int end = matcher.getEnd(); if (matcher.getBegin() == 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; } return substr(matcher.getBegin(), end - matcher.getBegin()).infectBy(regex); } return null; }