Package org.jruby

Examples of org.jruby.RubyString


            if (s.length() > 0) {
                return Character.valueOf(s.charAt(0));
            }
            return Character.valueOf('\0');
        } else if (javaClass == String.class) {
            RubyString rubyString = (RubyString) rubyObject.callMethod(context, "to_s");
            ByteList bytes = rubyString.getByteList();
            return RubyEncoding.decodeUTF8(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
        } else if (javaClass == ByteList.class) {
            return rubyObject.convertToString().getByteList();
        } else if (javaClass == BigInteger.class) {
           if (rubyObject instanceof RubyBignum) {
View Full Code Here


        return packCommon(runtime, list, formatString, false, executor18());
    }

    @SuppressWarnings("fallthrough")
    public static RubyString pack19(ThreadContext context, Ruby runtime, RubyArray list, RubyString formatString) {
        RubyString pack = packCommon(runtime, list, formatString.getByteList(), formatString.isTaint(), executor19());
        pack = (RubyString) pack.infectBy(formatString);

        for (IRubyObject element : list.toJavaArray()) {
            if (element.isUntrusted()) {
                pack = (RubyString) pack.untrust(context);
                break;
            }
        }

        return pack;
View Full Code Here

                    break;
            }
        }       

        RubyString output = runtime.newString(result);
        if(taintOutput) {
            output.taint(runtime.getCurrentContext());
        }

        if (runtime.is1_9()) {
            switch (enc_info)
            {
                case 1:
                    output.setEncodingAndCodeRange(USASCII, RubyObject.USER8_F);
                    break;
                case 2:
                    output.force_encoding(runtime.getCurrentContext(),
                            runtime.getEncodingService().convertEncodingToRubyEncoding(UTF8));
                    break;
                default:
                    /* do nothing, keep ASCII-8BIT */
            }
View Full Code Here

            string.append(node.interpret(runtime, context, self, aBlock));
        }
    }

    public RubyString buildDynamicString(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        RubyString string = allocateString(runtime);

        int size = size();
        for (int i = 0; i < size; i++) {
            appendToString(runtime, context, self, aBlock, string, get(i));
        }
View Full Code Here

     * @param runtime The ruby runtime
     * @param bytes The array to make into a ruby string.
     * @return A ruby string.
     */
    public static final RubyString newTaintedString(Ruby runtime, byte[] bytes) {
        RubyString s = RubyString.newStringNoCopy(runtime, bytes);
        s.setTaint(true);
        return s;
    }
View Full Code Here

    @JRubyMethod(required = 1, rest = true)
    public IRubyObject send(ThreadContext context, IRubyObject[] args) {
        try {
            int written;
            if (args.length >= 3) { // host and port given
                RubyString nameStr = args[2].convertToString();
                RubyString data = args[0].convertToString();
                ByteBuffer buf = ByteBuffer.wrap(data.getBytes());

                byte [] buf2 = data.getBytes();
                DatagramPacket sendDP = null;

                int port;
                if (args[3] instanceof RubyString) {
                    jnr.netdb.Service service = jnr.netdb.Service.getServiceByName(args[3].asJavaString(), "udp");
                    if (service != null) {
                        port = service.getPort();
                    } else {
                        port = (int)args[3].convertToInteger("to_i").getLongValue();
                    }
                } else {
                    port = (int)args[3].convertToInteger().getLongValue();
                }

                InetAddress address = RubySocket.getRubyInetAddress(nameStr.getByteList());
                InetSocketAddress addr =
                        new InetSocketAddress(address, port);

                if (this.multicastStateManager == null) {
                    written = ((DatagramChannel) this.getChannel()).send(buf, addr);
                }
                else {
                    sendDP = new DatagramPacket(buf2, buf2.length, address, port);
                    MulticastSocket ms = this.multicastStateManager.getMulticastSocket();
                    ms.send(sendDP);
                    written = sendDP.getLength();
                }
            } else {
                RubyString data = args[0].convertToString();
                ByteBuffer buf = ByteBuffer.wrap(data.getBytes());
                written = ((DatagramChannel) this.getChannel()).write(buf);
            }
            return context.getRuntime().newFixnum(written);
        } catch (UnknownHostException e) {
            throw sockerr(context.getRuntime(), "send: name or service not known");
View Full Code Here

        if(slen < buflen) {
            buflen = slen;
        }

        RubyString _str = context.getRuntime().newString(new ByteList(tmpbuf, 0, buflen, true));

        return context.getRuntime().newArrayNoCopy(new IRubyObject[]{_str, unixaddr(context.getRuntime(), buf, alen)});
    }
View Full Code Here

    public static class HistoryMethods {
        @JRubyMethod(name = {"push", "<<"}, rest = true)
        public static IRubyObject s_push(IRubyObject recv, IRubyObject[] lines) {
            ConsoleHolder holder = getHolder(recv.getRuntime());
            for (int i = 0; i < lines.length; i++) {
                RubyString line = lines[i].convertToString();
                holder.history.addToHistory(line.getUnicodeValue());
            }
            return recv.getRuntime().getNil();
        }
View Full Code Here

            this.channel = channel;
        }
       
        @JRubyMethod
        public static IRubyObject rbuf_fill(IRubyObject recv) {
            RubyString buf = (RubyString)recv.getInstanceVariables().getInstanceVariable("@rbuf");
            RubyIO io = (RubyIO)recv.getInstanceVariables().getInstanceVariable("@io");

            int timeout = RubyNumeric.fix2int(recv.getInstanceVariables().getInstanceVariable("@read_timeout")) * 1000;
            NativeImpl nim = (NativeImpl)recv.dataGetStruct();

            Selector selector = null;
            synchronized (nim.channel.blockingLock()) {
                boolean oldBlocking = nim.channel.isBlocking();

                try {
                    selector = SelectorFactory.openWithRetryFrom(recv.getRuntime(), SelectorProvider.provider());
                    nim.channel.configureBlocking(false);
                    SelectionKey key = nim.channel.register(selector, SelectionKey.OP_READ);
                    int n = selector.select(timeout);

                    if(n > 0) {
                        IRubyObject readItems = io.read(new IRubyObject[]{recv.getRuntime().newFixnum(1024*16)});
                        return buf.concat(readItems);
                    } else {
                        RubyClass exc = (RubyClass)(recv.getRuntime().getModule("Timeout").getConstant("Error"));
                        throw new RaiseException(RubyException.newException(recv.getRuntime(), exc, "execution expired"),false);
                    }
                } catch(IOException exception) {
View Full Code Here

    private RubyArray getLines(ParserConfiguration configuration, Ruby runtime, String file) {
        RubyArray list = null;
        IRubyObject scriptLines = runtime.getObject().fastGetConstantAt("SCRIPT_LINES__");
        if (!configuration.isEvalParse() && scriptLines != null) {
            if (scriptLines instanceof RubyHash) {
                RubyString filename = runtime.newString(file);
                ThreadContext context = runtime.getCurrentContext();
                IRubyObject object = ((RubyHash) scriptLines).op_aref(context, filename);
                list = (RubyArray) (object instanceof RubyArray ? object : runtime.newArray());
                ((RubyHash) scriptLines).op_aset(context, filename, list);
            }
View Full Code Here

TOP

Related Classes of org.jruby.RubyString

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.