Examples of Regex


Examples of org.joni.Regex

        return regex;
    }

    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;
    }
View Full Code Here

Examples of org.joni.Regex

                    continue again;
                }

                if (bytes[p] == ':' && bytes[p + len - 1] == ')') {
                    try {
                        new Regex(bytes, ++p, p + (len -= 2), Option.DEFAULT, getEncoding(runtime, str), Syntax.DEFAULT);
                        err = false;
                    } catch (JOniException e) {
                        err = true;
                    }
                }
View Full Code Here

Examples of org.joni.Regex

   
    private IRubyObject scan(IRubyObject regex, boolean succptr, boolean getstr, boolean headonly) {
        if (!(regex instanceof RubyRegexp)) throw getRuntime().newTypeError("wrong argument type " + regex.getMetaClass() + " (expected Regexp)");
        check();
       
        Regex pattern = ((RubyRegexp)regex).getPattern();

        clearMatched();
        int rest = str.getByteList().getRealSize() - pos;
        if (rest < 0) return getRuntime().getNil();

        ByteList value = str.getByteList();
        Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin() + pos, value.getBegin() + value.getRealSize());

        final int ret;
        if (headonly) {
            ret = matcher.match(value.getBegin() + pos, value.getBegin() + value.getRealSize(), Option.NONE);
        } else {
View Full Code Here

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.getRuntime();
        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

Examples of org.joni.Regex

    public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
        Ruby runtime = context.getRuntime();
        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

Examples of org.joni.Regex

    }

    private IRubyObject gsubCommon(ThreadContext context, final boolean bang, IRubyObject arg, Block block, RubyString repl, int tuFlags) {
        Ruby runtime = context.getRuntime();
        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

Examples of org.joni.Regex

    private IRubyObject gsubCommon19(ThreadContext context, Block block, RubyString repl,
            RubyHash hash, IRubyObject arg0, final boolean bang, int tuFlags) {
        Ruby runtime = context.getRuntime();

        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

Examples of org.joni.Regex

        return result;
    }

    private RubyArray regexSplit(ThreadContext context, IRubyObject pat, boolean limit, int lim, int i) {
        Ruby runtime = context.getRuntime();
        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

Examples of org.joni.Regex

            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.getRuntime(), 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;
                final RubyRegexp regexp;
                Ruby runtime = context.getRuntime();
                if (spat instanceof RubyRegexp) {
                    regexp = (RubyRegexp)spat;
                    pattern = regexp.getPattern();
View Full Code Here

Examples of org.joni.Regex

     */
    @JRubyMethod(reads = BACKREF, writes = BACKREF, compat = RUBY1_8)
    public IRubyObject scan(ThreadContext context, IRubyObject arg, Block block) {
        Ruby runtime = context.getRuntime();
        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
TOP
Copyright © 2018 www.massapi.com. 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.