Class RegexpSupport

java.lang.Object
org.jruby.util.RegexpSupport

public class RegexpSupport extends Object
  • Constructor Details

    • RegexpSupport

      public RegexpSupport()
  • Method Details

    • preprocess

      public static ByteList preprocess(Ruby runtime, ByteList str, org.jcodings.Encoding enc, org.jcodings.Encoding[] fixedEnc, RegexpSupport.ErrorMode mode)
      Preprocess the given string for use in regexp, raising errors for encoding incompatibilities that arise. This version produces a new unescaped version of the string based on fixes performed while walking.
      Parameters:
      runtime - current runtime
      str - string to preprocess
      enc - string's encoding
      fixedEnc - new encoding after fixing
      mode - mode of errors
      Returns:
      a new unescaped string
    • unescapeNonAscii

      public static boolean unescapeNonAscii(Ruby runtime, ByteList to, byte[] bytes, int p, int end, org.jcodings.Encoding enc, org.jcodings.Encoding[] encp, ByteList str, RegexpSupport.ErrorMode mode)
      Unescape non-ascii elements in the given string, appending the results to the given bytelist if provided.
      Parameters:
      runtime - current runtime
      to - output bytelist; if null, no appending will be done
      bytes - the bytes to unescape
      p - starting position
      end - ending position
      enc - bytes' encoding
      encp - out param for fixed encoding
      str - original wrapper for the bytes
      mode - error mode
      Returns:
      whether any propery elements were encountered while walking
    • raisePreprocessError

      public static int raisePreprocessError(Ruby runtime, ByteList str, String err, RegexpSupport.ErrorMode mode)
    • raiseRegexpError19

      public static void raiseRegexpError19(Ruby runtime, ByteList bytes, org.jcodings.Encoding enc, RegexpOptions options, String err)
    • regexpDescription19

      public static ByteList regexpDescription19(Ruby runtime, ByteList bytes, RegexpOptions options, org.jcodings.Encoding enc)
    • regexpDescription19

      private static ByteList regexpDescription19(Ruby runtime, byte[] s, int start, int len, RegexpOptions options, org.jcodings.Encoding enc)
    • appendRegexpString19

      public static void appendRegexpString19(Ruby runtime, ByteList to, byte[] bytes, int start, int len, org.jcodings.Encoding enc, org.jcodings.Encoding resEnc)
    • appendOptions

      public static void appendOptions(ByteList to, RegexpOptions options)
    • readEscapedByte

      public static int readEscapedByte(Ruby runtime, byte[] to, int toP, byte[] bytes, int p, int end, ByteList str, RegexpSupport.ErrorMode mode)
    • unescapeEscapedNonAscii

      private static int unescapeEscapedNonAscii(Ruby runtime, ByteList to, byte[] bytes, int p, int end, org.jcodings.Encoding enc, org.jcodings.Encoding[] encp, ByteList str, RegexpSupport.ErrorMode mode)
      Unescape escaped non-ascii character at start position, appending all to the given bytelist if provided.
      Parameters:
      runtime - current runtime
      to - output bytelist; if null, no appending will be done
      bytes - incoming bytes
      p - start position
      end - end position
      enc - bytes' encoding
      encp - out param for fixed encoding
      str - original bytes wrapper
      mode - error mode
      Returns:
      new position after performing unescaping
    • unescapeUnicodeList

      private static int unescapeUnicodeList(Ruby runtime, ByteList to, byte[] bytes, int p, int end, org.jcodings.Encoding[] encp, ByteList str, RegexpSupport.ErrorMode mode)
      Unescape unicode characters at given offset, appending to the given out buffer if provided.
      Parameters:
      runtime - current runtime
      to - output buffer; if null, no appending will be done
      bytes - input bytes
      p - start position
      end - end position
      encp - out param for fixed encoding
      str - original bytes wrapper
      mode - error mode
      Returns:
      new position after unescaping
    • unescapeUnicodeBmp

      private static int unescapeUnicodeBmp(Ruby runtime, ByteList to, byte[] bytes, int p, int end, org.jcodings.Encoding[] encp, ByteList str, RegexpSupport.ErrorMode mode)
      Unescape unicode BMP char at given offset, appending to the specified buffer if non-null.
      Parameters:
      runtime - current runtime
      to - output buffer; if null, no appending will be done
      bytes - input bytes
      p - start position
      end - end position
      encp - out param for fixed encoding
      str - original bytes wrapper
      mode - error mode
      Returns:
      new position after unescaping
    • appendUtf8

      private static void appendUtf8(Ruby runtime, ByteList to, int code, org.jcodings.Encoding[] enc, ByteList str, RegexpSupport.ErrorMode mode)
      Append the given utf8 characters to the buffer, if given, checking for errors along the way.
      Parameters:
      runtime - current runtime
      to - output buffer; if null, no appending will be done
      code - utf8 character code
      enc - output param for new encoding
      str - original wrapper of source bytes
      mode - error mode
    • checkUnicodeRange

      private static void checkUnicodeRange(Ruby runtime, int code, ByteList str, RegexpSupport.ErrorMode mode)