Sha256: 6ad3baf01fbea62d02b5f44f90d68ff3885d9a7c4686c36ed6f1b23af9d609af

Contents?: true

Size: 973 Bytes

Versions: 3

Compression:

Stored size: 973 Bytes

Contents

package org.jruby.jubilee.utils;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyString;
import org.jruby.util.ByteList;

/**
 * Ruby reflection helper utilities.
 *
 * @author Bob McWhirter <bmcwhirt@redhat.com>
 */
public class RubyHelper {

    public static final RubyString toUsAsciiRubyString(final Ruby runtime, final String string) {
        byte[] bytes = new byte[string.length()];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) string.charAt(i);
        }
        return toUsAsciiRubyString(runtime, bytes);
    }

    public static final RubyString toUsAsciiRubyString(final Ruby runtime, final byte[] bytes) {
        return RubyString.newString(runtime, new ByteList(bytes, USASCIIEncoding.INSTANCE, false));
    }

    public static final RubyString toUnicodeRubyString(final Ruby runtime, final String string) {
        return RubyString.newUnicodeString(runtime, string);
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jubilee-3.0.0.beta2-java src/main/java/org/jruby/jubilee/utils/RubyHelper.java
jubilee-2.1.0.rc1-java src/main/java/org/jruby/jubilee/utils/RubyHelper.java
jubilee-2.1.0.beta-java java/src/org/jruby/jubilee/utils/RubyHelper.java