Class StringSupport

java.lang.Object
org.jruby.util.StringSupport

public final class StringSupport extends Object
  • Field Details

    • CR_7BIT_F

      public static final int CR_7BIT_F
    • CR_VALID_F

      public static final int CR_VALID_F
    • CR_UNKNOWN

      public static final int CR_UNKNOWN
      See Also:
    • CR_7BIT

      public static final int CR_7BIT
      See Also:
    • CR_VALID

      public static final int CR_VALID
      See Also:
    • CR_BROKEN

      public static final int CR_BROKEN
      See Also:
    • CR_MASK

      public static final int CR_MASK
      See Also:
    • TRANS_SIZE

      public static final int TRANS_SIZE
      See Also:
    • EMPTY_BYTELIST_ARRAY

      public static final ByteList[] EMPTY_BYTELIST_ARRAY
    • EMPTY_STRING_ARRAY

      public static final String[] EMPTY_STRING_ARRAY
  • Constructor Details

    • StringSupport

      public StringSupport()
  • Method Details

    • split

      public static List<String> split(String str, char sep)
      Split string into sub-parts.
      Parameters:
      str - the string
      sep - the separator
      See Also:
    • split

      public static List<String> split(String str, char sep, int lim)
      Split string into (limited) sub-parts.
      Parameters:
      str - the string
      sep - the separator
      lim - has same effect as with String.split(String, int)
    • startsWith

      public static boolean startsWith(CharSequence str, String prefix)
    • startsWith

      public static boolean startsWith(CharSequence str, char c)
    • startsWith

      public static boolean startsWith(CharSequence str, char c1, char c2)
    • lastIndexOf

      public static int lastIndexOf(CharSequence str, char c, int index)
    • contentEquals

      public static boolean contentEquals(CharSequence str, int chr)
    • contentEquals

      public static boolean contentEquals(CharSequence str, int chr1, int chr2)
    • concat

      public static CharSequence concat(CharSequence str1, CharSequence str2)
    • concat

      public static String concat(String str1, String str2)
    • delete

      public static String delete(String str, char c)
    • replaceFirst

      public static CharSequence replaceFirst(String str, String sub, String repl)
    • replaceAll

      public static CharSequence replaceAll(String str, String sub, String repl)
    • codeRangeAsString

      public static String codeRangeAsString(int codeRange)
    • encFastMBCLen

      public static int encFastMBCLen(byte[] bytes, int p, int e, org.jcodings.Encoding enc)
    • length

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

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

      public static boolean MBCLEN_NEEDMORE_P(int r)
    • MBCLEN_NEEDMORE

      public static int MBCLEN_NEEDMORE(int n)
    • MBCLEN_NEEDMORE_LEN

      public static int MBCLEN_NEEDMORE_LEN(int r)
    • MBCLEN_INVALID_P

      public static boolean MBCLEN_INVALID_P(int r)
    • MBCLEN_CHARFOUND_LEN

      public static int MBCLEN_CHARFOUND_LEN(int r)
    • MBCLEN_CHARFOUND_P

      public static boolean MBCLEN_CHARFOUND_P(int r)
    • CONSTRUCT_MBCLEN_CHARFOUND

      public static int CONSTRUCT_MBCLEN_CHARFOUND(int n)
    • searchNonAscii

      public static int searchNonAscii(byte[] bytes, int p, int end)
    • searchNonAscii

      public static int searchNonAscii(ByteList bytes)
    • searchNonAscii

      public static int searchNonAscii(String string)
    • codeRangeScan

      public static int codeRangeScan(org.jcodings.Encoding enc, byte[] bytes, int p, int len)
    • codeRangeScan

      public static int codeRangeScan(org.jcodings.Encoding enc, ByteList bytes)
    • codeRangeScanRestartable

      public static long codeRangeScanRestartable(org.jcodings.Encoding enc, byte[] bytes, int s, int end, int cr)
    • utf8Length

      public static int utf8Length(byte[] bytes, int p, int end)
    • utf8Length

      public static int utf8Length(ByteList bytes)
    • strLength

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

      public static int strLength(org.jcodings.Encoding enc, byte[] bytes, int p, int e, int cr)
    • strLength

      public static int strLength(ByteList bytes)
    • strLengthWithCodeRange

      public static long strLengthWithCodeRange(org.jcodings.Encoding enc, byte[] bytes, int p, int end)
    • strLengthWithCodeRangeAsciiCompatible

      public static long strLengthWithCodeRangeAsciiCompatible(org.jcodings.Encoding enc, byte[] bytes, int p, int end)
    • strLengthWithCodeRangeNonAsciiCompatible

      public static long strLengthWithCodeRangeNonAsciiCompatible(org.jcodings.Encoding enc, byte[] bytes, int p, int end)
    • strLengthWithCodeRange

      public static long strLengthWithCodeRange(ByteList bytes)
    • strLengthWithCodeRange

      public static long strLengthWithCodeRange(ByteList bytes, org.jcodings.Encoding enc)
    • pack

      public static long pack(int result, int arg)
    • unpackResult

      public static int unpackResult(long len)
    • unpackArg

      public static int unpackArg(long cr)
    • codePoint

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

      @Deprecated(since="10.0") public static int codePoint(Ruby runtime, org.jcodings.Encoding enc, byte[] bytes, int p, int end)
      Deprecated.
    • codePoint

      public static int codePoint(ThreadContext context, org.jcodings.Encoding enc, byte[] bytes, int p, int end)
    • codePoint

      @Deprecated(since="10.0") public static int codePoint(Ruby runtime, ByteList value)
      Deprecated.
    • codePoint

      public static int codePoint(ThreadContext context, ByteList value)
    • codeLength

      public static int codeLength(org.jcodings.Encoding enc, int c)
    • checkCodepointError

      public static int checkCodepointError(int i)
    • getAscii

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

      public static long getAscii(org.jcodings.Encoding enc, byte[] bytes, int p, int end, int len)
    • preciseCodePoint

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

      public static int utf8Nth(byte[] bytes, int p, int e, int nth)
    • nth

      public static int nth(org.jcodings.Encoding enc, byte[] bytes, int p, int end, int n)
      Return the byte offset of the nth character n in the given byte array between p and n using enc as the encoding. Note that the resulting offset will absolute, and therefore >= p. Subtract p to get a relative offset.
      Parameters:
      enc - the encoding of the characters in the byte array
      bytes - the byte array
      p - starting offset
      end - limit offset
      n - character offset to find
      Returns:
      the byte offset of the requested character, or -1 if the requested character offset is outside the given byte offset range
    • nth

      public static int nth(org.jcodings.Encoding enc, ByteList value, int n)
    • nth

      public static int nth(org.jcodings.Encoding enc, byte[] bytes, int p, int end, int n, boolean singlebyte)
      Get the position of the nth character in the given byte array, using the given encoding and range.
      Parameters:
      enc - encoding to use
      bytes - bytes to scan
      p - starting byte offset
      end - ending byte offset
      n - index of character for which to find byte offset
      singlebyte - whether the byte contents are in a single byte encoding
      Returns:
      the offset of the nth character in the string, or -1 if nth is out of the string
    • utf8Offset

      public static int utf8Offset(byte[] bytes, int p, int end, int n)
    • offset

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

      public static int offset(org.jcodings.Encoding enc, byte[] bytes, int p, int end, int n, boolean singlebyte)
    • offset

      public static int offset(RubyString str, int pos)
    • toLower

      @Deprecated public static int toLower(org.jcodings.Encoding enc, int c)
      Deprecated.
    • toUpper

      @Deprecated public static int toUpper(org.jcodings.Encoding enc, int c)
      Deprecated.
    • caseCmp

      public static int caseCmp(byte[] bytes1, int p1, byte[] bytes2, int p2, int len)
    • scanHex

      public static int scanHex(byte[] bytes, int p, int len)
    • scanHex

      public static int scanHex(byte[] bytes, int p, int len, org.jcodings.Encoding enc)
    • hexLength

      public static int hexLength(byte[] bytes, int p, int len)
    • hexLength

      public static int hexLength(byte[] bytes, int p, int len, org.jcodings.Encoding enc)
    • scanOct

      public static int scanOct(byte[] bytes, int p, int len)
    • scanOct

      public static int scanOct(byte[] bytes, int p, int len, org.jcodings.Encoding enc)
    • octLength

      public static int octLength(byte[] bytes, int p, int len)
    • octLength

      public static int octLength(byte[] bytes, int p, int len, org.jcodings.Encoding enc)
    • checkStringSafety

      public static void checkStringSafety(Ruby runtime, IRubyObject value)
      Check whether input object's string value contains a null byte, and if so throw ArgumentError.
      Parameters:
      runtime -
      value -
    • checkStringSafetyMBC

      public static void checkStringSafetyMBC(Ruby runtime, RubyString value)
    • escapedCharFormat

      public static String escapedCharFormat(int c, boolean isUnicode)
    • isIncompleteChar

      public static boolean isIncompleteChar(int b)
    • bytesToFixBrokenTrailingCharacter

      public static int bytesToFixBrokenTrailingCharacter(ByteList val, int usingLength)
    • bytesToFixBrokenTrailingCharacter

      public static int bytesToFixBrokenTrailingCharacter(byte[] bytes, int begin, int byteSize, org.jcodings.Encoding encoding, int usingLength)
    • memchr

      @Deprecated(since="10.0") public static int memchr(byte[] ptr, int start, int find, int len)
      Deprecated.
    • checkEmbeddedNulls

      @Deprecated(since="10.0") public static RubyString checkEmbeddedNulls(Ruby runtime, IRubyObject ptr)
      Deprecated.
    • strNullCheck

      public static Object[] strNullCheck(IRubyObject ptr)
    • positionEndForScan

      public static int positionEndForScan(ByteList value, org.joni.Matcher matcher, org.jcodings.Encoding enc, int begin, int range)
      rb_str_scan
    • dumpCommon

      public static ByteList dumpCommon(Ruby runtime, ByteList bytelist)
      rb_str_dump
    • dumpCommon

      public static ByteList dumpCommon(Ruby runtime, ByteList byteList, boolean quoteOnlyIfNeeded)
    • isEVStr

      public static boolean isEVStr(byte[] bytes, int p, int end)
    • isEVStr

      public static boolean isEVStr(int c)
    • strCount

      public static int strCount(ByteList str, boolean[] table, StringSupport.TrTables tables, org.jcodings.Encoding enc)
      rb_str_count
    • strCount

      @Deprecated(since="10.0") public static int strCount(ByteList str, Ruby runtime, boolean[] table, StringSupport.TrTables tables, org.jcodings.Encoding enc)
      Deprecated.
    • strCount

      public static int strCount(ThreadContext context, ByteList str, boolean[] table, StringSupport.TrTables tables, org.jcodings.Encoding enc)
    • rindex

      public static int rindex(ByteList source, int sourceChars, int subChars, int pos, CodeRangeable subStringCodeRangeable, org.jcodings.Encoding enc)
    • byterindex

      public static int byterindex(ByteList source, int pos, CodeRangeable subStringCodeRangeable, org.jcodings.Encoding enc)
    • strLengthFromRubyString

      public static int strLengthFromRubyString(CodeRangeable string, org.jcodings.Encoding enc)
    • strLengthFromRubyString

      public static int strLengthFromRubyString(CodeRangeable string)
    • strLengthFromRubyString

      public static int strLengthFromRubyString(CodeRangeable string, ByteList bytes, org.jcodings.Encoding enc)
    • trSetupTable

      public static StringSupport.TrTables trSetupTable(ByteList str, boolean[] stable, StringSupport.TrTables tables, boolean first, org.jcodings.Encoding enc)
    • trSetupTable

      @Deprecated(since="10.0") public static StringSupport.TrTables trSetupTable(ByteList str, Ruby runtime, boolean[] stable, StringSupport.TrTables tables, boolean first, org.jcodings.Encoding enc)
      Deprecated.
    • trSetupTable

      public static StringSupport.TrTables trSetupTable(ThreadContext context, ByteList str, boolean[] stable, StringSupport.TrTables tables, boolean first, org.jcodings.Encoding enc)
    • trFind

      public static boolean trFind(int c, boolean[] table, StringSupport.TrTables tables)
    • trNext

      public static int trNext(StringSupport.TR tr, org.jcodings.Encoding enc)
    • trNext

      public static int trNext(StringSupport.TR tr, Ruby runtime, org.jcodings.Encoding enc)
    • succCommon

      public static ByteList succCommon(ByteList original)
    • succCommon

      @Deprecated(since="10.0") public static ByteList succCommon(Ruby runtime, ByteList original)
      Deprecated.
    • succCommon

      public static ByteList succCommon(ThreadContext context, ByteList original)
    • succChar

      public static StringSupport.NeighborChar succChar(org.jcodings.Encoding enc, byte[] bytes, int p, int len)
    • succChar

      public static StringSupport.NeighborChar succChar(Ruby runtime, org.jcodings.Encoding enc, byte[] bytes, int p, int len)
    • isSingleByteOptimizable

      public static boolean isSingleByteOptimizable(CodeRangeable string, org.jcodings.Encoding encoding)
    • index

      public static int index(ByteList source, ByteList other, int offset, org.jcodings.Encoding enc)
      Parameters:
      source - string to find index within
      other - string to match in source
      offset - in bytes to start looking
      enc - encoding to use to walk the source string.
      Returns:
    • byteindex

      public static int byteindex(CodeRangeable sourceString, CodeRangeable otherString, int offset, org.jcodings.Encoding enc)
    • index

      public static int index(CodeRangeable sourceString, CodeRangeable otherString, int offset, org.jcodings.Encoding enc)
    • associateEncoding

      public static void associateEncoding(CodeRangeable string, org.jcodings.Encoding enc)
    • replaceInternal

      public static ByteList replaceInternal(int beg, int len, ByteListHolder source, CodeRangeable repl)
    • replaceInternal19

      @Deprecated(since="9.4") public static void replaceInternal19(int beg, int len, CodeRangeable source, CodeRangeable repl)
      Deprecated.
    • replaceInternal19

      @Deprecated(since="9.4") public static void replaceInternal19(Ruby runtime, int beg, int len, RubyString source, RubyString repl)
      Deprecated.
    • strUpdate

      public static void strUpdate(int beg, int len, CodeRangeable source, CodeRangeable repl)
    • strUpdate

      @Deprecated(since="10.0") public static void strUpdate(Ruby runtime, int beg, int len, RubyString source, RubyString repl)
      Deprecated.
    • strUpdate

      public static void strUpdate(ThreadContext context, int beg, int len, RubyString source, RubyString repl)
    • isAsciiOnly

      public static boolean isAsciiOnly(CodeRangeable string)
    • strDeleteBang

      @Deprecated(since="10.0") public static CodeRangeable strDeleteBang(CodeRangeable rubyString, Ruby runtime, boolean[] squeeze, StringSupport.TrTables tables, org.jcodings.Encoding enc)
      Deprecated.
    • strDeleteBang

      public static CodeRangeable strDeleteBang(ThreadContext context, CodeRangeable rubyString, boolean[] squeeze, StringSupport.TrTables tables, org.jcodings.Encoding enc)
    • choppedLength

      public static int choppedLength(CodeRangeable str)
      MRI: chopped_length
    • areCompatible

      public static org.jcodings.Encoding areCompatible(CodeRangeable str1, CodeRangeable str2)
      rb_enc_compatible
    • areCompatible

      public static org.jcodings.Encoding areCompatible(org.jcodings.Encoding enc1, CodeRangeable str2)
    • areCompatible

      public static org.jcodings.Encoding areCompatible(ByteList str1, ByteList str2)
    • addByteLists

      public static ByteList addByteLists(ByteList value1, ByteList value2)
    • areComparable

      public static boolean areComparable(CodeRangeable string, CodeRangeable other)
    • areComparableViaCodeRange

      public static boolean areComparableViaCodeRange(CodeRangeable string, CodeRangeable other)
    • rbStrEnumerateLines

      public static IRubyObject rbStrEnumerateLines(RubyString str, ThreadContext context, String name, IRubyObject arg, Block block, boolean wantarray)
    • rbStrEnumerateLines

      public static IRubyObject rbStrEnumerateLines(RubyString str, ThreadContext context, String name, IRubyObject arg, IRubyObject opts, Block block, boolean wantarray)
    • memsearch

      public static int memsearch(byte[] xBytes, int x0, int m, byte[] yBytes, int y0, int n, org.jcodings.Encoding enc)
    • trTransHelper

      public static CodeRangeable trTransHelper(CodeRangeable self, CodeRangeable srcStr, CodeRangeable replStr, boolean sflag)
      rb_str_tr / rb_str_tr_bang
    • trTransHelper

      @Deprecated(since="10.0") public static CodeRangeable trTransHelper(Ruby runtime, CodeRangeable self, CodeRangeable srcStr, CodeRangeable replStr, boolean sflag)
      Deprecated.
    • multiByteCasecmp

      public static int multiByteCasecmp(org.jcodings.Encoding enc, ByteList value, ByteList otherValue)
    • singleByteSqueeze

      public static boolean singleByteSqueeze(ByteList value, boolean[] squeeze)
    • multiByteSqueeze

      public static boolean multiByteSqueeze(ByteList value, boolean[] squeeze, StringSupport.TrTables tables, org.jcodings.Encoding enc, boolean isArg)
    • multiByteSqueeze

      @Deprecated(since="10.0") public static boolean multiByteSqueeze(Ruby runtime, ByteList value, boolean[] squeeze, StringSupport.TrTables tables, org.jcodings.Encoding enc, boolean isArg)
      Deprecated.
    • multiByteSqueeze

      public static boolean multiByteSqueeze(ThreadContext context, ByteList value, boolean[] squeeze, StringSupport.TrTables tables, org.jcodings.Encoding enc, boolean isArg)
    • memmem

      public static int memmem(byte[] aBytes, int aStart, int aLen, byte[] p, int pStart, int pLen)
    • checkCaseMapOptions

      @Deprecated(since="10.0") public static int checkCaseMapOptions(Ruby runtime, IRubyObject arg0, IRubyObject arg1, int flags)
      Deprecated.
    • checkCaseMapOptions

      public static int checkCaseMapOptions(ThreadContext context, IRubyObject arg0, IRubyObject arg1, int flags)
    • checkCaseMapOptions

      @Deprecated(since="10.0") public static int checkCaseMapOptions(Ruby runtime, IRubyObject arg0, int flags)
      Deprecated.
    • checkCaseMapOptions

      public static int checkCaseMapOptions(ThreadContext context, IRubyObject arg0, int flags)
    • caseMap

      @Deprecated(since="10.0") public static ByteList caseMap(Ruby runtime, ByteList src, org.jcodings.IntHolder flags, org.jcodings.Encoding enc)
      Deprecated.
    • caseMap

      public static ByteList caseMap(ThreadContext context, ByteList src, org.jcodings.IntHolder flags, org.jcodings.Encoding enc)
    • asciiOnlyCaseMap

      @Deprecated(since="10.0") public static void asciiOnlyCaseMap(Ruby runtime, ByteList value, org.jcodings.IntHolder flags, org.jcodings.Encoding enc)
      Deprecated.
    • asciiOnlyCaseMap

      public static void asciiOnlyCaseMap(ThreadContext context, ByteList value, org.jcodings.IntHolder flags)
    • encCoderangeClean

      public static int encCoderangeClean(int cr)
    • byteListAsString

      public static String byteListAsString(ByteList bytes)
    • isUnicode

      @Deprecated public static boolean isUnicode(org.jcodings.Encoding enc)
      Deprecated.