Package org.joni

Examples of org.joni.Regex


    // MRI: str_gsub, roughly
    private IRubyObject gsubCommon19(ThreadContext context, Block block, RubyString repl,
            RubyHash hash, IRubyObject arg0, final boolean bang, int tuFlags, boolean useBackref) {
        Ruby runtime = context.runtime;

        final Regex pattern, prepared;
        final RubyRegexp regexp;
        if (arg0 instanceof RubyRegexp) {
            regexp = (RubyRegexp)arg0;
            pattern = regexp.getPattern();
            prepared = regexp.preparePattern(this);
View Full Code Here


            if (spat instanceof RubyString) {
                ByteList spatValue = ((RubyString)spat).value;
                int len = spatValue.getRealSize();
                Encoding spatEnc = spatValue.getEncoding();
                if (len == 0) {
                    Regex pattern = RubyRegexp.getRegexpFromCache(context.runtime, spatValue, spatEnc, new RegexpOptions());
                    result = regexSplit19(context, pattern, pattern, limit, lim, i, useBackref);
                } else {
                    final int c;
                    byte[]bytes = spatValue.getUnsafeBytes();
                    int p = spatValue.getBegin();
                    if (spatEnc.isAsciiCompatible()) {
                        c = len == 1 ? bytes[p] & 0xff : -1;
                    } else {
                        c = len == StringSupport.preciseLength(spatEnc, bytes, p, p + len) ? spatEnc.mbcToCode(bytes, p, p + len) : -1;
                    }
                    result = c == ' ' ? awkSplit19(limit, lim, i) : stringSplit19(context, (RubyString)spat, limit, lim, i);
                }
            } else {
                final Regex pattern, prepared;
               
                Ruby runtime = context.runtime;
                if (spat instanceof RubyRegexp) {
                    RubyRegexp regexp = (RubyRegexp)spat;
                    pattern = regexp.getPattern();
View Full Code Here

    @JRubyMethod(name = "scan", reads = BACKREF, writes = BACKREF)
    public IRubyObject scan19(ThreadContext context, IRubyObject arg, Block block) {
        Ruby runtime = context.runtime;
        Encoding enc = value.getEncoding();
        final Regex pattern, prepared;
        final RubyRegexp regexp;
        final int tuFlags;
        if (arg instanceof RubyRegexp) {
            regexp = (RubyRegexp)arg;
            tuFlags = regexp.flags;
View Full Code Here

            }

            if (value instanceof Slice &&
                    pattern instanceof Slice &&
                    (escape == null || escape instanceof Slice)) {
                Regex regex = LikeUtils.likeToPattern((Slice) pattern, (Slice) escape);

                return LikeUtils.regexMatches(regex, (Slice) value);
            }

            // if pattern is a constant without % or _ replace with a comparison
View Full Code Here

            return new LikePredicate(toExpression(value), toExpression(pattern), optimizedEscape);
        }

        private Regex getConstantPattern(LikePredicate node)
        {
            Regex result = LIKE_PATTERN_CACHE.get(node);

            if (result == null) {
                StringLiteral pattern = (StringLiteral) node.getPattern();
                StringLiteral escape = (StringLiteral) node.getEscape();
View Full Code Here

    }

    public static boolean dynamicLike(LikePatternCache callSiteCache, Slice value, Slice pattern, Slice escape)
    {
        LikeCacheKey key = new LikeCacheKey(pattern, escape);
        Regex regex = callSiteCache.get(key);
        return regexMatches(regex, value);
    }
View Full Code Here

            }
        }
        regex.append('$');

        byte[] bytes = regex.toString().getBytes(Charsets.UTF_8);
        return new Regex(bytes, 0, bytes.length, 0, UTF8Encoding.INSTANCE, SYNTAX);
    }
View Full Code Here

            Slice escapeSlice = null;
            if (escapeNode != null) {
                escapeSlice = (Slice) ((Constant) escapeNode).getValue();
            }

            Regex regex = LikeUtils.likeToPattern(pattern, escapeSlice);

            methodHandle = constantPattern.bindTo(regex);
            arguments = ImmutableList.of(valueNode);
        }
        else {
View Full Code Here

            }

            if (value instanceof Slice &&
                    pattern instanceof Slice &&
                    (escape == null || escape instanceof Slice)) {
                Regex regex = LikeUtils.likeToPattern((Slice) pattern, (Slice) escape);

                return LikeUtils.regexMatches(regex, (Slice) value);
            }

            // if pattern is a constant without % or _ replace with a comparison
View Full Code Here

                    optimizedEscape);
        }

        private Regex getConstantPattern(LikePredicate node)
        {
            Regex result = likePatternCache.get(node);

            if (result == null) {
                StringLiteral pattern = (StringLiteral) node.getPattern();
                StringLiteral escape = (StringLiteral) node.getEscape();
View Full Code Here

TOP

Related Classes of org.joni.Regex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.