Package org.jruby.runtime.builtin

Examples of org.jruby.runtime.builtin.IRubyObject.convertToString()


   
    private static IRubyObject str_to_r_strict(ThreadContext context, IRubyObject recv) {
        RubyArray a = str_to_r_internal(context, recv);
        if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
            IRubyObject s = recv.callMethod(context, "inspect");
            throw context.getRuntime().newArgumentError("invalid value for convert(): " + s.convertToString());
        }
        return a.eltInternal(0);
    }   
}
View Full Code Here


                    // We do this b/c make_tmpname might be overridden
                    IRubyObject tmpname = callMethod(runtime.getCurrentContext(),
                                                     "make_tmpname", new IRubyObject[] {basename, runtime.newFixnum(counter)});
                    tmp = JRubyFile.create(getRuntime().getCurrentDirectory(),
                                           new File(dir.convertToString().toString(), tmpname.convertToString().toString()).getPath());
                    if (tmp.createNewFile()) {
                        tmpFile = tmp;
                        path = tmp.getPath();
                        try {
                            tmpFile.deleteOnExit();
View Full Code Here

                        IRubyObject from = list.eltInternal(idx++);
                        if(from.isTaint()) {
                            taintOutput = true;
                        }
                        lCurElemString = from == runtime.getNil() ? ByteList.EMPTY_BYTELIST : from.convertToString().getByteList();

                        if (isStar) {
                            occurrences = lCurElemString.length();
                            // 'Z' adds extra null pad (versus 'a')
                            if (type == 'Z') occurrences++;
View Full Code Here

                            throw runtime.newArgumentError(sTooFew);
                        }
                        IRubyObject from = list.eltInternal(idx++);
                        lCurElemString = from == runtime.getNil() ?
                            ByteList.EMPTY_BYTELIST :
                            from.convertToString().getByteList();
                        if (runtime.is1_9() && occurrences == 0 && type == 'm' && !ignoreStar) {
                            encodes(runtime, result, lCurElemString.getUnsafeBytes(),
                                    lCurElemString.getBegin(), lCurElemString.length(),
                                    lCurElemString.length(), (byte)type, false);
                            break;
View Full Code Here

     * Queries <code>JSON.create_id</code>. Returns <code>null</code> if it is
     * set to <code>nil</code> or <code>false</code>, and a String if not.
     */
    private RubyString getCreateId(ThreadContext context) {
        IRubyObject v = info.jsonModule.get().callMethod(context, "create_id");
        return v.isTrue() ? v.convertToString() : null;
    }

    /**
     * A string parsing session.
     *
 
View Full Code Here

    RubyString getString(String key, RubyString defaultValue) {
        IRubyObject value = get(key);
        if (value == null || !value.isTrue()) return defaultValue;

        RubyString str = value.convertToString();
        RuntimeInfo info = getRuntimeInfo();
        if (info.encodingsSupported() && str.encoding(context) != info.utf8.get()) {
            str = (RubyString)str.encode(context, info.utf8.get());
        }
        return str;
View Full Code Here

                        }

                        IRubyObject from = list.eltInternal(idx++);
                        if(from.isTaint()) taintOutput = true;

                        lCurElemString = from == runtime.getNil() ? ByteList.EMPTY_BYTELIST : from.convertToString().getByteList();

                        if (isStar) {
                            occurrences = lCurElemString.length();
                            // 'Z' adds extra null pad (versus 'a')
                            if (type == 'Z') occurrences++;
View Full Code Here

                case 'm' : {
                        if (listSize-- <= 0) throw runtime.newArgumentError(sTooFew);

                        IRubyObject from = list.eltInternal(idx++);
                        if (from == runtime.getNil()) throw runtime.newTypeError(from, "Integer");
                        lCurElemString = from.convertToString().getByteList();
                        if (runtime.is1_9() && occurrences == 0 && type == 'm' && !ignoreStar) {
                            encodes(runtime, result, lCurElemString.getUnsafeBytes(),
                                    lCurElemString.getBegin(), lCurElemString.length(),
                                    lCurElemString.length(), (byte)type, false);
                            break;
View Full Code Here

        CodingErrorAction onUnmappableCharacter = CodingErrorAction.REPORT;
        RubyString replaceWith = null;
           
        IRubyObject replace = hash.fastARef(runtime.newSymbol("replace"));
        if (replace != null && !replace.isNil()) {
            RubyString replaceWithStr = replace.convertToString();
            if (replaceWithStr.size() == 1) { // we can only replaceWith a single char
                replaceWith = replaceWithStr;
            }
        }
           
View Full Code Here

   
    private static IRubyObject str_to_r_strict(ThreadContext context, IRubyObject recv) {
        RubyArray a = str_to_r_internal(context, recv);
        if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
            IRubyObject s = recv.callMethod(context, "inspect");
            throw context.runtime.newArgumentError("invalid value for convert(): " + s.convertToString());
        }
        return a.eltInternal(0);
    }   
}
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.