Class EncodingUtils

java.lang.Object
org.jruby.util.io.EncodingUtils

public class EncodingUtils extends Object
  • Field Details

  • Constructor Details

    • EncodingUtils

      public EncodingUtils()
  • Method Details

    • rbToEncoding

      public static org.jcodings.Encoding rbToEncoding(ThreadContext context, IRubyObject enc)
    • toEncoding

      public static org.jcodings.Encoding toEncoding(ThreadContext context, IRubyObject enc)
    • openArgsToArgs

      public static IRubyObject[] openArgsToArgs(Ruby runtime, IRubyObject firstElement, RubyHash options)
    • extractBinmode

      public static void extractBinmode(Ruby runtime, IRubyObject optionsArg, int[] fmode_p)
    • hashARef

      private static IRubyObject hashARef(Ruby runtime, IRubyObject hash, String symbol)
    • ascii8bitEncoding

      public static org.jcodings.Encoding ascii8bitEncoding(Ruby runtime)
    • vmodeVperm

      public static Object vmodeVperm(IRubyObject vmode, IRubyObject vperm)
    • vmode

      public static IRubyObject vmode(Object vmodeVperm)
    • vmode

      public static void vmode(Object vmodeVperm, IRubyObject vmode)
    • vperm

      public static IRubyObject vperm(Object vmodeVperm)
    • vperm

      public static void vperm(Object vmodeVperm, IRubyObject vperm)
    • MODE_BTMODE

      public static final int MODE_BTMODE(int fmode, int a, int b, int c)
    • SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2

      public static int SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(org.jcodings.Encoding enc2, int ecflags)
    • extractModeEncoding

      public static void extractModeEncoding(ThreadContext context, IOEncodable ioEncodable, Object vmodeAndVperm_p, IRubyObject options, int[] oflags_p, int[] fmode_p)
    • ioExtractEncodingOption

      public static boolean ioExtractEncodingOption(ThreadContext context, IOEncodable ioEncodable, IRubyObject options, int[] fmode_p)
    • newExternalStringWithEncoding

      public static RubyString newExternalStringWithEncoding(Ruby runtime, String string, org.jcodings.Encoding encoding)
    • newExternalStringWithEncoding

      public static RubyString newExternalStringWithEncoding(Ruby runtime, ByteList bytelist, org.jcodings.Encoding encoding)
    • ioExtIntToEncs

      public static void ioExtIntToEncs(ThreadContext context, IOEncodable encodable, org.jcodings.Encoding external, org.jcodings.Encoding internal, int fmode)
    • parseModeEncoding

      public static void parseModeEncoding(ThreadContext context, IOEncodable ioEncodable, String option, int[] fmode_p)
    • econvStrConvert

      public static ByteList econvStrConvert(ThreadContext context, org.jcodings.transcode.EConv ec, ByteList src, int flags)
    • econvByteConvert

      public static ByteList econvByteConvert(ThreadContext context, org.jcodings.transcode.EConv ec, byte[] bytes, int start, int length, int flags)
    • econvSubstrAppend

      public static ByteList econvSubstrAppend(ThreadContext context, org.jcodings.transcode.EConv ec, ByteList src, ByteList dst, int flags)
    • econvAppend

      public static ByteList econvAppend(ThreadContext context, org.jcodings.transcode.EConv ec, ByteList sByteList, ByteList dst, int flags)
    • econvAppend

      public static ByteList econvAppend(ThreadContext context, org.jcodings.transcode.EConv ec, byte[] bytes, int start, int length, ByteList dst, int flags)
    • econvCheckError

      public static void econvCheckError(ThreadContext context, org.jcodings.transcode.EConv ec)
    • econvPrepareOpts

      public static int econvPrepareOpts(ThreadContext context, IRubyObject opthash, IRubyObject[] opts)
    • econvPrepareOptions

      public static int econvPrepareOptions(ThreadContext context, IRubyObject opthash, IRubyObject[] opts, int ecflags)
    • econvOpts

      public static int econvOpts(ThreadContext context, IRubyObject opt, int ecflags)
    • econvOpenOpts

      public static org.jcodings.transcode.EConv econvOpenOpts(ThreadContext context, byte[] sourceEncoding, byte[] destinationEncoding, int ecflags, IRubyObject opthash)
    • econvOpenExc

      public static RaiseException econvOpenExc(ThreadContext context, byte[] sourceEncoding, byte[] destinationEncoding, int ecflags)
    • econvDescription

      public static String econvDescription(ThreadContext context, byte[] sourceEncoding, byte[] destinationEncoding, int ecflags, String message)
    • econvAsciicompatEncoding

      public static org.jcodings.Encoding econvAsciicompatEncoding(org.jcodings.Encoding enc)
    • encAsciicompat

      public static boolean encAsciicompat(org.jcodings.Encoding enc)
    • encAscget

      public static int encAscget(byte[] pBytes, int p, int e, int[] len, org.jcodings.Encoding enc)
    • encMbminlen

      public static int encMbminlen(org.jcodings.Encoding encoding)
    • encDummy

      public static boolean encDummy(org.jcodings.Encoding enc)
    • encGet

      public static org.jcodings.Encoding encGet(ThreadContext context, IRubyObject obj)
    • encodingEqual

      public static boolean encodingEqual(byte[] enc1, byte[] enc2)
    • encArg

      public static org.jcodings.Encoding encArg(ThreadContext context, IRubyObject encval, byte[][] name_p, org.jcodings.Encoding[] enc_p)
    • toEncodingIndex

      public static org.jcodings.Encoding toEncodingIndex(ThreadContext context, IRubyObject enc)
    • encodedDup

      public static IRubyObject encodedDup(ThreadContext context, IRubyObject newstr, IRubyObject str, org.jcodings.Encoding encindex)
    • strEncodeAssociate

      public static IRubyObject strEncodeAssociate(ThreadContext context, IRubyObject str, org.jcodings.Encoding encidx)
    • encAssociateIndex

      public static IRubyObject encAssociateIndex(IRubyObject obj, org.jcodings.Encoding encidx)
    • strEncode

      public static IRubyObject strEncode(ThreadContext context, IRubyObject str, IRubyObject... args)
    • rbStrEncode

      public static IRubyObject rbStrEncode(ThreadContext context, IRubyObject str, IRubyObject to, int ecflags, IRubyObject ecopt)
    • rbByteEncode

      public static ByteList rbByteEncode(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding, int cr, org.jcodings.Encoding to, int ecflags, IRubyObject ecopt)
    • noDecorators

      protected static boolean noDecorators(int ecflags)
    • strTranscode

      public static org.jcodings.Encoding strTranscode(ThreadContext context, IRubyObject[] args, IRubyObject[] self_p)
    • strTranscode0

      public static org.jcodings.Encoding strTranscode0(ThreadContext context, int argc, IRubyObject[] args, IRubyObject[] self_p, int ecflags, IRubyObject ecopts)
    • objEncoding

      public static IRubyObject objEncoding(ThreadContext context, IRubyObject obj)
    • strTranscodeEncArgs

      public static org.jcodings.Encoding strTranscodeEncArgs(ThreadContext context, IRubyObject str, IRubyObject arg1, IRubyObject arg2, byte[][] sname_p, org.jcodings.Encoding[] senc_p, byte[][] dname_p, org.jcodings.Encoding[] denc_p)
    • encRegistered

      public static boolean encRegistered(byte[] name)
    • encCheckDuplication

      public static void encCheckDuplication(ThreadContext context, byte[] name)
    • encReplicate

      public static org.jcodings.Encoding encReplicate(ThreadContext context, byte[] name, org.jcodings.Encoding encoding)
    • defineDummyEncoding

      public static org.jcodings.Encoding defineDummyEncoding(ThreadContext context, byte[] name)
    • DECORATOR_P

      public static boolean DECORATOR_P(byte[] sname, byte[] dname)
    • strConvEncOpts

      public static ByteList strConvEncOpts(ThreadContext context, ByteList str, org.jcodings.Encoding fromEncoding, org.jcodings.Encoding toEncoding, int ecflags, IRubyObject ecopts)
    • strConvEncOpts

      public static RubyString strConvEncOpts(ThreadContext context, RubyString str, org.jcodings.Encoding fromEncoding, org.jcodings.Encoding toEncoding, int ecflags, IRubyObject ecopts)
      This will try and transcode the supplied ByteList to the supplied toEncoding. It will use forceEncoding as its encoding if it is supplied; otherwise it will use the encoding it has tucked away in the bytelist. This will return a new copy of a ByteList in the request encoding or die trying (ConverterNotFound). c: rb_str_conv_enc_opts
    • strConvEnc

      public static RubyString strConvEnc(ThreadContext context, RubyString value, org.jcodings.Encoding fromEncoding, org.jcodings.Encoding toEncoding)
    • strConvEnc

      public static ByteList strConvEnc(ThreadContext context, ByteList value, org.jcodings.Encoding fromEncoding, org.jcodings.Encoding toEncoding)
    • setStrBuf

      public static RubyString setStrBuf(Ruby runtime, IRubyObject obj, int len)
    • encodingNames

      public static List<String> encodingNames(byte[] name, int p, int end)
    • transcodeLoop

      public static void transcodeLoop(ThreadContext context, byte[] inBytes, org.jcodings.Ptr inPos, byte[] outBytes, org.jcodings.Ptr outPos, int inStop, int _outStop, ByteList destination, EncodingUtils.ResizeFunction resizeFunction, byte[] sname, byte[] dname, int ecflags, IRubyObject ecopts)
      Perform the inner transcoding loop.
      See Also:
      • This version will determine fallback function and encoding options from the given options object. MRI: transcode_loop Ruby-related bits
    • transcodeString

      public static ByteList transcodeString(String string, org.jcodings.Encoding toEncoding, int ecflags)
      A version of transcodeLoop for working without any Ruby runtime available. MRI: transcode_loop with no fallback and java.lang.String input
    • getUTF16ForPlatform

      public static org.jcodings.Encoding getUTF16ForPlatform()
    • transcodeLoop

      public static <Data> boolean transcodeLoop(org.jcodings.transcode.EConv ec, EncodingUtils.TranscodeFallback<Data> fallbackFunc, ThreadContext context, Data fallbackData, byte[] inBytes, org.jcodings.Ptr inPos, byte[] outBytes, org.jcodings.Ptr outPos, int inStop, int outStop, ByteList destination, EncodingUtils.ResizeFunction resizeFunction)
      Perform the inner transcoding loop. The data in inBytes will be transcoded from the source encoding to the destination, eventually replacing the contents of the given ByteList. Along the way, invalid characters may be handled by calling the fallback function (if non-null) with the given state and data. If the destination needs to be resized, use the given function to do so. Upon completion, destination will contain the resulting transcoded bytes. MRI: transcode_loop generified with EConv and fallback function provided
      Type Parameters:
      Data - type of data for the fallback function
      Parameters:
      ec - the encoding converter
      fallbackFunc - the fallback function for non-transcodable characters, or null if none
      context - runtime state to pass into the fallback
      fallbackData - call state to pass into the fallback
      inBytes - the incoming byte array
      inPos - the position from which to start in the incoming bytearray
      outBytes - the initial output byte array
      outPos - the position from which to start in the initial output byte array
      inStop - the position at which to stop in the input
      outStop - the number of bytes at which to stop in the output
      destination - the ByteList to hold the eventual output
      resizeFunction - a function to use to grow the destination
      Returns:
    • makeEconvException

      public static RaiseException makeEconvException(Ruby runtime, org.jcodings.transcode.EConv ec)
    • makeEConvExceptionSetEncs

      private static RaiseException makeEConvExceptionSetEncs(RaiseException exc, Ruby runtime, org.jcodings.transcode.EConv ec)
    • moreOutputBuffer

      static void moreOutputBuffer(ByteList destination, EncodingUtils.ResizeFunction resizeDestination, int maxOutput, org.jcodings.Ptr outStart, org.jcodings.Ptr outPos, org.jcodings.Ptr outStop)
    • ioSetEncodingByBOM

      public static void ioSetEncodingByBOM(ThreadContext context, RubyIO io)
    • ioStripBOM

      public static org.jcodings.Encoding ioStripBOM(ThreadContext context, RubyIO io)
    • validateEncodingBinmode

      public static void validateEncodingBinmode(ThreadContext context, int[] fmode_p, int ecflags, IOEncodable ioEncodable)
    • rbEncSetDefaultExternal

      public static void rbEncSetDefaultExternal(ThreadContext context, IRubyObject encoding)
    • rbEncSetDefaultInternal

      public static void rbEncSetDefaultInternal(ThreadContext context, IRubyObject encoding)
    • encSetDefaultEncoding

      public static boolean encSetDefaultEncoding(ThreadContext context, org.jcodings.Encoding[] def_p, IRubyObject encoding, String name)
    • defaultExternalEncoding

      public static org.jcodings.Encoding defaultExternalEncoding(Ruby runtime)
    • rbStrBufCat

      public static void rbStrBufCat(Ruby runtime, RubyString str, ByteList ptr)
    • rbStrBufCat

      public static void rbStrBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len)
    • rbStrBufCat

      public static void rbStrBufCat(Ruby runtime, ByteList str, byte[] ptrBytes, int ptr, int len)
    • strBufCat

      public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr)
    • strBufCat

      public static void strBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len)
    • strBufCat

      public static void strBufCat(ByteList str, byte[] ptrBytes, int ptr, int len)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, ByteList ptr, org.jcodings.Encoding enc)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, ByteList ptr)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, org.jcodings.Encoding enc)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len, org.jcodings.Encoding enc)
    • encStrBufCat

      public static void encStrBufCat(Ruby runtime, RubyString str, CharSequence cseq)
    • encCrStrBufCat

      public static int encCrStrBufCat(Ruby runtime, CodeRangeable str, ByteList ptr, org.jcodings.Encoding ptrEnc, int ptr_cr)
    • encCrStrBufCat

      public static int encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, org.jcodings.Encoding ptrEnc, int ptr_cr)
    • econvArgs

      public static void econvArgs(ThreadContext context, IRubyObject[] args, byte[][] encNames, org.jcodings.Encoding[] encs, int[] ecflags_p, IRubyObject[] ecopts_p)
    • econvInitByConvpath

      public static org.jcodings.transcode.EConv econvInitByConvpath(ThreadContext context, IRubyObject convpath, byte[][] encNames, org.jcodings.Encoding[] encs)
    • decorateConvpath

      public static int decorateConvpath(ThreadContext context, IRubyObject convpath, int ecflags)
    • ioEncStr

      public static IRubyObject ioEncStr(Ruby runtime, IRubyObject str, OpenFile fptr)
    • encUintChr

      public static RubyString encUintChr(ThreadContext context, int code, org.jcodings.Encoding enc)
    • encMbcput

      public static int encMbcput(int c, byte[] buf, int p, org.jcodings.Encoding enc)
    • encMbcput

      public static int encMbcput(ThreadContext context, int c, byte[] buf, int p, org.jcodings.Encoding enc)
    • encCodepointLength

      public static int encCodepointLength(byte[] pBytes, int p, int e, int[] len_p, org.jcodings.Encoding enc)
    • encCodepointLength

      public static int encCodepointLength(Ruby runtime, byte[] pBytes, int p, int e, int[] len_p, org.jcodings.Encoding enc)
    • strCompatAndValid

      public static IRubyObject strCompatAndValid(ThreadContext context, IRubyObject _str, org.jcodings.Encoding enc)
    • getEncoding

      public static org.jcodings.Encoding getEncoding(ByteList str)
    • getActualEncoding

      public static org.jcodings.Encoding getActualEncoding(org.jcodings.Encoding enc, ByteList byteList)
    • getActualEncoding

      public static org.jcodings.Encoding getActualEncoding(org.jcodings.Encoding enc, byte[] bytes, int p, int end)
    • STR_ENC_GET

      public static org.jcodings.Encoding STR_ENC_GET(ByteListHolder str)
    • rbStrEscape

      public static RubyString rbStrEscape(Ruby runtime, RubyString str)
    • rbStrBufCatEscapedChar

      public static int rbStrBufCatEscapedChar(RubyString result, long c, boolean unicode_p)
    • charsetForEncoding

      public static Charset charsetForEncoding(org.jcodings.Encoding enc)
      Get an appropriate Java Charset for the given Encoding. This works around a bug in jcodings where it would return null as the charset for encodings that should have a match, like Windows-1252. This method is equivalent to enc.getCharset in jcodings 1.0.25 and higher. See https://github.com/jruby/jruby/issues/4716 for more information.
      Parameters:
      enc - the encoding for which to get a matching charset
      Returns:
      the matching charset
    • encCodelen

      public static int encCodelen(ThreadContext context, int c, org.jcodings.Encoding enc)
    • ioStripBOM

      @Deprecated public static org.jcodings.Encoding ioStripBOM(RubyIO io)
      Deprecated.