Package org.jcodings

Examples of org.jcodings.Encoding


            // read. We checks readability first if possible so retry should
            // not be needed I believe.
            return runtime.getNil();
        }

        Encoding external = getExternalEncoding(runtime);
        ByteList bytes = fromEncodedBytes(runtime, external, (int) c);
        Encoding internal = getInternalEncoding(runtime);
       
        if (internal != null) {
            bytes = RubyString.transcode(context, bytes, external, internal, runtime.getNil());
        }
View Full Code Here


            return actualKey;
        }
       
        private IRubyObject normalizeEnvString(IRubyObject str) {
            if (str instanceof RubyString) {
                Encoding enc = getRuntime().getEncodingService().getLocaleEncoding();
                RubyString newStr = getRuntime().newString(new ByteList(str.toString().getBytes(), enc));
                newStr.setFrozen(true);
                return newStr;
            } else {
                return str;
View Full Code Here

        boolean escape = (flags & RubyYaccLexer.STR_FUNC_ESCAPE) != 0;
        boolean regexp = (flags & RubyYaccLexer.STR_FUNC_REGEXP) != 0;
        boolean symbol = (flags & RubyYaccLexer.STR_FUNC_SYMBOL) != 0;
        boolean hasNonAscii = false;
        int c;
        Encoding encoding = lexer.getEncoding();

        while ((c = src.read()) != RubyYaccLexer.EOF) {
            if (begin != '\0' && c == begin) {
                nest++;
            } else if (c == end) {
View Full Code Here

        int value = (int)getLongValue();
        if (value >= 0 && value <= 0xFF) {
            ByteList bytes = SINGLE_CHAR_BYTELISTS19[value];
            return RubyString.newStringShared(runtime, bytes, bytes.getEncoding());
        } else {
            Encoding enc = runtime.getDefaultInternalEncoding();
            if (value > 0xFF && (enc == null || enc == ASCIIEncoding.INSTANCE)) {
                throw runtime.newRangeError(this.toString() + " out of char range");
            } else {
                if (enc == null) enc = USASCIIEncoding.INSTANCE;
                return RubyString.newStringNoCopy(runtime, fromEncodedBytes(runtime, enc, (int)value), enc, 0);
View Full Code Here

    @JRubyMethod(name = "chr", compat = CompatVersion.RUBY1_9)
    public RubyString chr19(ThreadContext context, IRubyObject arg) {
        Ruby runtime = context.getRuntime();
        long value = getLongValue();
        Encoding enc;
        if (arg instanceof RubyEncoding) {
            enc = ((RubyEncoding)arg).getEncoding();
        } else {
            enc =  arg.convertToString().toEncoding(runtime);
        }
View Full Code Here

    public void setParserSupport(ParserSupport parserSupport) {
        this.parserSupport = parserSupport;
    }

    private void setEncoding(ByteList name) {
        Encoding newEncoding = parserSupport.getConfiguration().getEncodingService().loadEncoding(name);

        if (newEncoding == null) {
            throw new SyntaxException(PID.UNKNOWN_ENCODING, getPosition(),
                    null, "unknown encoding name: " + name.toString());
        }

        if (!newEncoding.isAsciiCompatible()) {
            throw new SyntaxException(PID.NOT_ASCII_COMPATIBLE, getPosition(),
                    null, name.toString() + " is not ASCII compatible");
        }

        setEncoding(newEncoding);
View Full Code Here

        return encoding.codeToMbcLength(c) != 1;
    }

    // STR_NEW3/parser_str_new
    public StrNode createStrNode(ISourcePosition position, ByteList buffer, int flags) {
        Encoding bufferEncoding = buffer.getEncoding();
        int codeRange = StringSupport.codeRangeScan(bufferEncoding, buffer);

        if ((flags & RubyYaccLexer.STR_FUNC_REGEXP) == 0 && bufferEncoding.isAsciiCompatible()) {
            // If we have characters outside 7-bit range and we are still ascii then change to ascii-8bit
            if (codeRange == StringSupport.CR_7BIT) {
                // Do nothing like MRI
            } else if (getEncoding() == RubyYaccLexer.USASCII_ENCODING &&
                    bufferEncoding != RubyYaccLexer.UTF8_ENCODING) {
View Full Code Here

    }

    static Regex getQuotedRegexpFromCache19(Ruby runtime, ByteList bytes, RegexpOptions options, boolean asciiOnly) {
        Map<ByteList, Regex> cache = quotedPatternCache.get();
        Regex regex = cache.get(bytes);
        Encoding enc = asciiOnly ? USASCIIEncoding.INSTANCE : bytes.getEncoding();
        if (regex != null && regex.getEncoding() == enc && regex.getOptions() == options.toJoniOptions()) return regex;
        ByteList quoted = quote19(bytes, asciiOnly);
        regex = makeRegexp(runtime, quoted, options, quoted.getEncoding());
        regex.setUserObject(quoted);
        cache.put(bytes, regex);
View Full Code Here

        if (str.scanForCodeRange() == StringSupport.CR_BROKEN) {
            // FIXME: This should be here, but various specs fail...we must have a coderange scan bug somewhere
           // throw getRuntime().newArgumentError("invalid byte sequence in " + str.getEncoding());
        }
        check();
        Encoding enc = str.getEncoding();
        if (!enc.isAsciiCompatible()) {
            if (enc != pattern.getEncoding()) encodingMatchError(getRuntime(), pattern, enc);
        } else if (options.isFixed()) {
            if (enc != pattern.getEncoding() &&
               (!pattern.getEncoding().isAsciiCompatible() ||
               str.scanForCodeRange() != StringSupport.CR_7BIT)) encodingMatchError(getRuntime(), pattern, enc);
View Full Code Here

        return enc;
    }

    final Regex preparePattern(RubyString str) {
        check();
        Encoding enc = checkEncoding(str, true);
        if (enc == pattern.getEncoding()) return pattern;
        return getPreprocessedRegexpFromCache(getRuntime(), this.str, enc, options, ErrorMode.PREPROCESS);
    }
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.