Package org.jruby.util

Examples of org.jruby.util.ByteList


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

        ByteList value = str.getByteList();
        Matcher matcher = pattern.matcher(value.bytes, value.begin + pos, value.begin + value.realSize);

        final int ret;
        if (headonly) {
            ret = matcher.match(value.begin + pos, value.begin + value.realSize, Option.NONE);           
View Full Code Here


    public IRubyObject getch(ThreadContext context) {
        check();
        clearMatched();
       
        Ruby runtime = context.getRuntime();
        ByteList value = str.getByteList();
       
        if (pos >= value.realSize) return runtime.getNil();

        Encoding enc = runtime.getKCode().getEncoding();
       
View Full Code Here

        int len = RubyNumeric.num2int(length);
        if (len < 0) {
            throw context.getRuntime().newArgumentError("negative string size (or size too big)");
        }

        ByteList value = str.getByteList();
        if (pos >= value.realSize) return RubyString.newEmptyString(getRuntime()).infectBy(str);
        if (pos + len > value.realSize) len = value.realSize - pos;

        return extractBegLen(context.getRuntime(), pos, len);
    }
View Full Code Here

    }
   
    @JRubyMethod(name = "beginning_of_line?", alias = "bol?")
    public IRubyObject bol_p() {
        check();
        ByteList value = str.getByteList();
        if (pos > value.realSize) return getRuntime().getNil();
        if (pos == 0) return getRuntime().getTrue();
        return value.bytes[(value.begin + pos) - 1] == (byte)'\n' ? getRuntime().getTrue() : getRuntime().getFalse();       
    }
View Full Code Here

    }
   
    @JRubyMethod(name = "rest")
    public IRubyObject rest(ThreadContext context) {
        check();
        ByteList value = str.getByteList();
        if (pos >= value.realSize) return RubyString.newEmptyString(context.getRuntime()).infectBy(str);
        return extractRange(context.getRuntime(), pos, value.realSize);
    }
View Full Code Here

    }
   
    @JRubyMethod(name = "rest_size")
    public RubyFixnum rest_size() {
        check();
        ByteList value = str.getByteList();
        if (pos >= value.realSize) return RubyFixnum.zero(getRuntime());
        return RubyFixnum.newFixnum(getRuntime(), value.realSize - pos);
    }
View Full Code Here

     */
    @JRubyMethod(name = {"fnmatch", "fnmatch?"}, required = 2, optional = 1, meta = true)
    public static IRubyObject fnmatch(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
        int flags = args.length == 3 ? RubyNumeric.num2int(args[2]) : 0;

        ByteList pattern = args[0].convertToString().getByteList();
        ByteList path = args[1].convertToString().getByteList();

        if (org.jruby.util.Dir.fnmatch(pattern.bytes, pattern.begin, pattern.begin+pattern.realSize,
                                       path.bytes, path.begin, path.begin+path.realSize, flags) == 0) {
            return context.getRuntime().getTrue();
        }
View Full Code Here

        if (!(byteArray instanceof JavaArray &&
                ((JavaArray)byteArray).getValue() instanceof byte[])) {
            throw runtime.newTypeError("wrong argument type " + wrappedObject.getMetaClass() +
                    " (expected byte[])");
        }
        return runtime.newString(new ByteList((byte[])((JavaArray)byteArray).getValue(), true));
    }
View Full Code Here

    private IRubyObject _iconv(RubyString str, int start, int end) {
        if (fromEncoding == null) {
            throw getRuntime().newArgumentError("closed iconv");
        }
       
        ByteList bytes = str.getByteList();
       
        // treat start and end as start...end for end >= 0, start..end for end < 0
        if (start < 0) {
            start += bytes.length();
        }
       
        if (end < 0) {
            end += 1 + bytes.length();
        } else if (end > bytes.length()) {
            end = bytes.length();
        }
       
        if (start < 0 || end < start) { // invalid ranges result in an empty string
            return RubyString.newEmptyString(getRuntime());
        }
       
        ByteBuffer buf = ByteBuffer.wrap(bytes.unsafeBytes(), bytes.begin() + start, end - start);
       
        try {
            CharBuffer cbuf = fromEncoding.decode(buf);
            buf = toEncoding.encode(cbuf);
        } catch (MalformedInputException e) {
        } catch (UnmappableCharacterException e) {
        } catch (CharacterCodingException e) {
            throw getRuntime().newInvalidEncoding("invalid sequence");
        } catch (IllegalStateException e) {
        }
        byte[] arr = buf.array();
       
        return getRuntime().newString(new ByteList(arr, 0, buf.limit()));
    }
View Full Code Here

        this.runtime = runtime;
    }

    public Object constructRubyScalar(final Node node) {
        if(node instanceof org.jvyamlb.nodes.ScalarNode) {
            ByteList sc = (ByteList)super.constructScalar(node);
            if(sc.length() > 1 && sc.charAt(0) == ':' && ((org.jvyamlb.nodes.ScalarNode)node).getStyle() == 0) {
                int first = sc.get(1);
                int last = sc.get(sc.realSize-1);
                if((first == '"' && last == '"') ||
                   (first == '\'' && last == '\'')) {

                    Scanner scn = new ScannerImpl(sc.makeShared(1, sc.realSize-1));
                    Constructor ctor = new JRubyConstructor(runtime, new ComposerImpl(new ParserImpl(scn,YAML.config().version("1.0")),new ResolverImpl()));
                    ctor.checkData();
                    return ((RubyString)ctor.getData()).intern();
                }
View Full Code Here

TOP

Related Classes of org.jruby.util.ByteList

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.