@Override public int getFlags() { return pattern.getOptions(); }
@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 byte[] toByteArray() { ComparatorProtos.RegexStringComparator.Builder builder = ComparatorProtos.RegexStringComparator.newBuilder(); builder.setPattern(regex); builder.setPatternFlags(joniToPatternFlags(pattern.getOptions())); builder.setCharset(encoding.getCharsetName()); builder.setEngine(EngineType.JONI.name()); return builder.build().toByteArray(); }
@Override public int getFlags() { return pattern.getOptions(); }
@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 byte[] toByteArray() { ComparatorProtos.RegexStringComparator.Builder builder = ComparatorProtos.RegexStringComparator.newBuilder(); builder.setPattern(regex); builder.setPatternFlags(joniToPatternFlags(pattern.getOptions())); builder.setCharset(encoding.getCharsetName()); builder.setEngine(EngineType.JONI.name()); return builder.build().toByteArray(); }
static RubyRegexp newRegexp(Ruby runtime, ByteList str, Regex pattern) { RubyRegexp regexp = new RubyRegexp(runtime); assert str != null; regexp.str = str; regexp.options = RegexpOptions.fromJoniOptions(pattern.getOptions()); regexp.pattern = pattern; return regexp; }
@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; }
static Regex getRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options) { Map<ByteList, Regex> cache = patternCache.get(); Regex regex = cache.get(bytes); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; regex = makeRegexp(runtime, bytes, options, enc); regex.setUserObject(bytes); cache.put(bytes, regex); return regex; }
public static void marshalTo(RubyRegexp regexp, MarshalStream output) throws java.io.IOException { output.registerLinkTarget(regexp); output.writeString(new String(regexp.str.bytes,regexp.str.begin,regexp.str.realSize)); output.writeInt(regexp.pattern.getOptions() & EMBEDDABLE); } }
private static Regex getPreprocessedRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options, ErrorMode mode) { Map<ByteList, Regex> cache = preprocessedPatternCache.get(); Regex regex = cache.get(bytes); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; ByteList preprocessed = preprocess(runtime, bytes, enc, new Encoding[]{null}, ErrorMode.RAISE); regex = makeRegexp(runtime, preprocessed, options, enc); regex.setUserObject(preprocessed); cache.put(bytes, regex); return regex; }
/** rb_reg_inspect * */ @JRubyMethod(name = "inspect") @Override public IRubyObject inspect() { check(); return getRuntime().newString(ByteList.create(rb_reg_desc(str.bytes, str.begin, str.realSize, pattern.getOptions()).toString())); }
@JRubyMethod(name = {"==", "eql?"}, required = 1) @Override public IRubyObject op_equal(ThreadContext context, IRubyObject other) { if(this == other) return context.getRuntime().getTrue(); if(!(other instanceof RubyRegexp)) return context.getRuntime().getFalse(); RubyRegexp otherRegex = (RubyRegexp)other; check(); otherRegex.check(); return context.getRuntime().newBoolean(str.equal(otherRegex.str) && kcode == otherRegex.kcode && pattern.getOptions() == otherRegex.pattern.getOptions()); }
public static void marshalTo(RubyRegexp regexp, MarshalStream output) throws java.io.IOException { output.registerLinkTarget(regexp); output.writeString(regexp.str); int options = regexp.pattern.getOptions() & EMBEDDABLE; if (regexp.getOptions().isFixed()) options |= ARG_ENCODING_FIXED; output.writeByte(options); }
public static Regex getRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options) { Regex regex = patternCache.get(bytes); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; regex = makeRegexp(runtime, bytes, options, enc); regex.setUserObject(bytes); patternCache.put(bytes, regex); return regex; }
private static Regex getPreprocessedRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options, RegexpSupport.ErrorMode mode) { Regex regex = preprocessedPatternCache.get(bytes); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; ByteList preprocessed = RegexpSupport.preprocess(runtime, bytes, enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE); regex = makeRegexp(runtime, preprocessed, options, enc); regex.setUserObject(preprocessed); preprocessedPatternCache.put(bytes, regex); return regex; }
private static Regex getPreprocessedRegexpFromCache(Ruby runtime, ByteList bytes, Encoding enc, RegexpOptions options, RegexpSupport.ErrorMode mode) { Regex regex = preprocessedPatternCache.get(bytes); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; ByteList preprocessed = RegexpSupport.preprocess(runtime, bytes, enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE); regex = makeRegexp(runtime, preprocessed, options, enc); regex.setUserObject(preprocessed); preprocessedPatternCache.put(bytes, regex); return regex; }
@Override public byte[] toByteArray() { ComparatorProtos.RegexStringComparator.Builder builder = ComparatorProtos.RegexStringComparator.newBuilder(); builder.setPattern(regex); builder.setPatternFlags(joniToPatternFlags(pattern.getOptions())); builder.setCharset(encoding.getCharsetName()); builder.setEngine(EngineType.JONI.name()); return builder.build().toByteArray(); }
static Regex getQuotedRegexpFromCache(Ruby runtime, RubyString str, RegexpOptions options) { final ByteList bytes = str.getByteList(); Regex regex = quotedPatternCache.get(bytes); Encoding enc = str.isAsciiOnly() ? USASCIIEncoding.INSTANCE : bytes.getEncoding(); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; final ByteList quoted = quote(str); regex = makeRegexp(runtime, quoted, options, quoted.getEncoding()); regex.setUserObject(quoted); quotedPatternCache.put(bytes, regex); return regex; }
static Regex getQuotedRegexpFromCache(Ruby runtime, RubyString str, RegexpOptions options) { final ByteList bytes = str.getByteList(); Regex regex = quotedPatternCache.get(bytes); Encoding enc = str.isAsciiOnly() ? USASCIIEncoding.INSTANCE : bytes.getEncoding(); if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex; final ByteList quoted = quote(str); regex = makeRegexp(runtime, quoted, options, quoted.getEncoding()); regex.setUserObject(quoted); quotedPatternCache.put(bytes, regex); return regex; }