Package org.jruby

Class RubyEncoding

All Implemented Interfaces:
Serializable, Cloneable, Comparable<IRubyObject>, Constantizable, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType

public class RubyEncoding extends RubyObject implements Constantizable
See Also:
  • Field Details

    • UTF8

      public static final Charset UTF8
    • UTF16

      public static final Charset UTF16
    • ISO

      public static final Charset ISO
    • LOCALE

      public static final ByteList LOCALE
    • EXTERNAL

      public static final ByteList EXTERNAL
    • FILESYSTEM

      public static final ByteList FILESYSTEM
    • INTERNAL

      public static final ByteList INTERNAL
    • BINARY_ASCII_NAME

      public static final ByteList BINARY_ASCII_NAME
    • UNICODE_VERSION

      public static final String UNICODE_VERSION
      See Also:
  • Method Details

    • createEncodingClass

      public static RubyClass createEncodingClass(ThreadContext context, RubyClass Object)
    • constant

      public Object constant()
      Specified by:
      constant in interface Constantizable
      See Also:
    • newEncoding

      public static RubyEncoding newEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy)
    • getEncoding

      public final org.jcodings.Encoding getEncoding()
    • areCompatible

      public static org.jcodings.Encoding areCompatible(IRubyObject obj1, IRubyObject obj2)
    • areCompatible

      public static org.jcodings.Encoding areCompatible(org.jcodings.Encoding enc1, int cr1, org.jcodings.Encoding enc2, int cr2)
    • encodeUTF8

      public static byte[] encodeUTF8(String str)
    • encodeUTF8

      public static byte[] encodeUTF8(CharSequence str)
    • encodeISO

      public static byte[] encodeISO(CharSequence str)
    • encodeISO

      public static byte[] encodeISO(char[] str)
    • encodeUTF16

      public static byte[] encodeUTF16(String str)
    • encodeUTF16

      public static byte[] encodeUTF16(CharSequence str)
    • encode

      public static byte[] encode(CharSequence cs, Charset charset)
    • encode

      public static byte[] encode(String str, Charset charset)
    • decodeUTF8

      public static String decodeUTF8(byte[] bytes, int start, int length)
      Decode the range of bytes specified as UTF-8 content. This will attempt to use a zero-allocation decoder if the content length is shorter than CHAR_THRESHOLD bytes, and otherwise will used cached decoders to avoid reallocating Charset-related objects.
      Parameters:
      bytes - the byte array
      start - start of content
      length - length of content
      Returns:
      a decoded String based on UTF-8 bytes
    • decodeRaw

      public static String decodeRaw(byte[] bytes, int start, int length)
      Decode the range of bytes specified as "raw" binary content, as in ISO-8859-1 or ASCII-8BIT encodings. This will attempt to use a zero-allocation decoder if the content length is shorter than CHAR_THRESHOLD bytes, and otherwise will used cached decoders to avoid reallocating Charset-related objects.
      Parameters:
      bytes - the byte array
      start - start of content
      length - length of content
      Returns:
      a decoded String based on raw bytes
    • decodeRaw

      public static String decodeRaw(ByteList byteList)
      Decode the specified bytelist as "raw" binary content. This is the same as calling decodeRaw(byte[], int, int) with the contents of byteList.
      Parameters:
      byteList -
      Returns:
      a decoded string based on raw bytes
    • decodeUTF8

      public static String decodeUTF8(byte[] bytes)
    • decode

      public static String decode(byte[] bytes, int start, int length, Charset charset)
    • decode

      public static String decode(byte[] bytes, Charset charset)
    • checkEncoding

      public static org.jcodings.Encoding checkEncoding(ThreadContext context, org.jcodings.Encoding encoding, CodeRangeable other)
      Check whether the given encoding and the encoding from the given CodeRangeable are compatible. This version differs from RubyString.checkEncoding(CodeRangeable) in that the contents of the first encoding's string are not taken into consideration (e.g. blank first string does not skip compatibility check with second string's encoding). See rb_enc_check in CRuby and use from stringio that passes encoding instead of string for the first argument. See https://github.com/ruby/stringio/pull/116 for some discussion MRI: rb_enc_check with encoding for first parameter
      Parameters:
      context - the current thread context
      encoding - the first encoding
      other - the CodeRangeable from which to get bytes and the second encoding
      Returns:
      a negotiated encoding, if compatible; null otherwise
    • list

      public static IRubyObject list(ThreadContext context, IRubyObject recv)
    • locale_charmap

      public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv)
    • name_list

      public static IRubyObject name_list(ThreadContext context, IRubyObject recv)
    • aliases

      public static IRubyObject aliases(ThreadContext context, IRubyObject recv)
    • find

      public static IRubyObject find(ThreadContext context, IRubyObject recv, IRubyObject str)
    • replicate

      @Deprecated(since="10.0.0.0") public IRubyObject replicate(ThreadContext context, IRubyObject arg)
      Deprecated.
    • _dump

      public IRubyObject _dump(ThreadContext context, IRubyObject arg)
    • _load

      public static IRubyObject _load(ThreadContext context, IRubyObject recv, IRubyObject str)
    • asciiCompatible_p

      public IRubyObject asciiCompatible_p(ThreadContext context)
    • to_s

      public IRubyObject to_s(ThreadContext context)
      Overrides:
      to_s in class RubyBasicObject
    • inspect

      public IRubyObject inspect(ThreadContext context)
      Description copied from class: RubyBasicObject
      Returns a string containing a human-readable representation of obj. If not overridden, uses the to_s method to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"
      Specified by:
      inspect in interface IRubyObject
      Overrides:
      inspect in class RubyBasicObject
    • names

      public IRubyObject names(ThreadContext context)
    • dummy_p

      public IRubyObject dummy_p(ThreadContext context)
    • compatible_p

      public static IRubyObject compatible_p(ThreadContext context, IRubyObject self, IRubyObject first, IRubyObject second)
    • getDefaultExternal

      public static IRubyObject getDefaultExternal(ThreadContext context, IRubyObject recv)
    • setDefaultExternal

      public static IRubyObject setDefaultExternal(ThreadContext context, IRubyObject recv, IRubyObject encoding)
    • getDefaultInternal

      public static IRubyObject getDefaultInternal(ThreadContext context, IRubyObject recv)
    • setDefaultInternal

      public static IRubyObject setDefaultInternal(ThreadContext context, IRubyObject recv, IRubyObject encoding)