Package org.joni

Examples of org.joni.Regex


    @JRubyMethod(name = "sub!", reads = BACKREF, writes = BACKREF, compat = RUBY1_9)
    public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, Block block) {
        Ruby runtime = context.runtime;
        frozenCheck();

        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


    public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
        Ruby runtime = context.runtime;
        IRubyObject hash = TypeConverter.convertToTypeWithCheck(arg1, runtime.getHash(), "to_hash");
        frozenCheck();

        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

    }

    private IRubyObject gsubCommon(ThreadContext context, final boolean bang, IRubyObject arg, Block block, RubyString repl, int tuFlags) {
        Ruby runtime = context.runtime;
        DynamicScope scope = context.getCurrentScope();
        Regex pattern = getQuotedPattern(arg);

        int begin = value.getBegin();
        int slen = value.getRealSize();
        int range = begin + slen;
        byte[]bytes = value.getUnsafeBytes();
        Matcher matcher = pattern.matcher(bytes, begin, range);

        int beg = matcher.search(begin, range, Option.NONE);
        if (beg < 0) {
            scope.setBackRef(runtime.getNil());
            return bang ? runtime.getNil() : strDup(runtime); /* bang: true, no match, no substitution */
 
View Full Code Here

    private IRubyObject gsubCommon19(ThreadContext context, Block block, RubyString repl,
            RubyHash hash, IRubyObject arg0, final boolean bang, int tuFlags) {
        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

        return result;
    }

    private RubyArray regexSplit(ThreadContext context, IRubyObject pat, boolean limit, int lim, int i) {
        Ruby runtime = context.runtime;
        final Regex pattern = getQuotedPattern(pat);

        int begin = value.getBegin();
        int len = value.getRealSize();
        int range = begin + len;
        byte[]bytes = value.getUnsafeBytes();

        final Matcher matcher = pattern.matcher(bytes, begin, range);

        RubyArray result = runtime.newArray();
        Encoding enc = getEncodingForKCodeDefault(runtime, pattern, pat);

        boolean captures = pattern.numberOfCaptures() != 0;

        int end, beg = 0;
        boolean lastNull = false;
        int start = begin;
        while ((end = matcher.search(start, range, Option.NONE)) >= 0) {
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);
                } 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(reads = BACKREF, writes = BACKREF, compat = RUBY1_8)
    public IRubyObject scan(ThreadContext context, IRubyObject arg, Block block) {
        Ruby runtime = context.runtime;
        Encoding enc = runtime.getKCode().getEncoding();
        final Regex pattern;
        final int tuFlags;
        if (arg instanceof RubyRegexp) {
            RubyRegexp regex = (RubyRegexp)arg;
            pattern = regex.getPattern();
            tuFlags = regex.flags;
        } else {
            pattern = getStringPattern(runtime, enc, arg);
            if (arg.isTaint()) {
              tuFlags = RubyBasicObject.TAINTED_F;
            }
            else {
              tuFlags = 0;
            }
        }

        int begin = value.getBegin();
        int range = begin + value.getRealSize();
        final Matcher matcher = pattern.matcher(value.getUnsafeBytes(), begin, range);

        if (block.isGiven()) {
            return scanIter(context, pattern, matcher, enc, block, begin, range, tuFlags);
        } else {
            return scanNoIter(context, pattern, matcher, enc, begin, range, tuFlags);
View Full Code Here

    @JRubyMethod(name = "scan", reads = BACKREF, writes = BACKREF, compat = RUBY1_9)
    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 = 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.