Package org.jcodings

Examples of org.jcodings.Encoding


        }
        return append19(other);
    }

    private RubyString concatNumeric(Ruby runtime, int c) {
        Encoding enc = value.getEncoding();
        int cl = codeLength(runtime, enc, c);
        modify19(value.getRealSize() + cl);
        enc.codeToMbc(c, value.getUnsafeBytes(), value.getBegin() + value.getRealSize());
        value.setRealSize(value.getRealSize() + cl);
        return this;
    }
View Full Code Here


    private IRubyObject subBangIter19(Ruby runtime, ThreadContext context, Regex pattern, Regex prepared, RubyHash hash, Block block, RubyRegexp regexp) {
        int begin = value.getBegin();
        int len = value.getRealSize();
        int range = begin + len;
        byte[]bytes = value.getUnsafeBytes();
        Encoding enc = value.getEncoding();
        final Matcher matcher = prepared.matcher(bytes, begin, range);

        DynamicScope scope = context.getCurrentScope();
        if (matcher.search(begin, range, Option.NONE) >= 0) {
            RubyMatchData match = RubyRegexp.updateBackRef19(context, this, scope, matcher, pattern);
View Full Code Here

    private IRubyObject subBangCommon19(ThreadContext context, Regex pattern, Matcher matcher, RubyString repl, int tuFlags) {
        final int beg = matcher.getBegin();      
        final int end = matcher.getEnd();

        Encoding enc = isCompatibleWith(repl);
        if (enc == null) enc = subBangVerifyEncoding(context, repl, beg, end);

        final int plen = end - beg;
        ByteList replValue = repl.value;
        if (replValue.getRealSize() > plen) {
View Full Code Here

    private Encoding subBangVerifyEncoding(ThreadContext context, RubyString repl, int beg, int end) {
        byte[]bytes = value.getUnsafeBytes();
        int p = value.getBegin();
        int len = value.getRealSize();
        Encoding strEnc = value.getEncoding();
        if (codeRangeScan(strEnc, bytes, p, beg) != CR_7BIT ||
            codeRangeScan(strEnc, bytes, p + end, len - end) != CR_7BIT) {
            throw context.getRuntime().newArgumentError(
                    "incompatible character encodings " + strEnc + " and " + repl.value.getEncoding());
        }
View Full Code Here

        int blen = slen + 30; /* len + margin */
        ByteList dest = new ByteList(blen);
        dest.setRealSize(blen);
        int offset = 0, buf = 0, bp = 0, cp = begin;

        Encoding enc = getEncodingForKCodeDefault(runtime, pattern, arg);

        RubyMatchData match = null;
        while (beg >= 0) {
            final RubyString val;
            final int begz = matcher.getBegin();
            final int endz = matcher.getEnd();

            if (repl == null) { // block given
                match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
                val = objAsString(context, block.yield(context, substr(runtime, begz, endz - begz)));
                modifyCheck(bytes, slen);
                if (bang) frozenCheck();
            } else {
                val = RubyRegexp.regsub(repl, this, matcher, enc);
            }

            tuFlags |= val.flags;

            ByteList vbuf = val.value;
            int len = (bp - buf) + (beg - offset) + vbuf.getRealSize() + 3;
            if (blen < len) {
                while (blen < len) blen <<= 1;
                len = bp - buf;
                dest.realloc(blen);
                dest.setRealSize(blen);
                bp = buf + len;
            }
            len = beg - offset; /* copy pre-match substr */
            System.arraycopy(bytes, cp, dest.getUnsafeBytes(), bp, len);
            bp += len;
            System.arraycopy(vbuf.getUnsafeBytes(), vbuf.getBegin(), dest.getUnsafeBytes(), bp, vbuf.getRealSize());
            bp += vbuf.getRealSize();
            offset = endz;

            if (begz == endz) {
                if (slen <= endz) break;
                len = enc.length(bytes, begin + endz, range);
                System.arraycopy(bytes, begin + endz, dest.getUnsafeBytes(), bp, len);
                bp += len;
                offset = endz + len;
            }
            cp = begin + offset;
View Full Code Here

            return bang ? runtime.getNil() : strDup(runtime); /* bang: true, no match, no substitution */
        }

        RubyString dest = new RubyString(runtime, getMetaClass(), new ByteList(slen + 30));
        int offset = 0, cp = begin;
        Encoding enc = value.getEncoding();

        RubyMatchData match = null;
        do {
            final RubyString val;
            int begz = matcher.getBegin();
View Full Code Here

        return pos == -1 ? runtime.getNil() : RubyFixnum.newFixnum(runtime, pos);
    }

    private int strIndex19(RubyString sub, int offset) {
        Encoding enc = checkEncoding(sub);
        if (sub.scanForCodeRange() == CR_BROKEN) return -1;
        int len = strLength(enc);
        int slen = sub.strLength(enc);
        if (offset < 0) {
            offset += len;
            if (offset < 0) return -1;
        }

        if (len - offset < slen) return -1;
        byte[]bytes = value.getUnsafeBytes();
        int p = value.getBegin();
        int end = p + value.getRealSize();
        if (offset != 0) {
            offset = singleByteOptimizable() ? offset : StringSupport.offset(enc, bytes, p, end, offset);
            p += offset;
        }
        if (slen == 0) return offset;

        while (true) {
            int pos = value.indexOf(sub.value, p - value.getBegin());
            if (pos < 0) return pos;
            pos -= (p - value.getBegin());
            int t = enc.rightAdjustCharHead(bytes, p, p + pos, end);
            if (t == p + pos) return pos + offset;
            if ((len -= t - p) <= 0) return -1;
            offset += t - p;
            p = t;
        }
View Full Code Here

        if (pos >= 0) return RubyFixnum.newFixnum(runtime, pos);
        return runtime.getNil();
    }

    private int strRindex19(RubyString sub, int pos) {
        Encoding enc = checkEncoding(sub);
        if (sub.scanForCodeRange() == CR_BROKEN) return -1;
        int len = strLength(enc);
        int slen = sub.strLength(enc);

        if (len < slen) return -1;
View Full Code Here

    public final IRubyObject substr19(Ruby runtime, int beg, int len) {
        if (len < 0) return runtime.getNil();
        int length = value.getRealSize();
        if (length == 0) len = 0;

        Encoding enc = value.getEncoding();
        if (singleByteOptimizable(enc)) {
            if (beg > length) return runtime.getNil();
            if (beg < 0) {
                beg += length;
                if (beg < 0) return runtime.getNil();
View Full Code Here

        value.setRealSize(newLength);
        return infectBy(repl);
    }

    private void replaceInternal19(int beg, int len, RubyString repl) {
        Encoding enc = checkEncoding(repl);
        int p = value.getBegin();
        int e;
        if (singleByteOptimizable()) {
            p += beg;
            e = p + len;
View Full Code Here

TOP

Related Classes of org.jcodings.Encoding

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.