com.mysql.cj.util

## Class StringUtils

- java.lang.Object
- - com.mysql.cj.util.StringUtils

    public class StringUtils
    extends Object

Various utility methods for converting to/from byte arrays in the platform encoding and several other String operations.

### Field Summary

Fields
`(package private) static char[]` `EMPTY_SPACE`
`private static char[]` `HEX_DIGITS`
`private static String` `VALID_ID_CHARS`
`private static int` `WILD_COMPARE_CONTINUE_WITH_WILD`
`private static int` `WILD_COMPARE_MATCH`
`private static int` `WILD_COMPARE_NO_MATCH`
`(package private) static char` `WILDCARD_ESCAPE`
`(package private) static char` `WILDCARD_MANY`
`(package private) static char` `WILDCARD_ONE`

### Constructor Summary

Constructors
Constructor and Description
`StringUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `appendAsHex(StringBuilder builder, byte[] bytes)`
`static void` `appendAsHex(StringBuilder builder, int value)`
`static boolean` `canHandleAsServerPreparedStatementNoCache(String sql, ServerVersion serverVersion, boolean allowMultiQueries, boolean noBackslashEscapes, boolean useAnsiQuotes)`
`static String` `dumpAsHex(byte[] byteBuffer, int length)` Returns the given bytes as a hex and ASCII dump (up to length bytes).
`private static boolean` `endsWith(byte[] dataFrom, String suffix)`
`static boolean` `endsWithIgnoreCase(String searchIn, String searchFor)` Determines whether or not the string 'searchIn' ends with the string 'searchFor', dis-regarding case starting at 'startAt' Shorthand for a String.regionMatch(...)
`static void` `escapeBytes(ByteArrayOutputStream bOut, byte[] x)`
`static String` `escapeQuote(String str, String quotChar)`
`static StringBuilder` `escapeString(StringBuilder buf, String x, boolean useAnsiQuotedIdentifiers, CharsetEncoder charsetEncoder)`
`static char` `firstAlphaCharUc(String searchIn, int startAt)`
`static char` `firstNonWsCharUc(String searchIn)` Returns the first non-whitespace char, converted to upper case
`static char` `firstNonWsCharUc(String searchIn, int startAt)`
`static String` `fixDecimalExponent(String dString)` Adds '+' to decimal numbers that are positive (MySQL doesn't understand them otherwise
`static byte[]` `getBytes(char[] value)` Returns the byte[] representation of subset of the given char[] using the default/platform encoding.
`static byte[]` `getBytes(char[] value, int offset, int length)`
`static byte[]` `getBytes(char[] value, int offset, int length, String encoding)` Returns the byte[] representation of subset of the given char[] using the given encoding.
`static byte[]` `getBytes(char[] c, String encoding)` Returns the byte[] representation of subset of the given char[] using the given encoding.
`static byte[]` `getBytes(String value)`
`static byte[]` `getBytes(String value, int offset, int length)`
`static byte[]` `getBytes(String value, int offset, int length, String encoding)`
`static byte[]` `getBytes(String s, String encoding)` Returns the byte[] representation of the given string using the given encoding.
`static byte[]` `getBytesNullTerminated(String value, String encoding)`
`static byte[]` `getBytesWrapped(String s, char beginWrap, char endWrap, String encoding)` Returns the byte[] representation of the given string properly wrapped between the given char delimiters using the given encoding.
`static String` `getFullyQualifiedName(String db, String entity, String quoteId, boolean isPedantic)` Builds and returns a fully qualified name, quoted if necessary, for the given database entity.
`static String` `getUniqueSavepointId()`
`static boolean` `hasWildcards(String src)` Does the string contain wildcard symbols ('%' or '_').
`static void` `hexEscapeBlock(byte[] buf, int size, BiConsumer<Byte,Byte> bc)` Used to escape binary data with hex
`static int` `indexOf(byte[] s, char c)`
`static int` `indexOfIgnoreCase(int startingPosition, String searchIn, String searchFor)` Finds the position of a substring within a string ignoring case.
`static int` `indexOfIgnoreCase(int startingPosition, String searchIn, String[] searchForSequence, String openingMarkers, String closingMarkers, Set<SearchMode> searchMode)` Finds the position of the first of a consecutive sequence of strings within a string, ignoring case, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfIgnoreCase(int startingPosition, String searchIn, String searchFor, String openingMarkers, String closingMarkers, Set<SearchMode> searchMode)` Finds the position of a substring within a string, ignoring case, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfIgnoreCase(int startingPosition, String searchIn, String searchFor, String openingMarkers, String closingMarkers, String overridingMarkers, Set<SearchMode> searchMode)` Finds the position of a substring within a string, ignoring case, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfIgnoreCase(String searchIn, String searchFor)` Finds the position of a substring within a string ignoring case.
`static int` `indexOfNextAlphanumericChar(int startingPosition, String searchIn, String openingMarkers, String closingMarkers, String overridingMarkers, Set<SearchMode> searchMode)` Finds the position of the next alphanumeric character within a string, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfNextNonWsChar(int startingPosition, String searchIn, String openingMarkers, String closingMarkers, String overridingMarkers, Set<SearchMode> searchMode)` Finds the position of the next non-whitespace character within a string, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfNextWsChar(int startingPosition, String searchIn, String openingMarkers, String closingMarkers, String overridingMarkers, Set<SearchMode> searchMode)` Finds the position of the next whitespace character within a string, with the option to skip text delimited by given markers or within comments.
`static int` `indexOfQuoteDoubleAware(String searchIn, String quoteChar, int startFrom)`
`private static boolean` `isCharAtPosNotEqualIgnoreCase(String searchIn, int pos, char firstCharOfSearchForUc, char firstCharOfSearchForLc)`
`protected static boolean` `isCharEqualIgnoreCase(char charToCompare, char compareToCharUC, char compareToCharLC)`
`static boolean` `isEmptyOrWhitespaceOnly(String str)`
`static boolean` `isNullOrEmpty(String str)`
`static boolean` `isStrictlyNumeric(CharSequence cs)` Checks is the CharSequence contains digits only.
`static boolean` `isValidIdChar(char c)`
`static String` `joinWithSerialComma(List<?> elements)` Joins all elements of the given list using serial comma (Oxford comma) rules.
`static int` `lastIndexOf(byte[] s, char c)`
`static boolean` `nullSafeEqual(String str1, String str2)` Two given strings are considered equal if both are null or if they have the same string value.
`static String` `padString(String stringVal, int requiredLength)`
`static byte[]` `quoteBytes(byte[] bytes)`
`static String` `quoteIdentifier(String identifier, boolean isPedantic)` Surrounds identifier with "`" and duplicates these symbols inside the identifier.
`static String` `quoteIdentifier(String identifier, String quoteChar, boolean isPedantic)` Surrounds identifier with quoteChar and duplicates these symbols inside the identifier.
`static boolean` `regionMatchesIgnoreCase(String searchIn, int startAt, String searchFor)` Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and starting at 'startAt'.
`static int` `safeIntParse(String intAsString)`
`static String` `safeTrim(String toTrim)`
`static String` `sanitizeProcOrFuncName(String src)` Next two functions are to help DBMD check if the given string is in form of database.name and return it as "database";"name" with comments removed.
`static List<String>` `split(String stringToSplit, String delimiter, boolean trim)` Splits stringToSplit into a list, using the given delimiter
`static List<String>` `split(String stringToSplit, String delimiter, String openingMarkers, String closingMarkers, boolean trim)` Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.
`static List<String>` `split(String stringToSplit, String delimiter, String openingMarkers, String closingMarkers, boolean trim, Set<SearchMode> searchMode)` Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.
`static List<String>` `split(String stringToSplit, String delimiter, String openingMarkers, String closingMarkers, String overridingMarkers, boolean trim)` Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.
`static List<String>` `split(String stringToSplit, String delimiter, String openingMarkers, String closingMarkers, String overridingMarkers, boolean trim, Set<SearchMode> searchMode)` Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.
`static List<String>` `splitDBdotName(String source, String db, String quoteId, boolean isNoBslashEscSet)` Splits an entity identifier into its parts (database and entity name) and returns a list containing the two elements.
`private static boolean` `startsWith(byte[] dataFrom, String chars)`
`static boolean` `startsWithIgnoreCase(String searchIn, String searchFor)` Determines whether or not the string 'searchIn' starts with the string 'searchFor', dis-regarding case.
`static boolean` `startsWithIgnoreCaseAndNonAlphaNumeric(String searchIn, String searchFor)` Determines whether or not the string 'searchIn' starts with the string 'searchFor', disregarding case,leading whitespace and non-alphanumeric characters.
`static boolean` `startsWithIgnoreCaseAndWs(String searchIn, String searchFor)` Determines whether or not the string 'searchIn' starts with the string 'searchFor', disregarding case and leading whitespace
`static int` `startsWithIgnoreCaseAndWs(String searchIn, String[] searchFor)` Determines whether or not the string 'searchIn' starts with one of the strings in 'searchFor', disregarding case and leading whitespace
`static boolean` `startsWithIgnoreCaseAndWs(String searchIn, String searchFor, int beginPos)` Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and leading whitespace
`static String` `stringArrayToString(String[] elems, String prefix, String midDelimiter, String lastDelimiter, String suffix)` Constructs a String containing all the elements in the String array bounded and joined by the provided concatenation elements.
`static String` `stripCommentsAndHints(String source, String openingMarkers, String closingMarkers, boolean allowBackslashEscapes)` Removes comments and hints from the given string.
`static byte[]` `stripEnclosure(byte[] source, String prefix, String suffix)`
`static char[]` `toAsciiCharArray(byte[] buffer, int startPos, int length)` Returns the bytes as an ASCII String.
`static String` `toAsciiString(byte[] buffer)` Returns the bytes as an ASCII String.
`static String` `toAsciiString(byte[] buffer, int startPos, int length)` Returns the bytes as an ASCII String.
`static String` `toHexString(byte[] byteBuffer, int length)` Converts the given byte array into Hex String, stopping at given length.
`static String` `toString(byte[] value)`
`static String` `toString(byte[] value, Charset charset)`
`static String` `toString(byte[] value, int offset, int length)`
`static String` `toString(byte[] value, int offset, int length, String encoding)`
`static String` `toString(byte[] value, String encoding)`
`static byte[]` `unquoteBytes(byte[] bytes)`
`static String` `unQuoteIdentifier(String identifier, String quoteChar)` Trims the identifier, removes quote chars from first and last positions and replaces double occurrences of quote char from entire identifier, i.e.
`static String` `urlEncode(String stringToEncode)` URL-encode the given string.
`static boolean` `wildCompareIgnoreCase(String searchIn, String searchFor)` Compares searchIn against searchForWildcard with wildcards, in a case insensitive manner.
`private static int` `wildCompareInternal(String searchIn, String searchFor)` Compares searchIn against searchForWildcard with wildcards (heavily borrowed from strings/ctype-simple.c in the server sources) This method does a single passage matching for normal characters and WILDCARD_ONE (_), and recursive matching for WILDCARD_MANY (%) which may be repeated for as many anchor chars are found.
`static String` `zeroFill(String value, int length)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### WILD_COMPARE_MATCH

    private static final int WILD_COMPARE_MATCH

See Also:
  Constant Field Values

#### WILD_COMPARE_CONTINUE_WITH_WILD

    private static final int WILD_COMPARE_CONTINUE_WITH_WILD

See Also:
  Constant Field Values

#### WILD_COMPARE_NO_MATCH

    private static final int WILD_COMPARE_NO_MATCH

See Also:
  Constant Field Values

#### WILDCARD_MANY

    static final char WILDCARD_MANY

See Also:
  Constant Field Values

#### WILDCARD_ONE

    static final char WILDCARD_ONE

See Also:
  Constant Field Values

#### WILDCARD_ESCAPE

    static final char WILDCARD_ESCAPE

See Also:
  Constant Field Values

#### VALID_ID_CHARS

    private static final String VALID_ID_CHARS

See Also:
  Constant Field Values

#### HEX_DIGITS

    private static final char[] HEX_DIGITS

#### EMPTY_SPACE

    static final char[] EMPTY_SPACE

### Constructor Detail

#### StringUtils

    public StringUtils()

### Method Detail

#### dumpAsHex

    public static String dumpAsHex(byte[] byteBuffer,
                                   int length)

Returns the given bytes as a hex and ASCII dump (up to length bytes).

Parameters:
  `byteBuffer` - the data to dump as hex
  `length` - the number of bytes to print
Returns:
  a hex and ASCII dump

#### toHexString

    public static String toHexString(byte[] byteBuffer,
                                     int length)

Converts the given byte array into Hex String, stopping at given length.

Parameters:
  `byteBuffer` - the byte array to convert
  `length` - the number of bytes from the given array to convert
Returns:
  a String containing the Hex representation of the given bytes

#### endsWith

    private static boolean endsWith(byte[] dataFrom,
                                    String suffix)

#### firstNonWsCharUc

    public static char firstNonWsCharUc(String searchIn)

Returns the first non-whitespace char, converted to upper case

Parameters:
  `searchIn` - the string to search in
Returns:
  the first non-whitespace character, upper cased.

#### firstNonWsCharUc

    public static char firstNonWsCharUc(String searchIn,
                                        int startAt)

#### firstAlphaCharUc

    public static char firstAlphaCharUc(String searchIn,
                                        int startAt)

#### fixDecimalExponent

    public static String fixDecimalExponent(String dString)

Adds '+' to decimal numbers that are positive (MySQL doesn't understand them otherwise

Parameters:
  `dString` - The value as a string
Returns:
  String the string with a '+' added (if needed)

#### getBytes

    public static byte[] getBytes(String s,
                                  String encoding)

Returns the byte[] representation of the given string using the given encoding.

Parameters:
  `s` - source string
  `encoding` - java encoding
Returns:
  bytes

#### getBytesWrapped

    public static byte[] getBytesWrapped(String s,
                                         char beginWrap,
                                         char endWrap,
                                         String encoding)

Returns the byte[] representation of the given string properly wrapped between the given char delimiters using the given encoding.

Parameters:
  `s` - source string
  `beginWrap` - opening char delimiter
  `endWrap` - closing char delimiter
  `encoding` - java encoding
Returns:
  bytes

#### indexOfIgnoreCase

    public static int indexOfIgnoreCase(String searchIn,
                                        String searchFor)

Finds the position of a substring within a string ignoring case.

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the array of strings to search for
Returns:
  the position where `searchFor` is found within `searchIn` starting from `startingPosition`.

#### indexOfIgnoreCase

    public static int indexOfIgnoreCase(int startingPosition,
                                        String searchIn,
                                        String searchFor)

Finds the position of a substring within a string ignoring case.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `searchFor` - the array of strings to search for
Returns:
  the position where `searchFor` is found within `searchIn` starting from `startingPosition`.

#### indexOfIgnoreCase

    public static int indexOfIgnoreCase(int startingPosition,
                                        String searchIn,
                                        String[] searchForSequence,
                                        String openingMarkers,
                                        String closingMarkers,
                                        Set<SearchMode> searchMode)

Finds the position of the first of a consecutive sequence of strings within a string, ignoring case, with the option to skip text delimited by given markers or within comments.

Independently of the `searchMode` provided, when searching for the second and following strings `SearchMode.SKIP_WHITE_SPACE` will be added and `SearchMode.SKIP_BETWEEN_MARKERS` removed.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `searchForSequence` - searchForSequence
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where `searchFor` is found within `searchIn` starting from `startingPosition`.

#### indexOfIgnoreCase

    public static int indexOfIgnoreCase(int startingPosition,
                                        String searchIn,
                                        String searchFor,
                                        String openingMarkers,
                                        String closingMarkers,
                                        Set<SearchMode> searchMode)

Finds the position of a substring within a string, ignoring case, with the option to skip text delimited by given markers or within comments.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `searchFor` - the string to search for
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where `searchFor` is found within `searchIn` starting from `startingPosition`.

#### indexOfIgnoreCase

    public static int indexOfIgnoreCase(int startingPosition,
                                        String searchIn,
                                        String searchFor,
                                        String openingMarkers,
                                        String closingMarkers,
                                        String overridingMarkers,
                                        Set<SearchMode> searchMode)

Finds the position of a substring within a string, ignoring case, with the option to skip text delimited by given markers or within comments.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `searchFor` - the string to search for
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where `searchFor` is found within `searchIn` starting from `startingPosition`.

#### indexOfNextAlphanumericChar

    public static int indexOfNextAlphanumericChar(int startingPosition,
                                                  String searchIn,
                                                  String openingMarkers,
                                                  String closingMarkers,
                                                  String overridingMarkers,
                                                  Set<SearchMode> searchMode)

Finds the position of the next alphanumeric character within a string, with the option to skip text delimited by given markers or within comments.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where the next non-whitespace character is found within `searchIn` starting from `startingPosition`.

#### indexOfNextNonWsChar

    public static int indexOfNextNonWsChar(int startingPosition,
                                           String searchIn,
                                           String openingMarkers,
                                           String closingMarkers,
                                           String overridingMarkers,
                                           Set<SearchMode> searchMode)

Finds the position of the next non-whitespace character within a string, with the option to skip text delimited by given markers or within comments.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where the next non-whitespace character is found within `searchIn` starting from `startingPosition`.

#### indexOfNextWsChar

    public static int indexOfNextWsChar(int startingPosition,
                                        String searchIn,
                                        String openingMarkers,
                                        String closingMarkers,
                                        String overridingMarkers,
                                        Set<SearchMode> searchMode)

Finds the position of the next whitespace character within a string, with the option to skip text delimited by given markers or within comments.

Parameters:
  `startingPosition` - the position to start the search from
  `searchIn` - the string to search in
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behavior of the search
Returns:
  the position where the next whitespace character is found within `searchIn` starting from `startingPosition`.

#### isCharAtPosNotEqualIgnoreCase

    private static boolean isCharAtPosNotEqualIgnoreCase(String searchIn,
                                                         int pos,
                                                         char firstCharOfSearchForUc,
                                                         char firstCharOfSearchForLc)

#### isCharEqualIgnoreCase

    protected static boolean isCharEqualIgnoreCase(char charToCompare,
                                                   char compareToCharUC,
                                                   char compareToCharLC)

#### split

    public static List<String> split(String stringToSplit,
                                     String delimiter,
                                     boolean trim)

Splits stringToSplit into a list, using the given delimiter

Parameters:
  `stringToSplit` - the string to split
  `delimiter` - the string to split on
  `trim` - should the split strings be whitespace trimmed?
Returns:
  the list of strings, split by delimiter
Throws:
  `IllegalArgumentException` - if an error occurs

#### split

    public static List<String> split(String stringToSplit,
                                     String delimiter,
                                     String openingMarkers,
                                     String closingMarkers,
                                     boolean trim)

Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.

Parameters:
  `stringToSplit` - the string to split
  `delimiter` - the string to split on
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `trim` - should the split strings be whitespace trimmed?
Returns:
  the list of strings, split by delimiter
Throws:
  `IllegalArgumentException` - if an error occurs

#### split

    public static List<String> split(String stringToSplit,
                                     String delimiter,
                                     String openingMarkers,
                                     String closingMarkers,
                                     boolean trim,
                                     Set<SearchMode> searchMode)

Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.

Parameters:
  `stringToSplit` - the string to split
  `delimiter` - the string to split on
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `trim` - should the split strings be whitespace trimmed?
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behaviour of the search
Returns:
  the list of strings, split by delimiter
Throws:
  `IllegalArgumentException` - if an error occurs

#### split

    public static List<String> split(String stringToSplit,
                                     String delimiter,
                                     String openingMarkers,
                                     String closingMarkers,
                                     String overridingMarkers,
                                     boolean trim)

Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.

Parameters:
  `stringToSplit` - the string to split
  `delimiter` - the string to split on
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `trim` - should the split strings be whitespace trimmed?
Returns:
  the list of strings, split by delimiter
Throws:
  `IllegalArgumentException` - if an error occurs

#### split

    public static List<String> split(String stringToSplit,
                                     String delimiter,
                                     String openingMarkers,
                                     String closingMarkers,
                                     String overridingMarkers,
                                     boolean trim,
                                     Set<SearchMode> searchMode)

Splits stringToSplit into a list, using the given delimiter and skipping all between the given markers.

Parameters:
  `stringToSplit` - the string to split
  `delimiter` - the string to split on
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `overridingMarkers` - the subset of `openingMarkers` that override the remaining markers, e.g., if `openingMarkers = "'("` and `overridingMarkers = "'"` then the block between the outer parenthesis in `"start ('max('); end"` is strictly consumed, otherwise the suffix `" end"` would end up being consumed too in the process of handling the nested parenthesis.
  `trim` - should the split strings be whitespace trimmed?
  `searchMode` - a `Set`, ideally an `EnumSet`, containing the flags from the enum `StringUtils.SearchMode` that determine the behaviour of the search
Returns:
  the list of strings, split by delimiter
Throws:
  `IllegalArgumentException` - if an error occurs

#### startsWith

    private static boolean startsWith(byte[] dataFrom,
                                      String chars)

#### regionMatchesIgnoreCase

    public static boolean regionMatchesIgnoreCase(String searchIn,
                                                  int startAt,
                                                  String searchFor)

Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and starting at 'startAt'. Shorthand for a String.regionMatch(...)

Parameters:
  `searchIn` - the string to search in
  `startAt` - the position to start at
  `searchFor` - the string to search for
Returns:
  whether searchIn starts with searchFor, ignoring case

#### startsWithIgnoreCase

    public static boolean startsWithIgnoreCase(String searchIn,
                                               String searchFor)

Determines whether or not the string 'searchIn' starts with the string 'searchFor', dis-regarding case. Shorthand for a String.regionMatch(...)

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for
Returns:
  whether searchIn starts with searchFor, ignoring case

#### startsWithIgnoreCaseAndNonAlphaNumeric

    public static boolean startsWithIgnoreCaseAndNonAlphaNumeric(String searchIn,
                                                                 String searchFor)

Determines whether or not the string 'searchIn' starts with the string 'searchFor', disregarding case,leading whitespace and non-alphanumeric characters.

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for
Returns:
  true if the string starts with 'searchFor' ignoring whitespace

#### startsWithIgnoreCaseAndWs

    public static boolean startsWithIgnoreCaseAndWs(String searchIn,
                                                    String searchFor)

Determines whether or not the string 'searchIn' starts with the string 'searchFor', disregarding case and leading whitespace

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for
Returns:
  true if the string starts with 'searchFor' ignoring whitespace

#### startsWithIgnoreCaseAndWs

    public static boolean startsWithIgnoreCaseAndWs(String searchIn,
                                                    String searchFor,
                                                    int beginPos)

Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and leading whitespace

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for
  `beginPos` - where to start searching
Returns:
  true if the string starts with 'searchFor' ignoring whitespace

#### startsWithIgnoreCaseAndWs

    public static int startsWithIgnoreCaseAndWs(String searchIn,
                                                String[] searchFor)

Determines whether or not the string 'searchIn' starts with one of the strings in 'searchFor', disregarding case and leading whitespace

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string array to search for
Returns:
  the 'searchFor' array index that matched or -1 if none matches

#### endsWithIgnoreCase

    public static boolean endsWithIgnoreCase(String searchIn,
                                             String searchFor)

Determines whether or not the string 'searchIn' ends with the string 'searchFor', dis-regarding case starting at 'startAt' Shorthand for a String.regionMatch(...)

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for
Returns:
  whether searchIn ends with searchFor, ignoring case

#### stripEnclosure

    public static byte[] stripEnclosure(byte[] source,
                                        String prefix,
                                        String suffix)

Parameters:
  `source` - bytes to strip
  `prefix` - prefix
  `suffix` - suffix
Returns:
  result bytes

#### toAsciiString

    public static String toAsciiString(byte[] buffer)

Returns the bytes as an ASCII String.

Parameters:
  `buffer` - the bytes representing the string
Returns:
  The ASCII String.

#### toAsciiString

    public static String toAsciiString(byte[] buffer,
                                       int startPos,
                                       int length)

Returns the bytes as an ASCII String.

Parameters:
  `buffer` - the bytes to convert
  `startPos` - the position to start converting
  `length` - the length of the string to convert
Returns:
  the ASCII string

#### toAsciiCharArray

    public static char[] toAsciiCharArray(byte[] buffer,
                                          int startPos,
                                          int length)

Returns the bytes as an ASCII String.

Parameters:
  `buffer` - the bytes to convert
  `startPos` - the position to start converting
  `length` - the length of the string to convert
Returns:
  the ASCII char array

#### wildCompareIgnoreCase

    public static boolean wildCompareIgnoreCase(String searchIn,
                                                String searchFor)

Compares searchIn against searchForWildcard with wildcards, in a case insensitive manner.

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for, using the 'standard' SQL wildcard chars of '%' and '_'
Returns:
  true if matches

#### wildCompareInternal

    private static int wildCompareInternal(String searchIn,
                                           String searchFor)

Compares searchIn against searchForWildcard with wildcards (heavily borrowed from strings/ctype-simple.c in the server sources) This method does a single passage matching for normal characters and WILDCARD_ONE (_), and recursive matching for WILDCARD_MANY (%) which may be repeated for as many anchor chars are found.

Parameters:
  `searchIn` - the string to search in
  `searchFor` - the string to search for, using the 'standard' SQL wildcard chars of '%' and '_'
Returns:
  WILD_COMPARE_MATCH if matched, WILD_COMPARE_NO_MATCH if not matched, WILD_COMPARE_CONTINUE_WITH_WILD if not matched yet, but it may in one of following recursion rounds

#### lastIndexOf

    public static int lastIndexOf(byte[] s,
                                  char c)

#### indexOf

    public static int indexOf(byte[] s,
                              char c)

#### isNullOrEmpty

    public static boolean isNullOrEmpty(String str)

#### nullSafeEqual

    public static boolean nullSafeEqual(String str1,
                                        String str2)

Two given strings are considered equal if both are null or if they have the same string value.

Parameters:
  `str1` - first string to compare
  `str2` - fecond string to compare
Returns:
  `true` if both strings are null or have the same value

#### stripCommentsAndHints

    public static String stripCommentsAndHints(String source,
                                               String openingMarkers,
                                               String closingMarkers,
                                               boolean allowBackslashEscapes)

Removes comments and hints from the given string.

Parameters:
  `source` - the query string to clean up.
  `openingMarkers` - characters that delimit the beginning of a text block to skip
  `closingMarkers` - characters that delimit the end of a text block to skip
  `allowBackslashEscapes` - whether or not backslash escapes are allowed
Returns:
  the query string with all comment-delimited data removed

#### sanitizeProcOrFuncName

    public static String sanitizeProcOrFuncName(String src)

Next two functions are to help DBMD check if the given string is in form of database.name and return it as "database";"name" with comments removed. If string is NULL or wildcard (%), returns null and exits. First, we sanitize...

Parameters:
  `src` - the source string
Returns:
  the input string with all comment-delimited data removed

#### splitDBdotName

    public static List<String> splitDBdotName(String source,
                                              String db,
                                              String quoteId,
                                              boolean isNoBslashEscSet)

Splits an entity identifier into its parts (database and entity name) and returns a list containing the two elements. If the identifier doesn't contain the database part then the argument `db` is used in its place and `source` corresponds to the full entity name. If argument `source` is NULL or wildcard (%), returns an empty list.

Parameters:
  `source` - the source string
  `db` - database, if available
  `quoteId` - quote character as defined on server
  `isNoBslashEscSet` - is our connection in no BackSlashEscape mode
Returns:
  the input string with all comment-delimited data removed

#### getFullyQualifiedName

    public static String getFullyQualifiedName(String db,
                                               String entity,
                                               String quoteId,
                                               boolean isPedantic)

Builds and returns a fully qualified name, quoted if necessary, for the given database entity.

Parameters:
  `db` - database name
  `entity` - identifier
  `quoteId` - quote character as defined on server
  `isPedantic` - are we in pedantic mode
Returns:
  fully qualified name

#### isEmptyOrWhitespaceOnly

    public static boolean isEmptyOrWhitespaceOnly(String str)

#### escapeQuote

    public static String escapeQuote(String str,
                                     String quotChar)

#### quoteIdentifier

    public static String quoteIdentifier(String identifier,
                                         String quoteChar,
                                         boolean isPedantic)

Surrounds identifier with quoteChar and duplicates these symbols inside the identifier.

Parameters:
  `quoteChar` - ` or "
  `identifier` - in pedantic mode (connection property pedantic=true) identifier is treated as unquoted (as it is stored in the database) even if it starts and ends with quoteChar; in non-pedantic mode if identifier starts and ends with quoteChar method treats it as already quoted and doesn't modify.
  `isPedantic` - are we in pedantic mode
Returns:
  With quoteChar="`":
  - null `->` null
  - abc `->` `abc`
  - ab`c `->` `ab``c`
  - ab"c `->` `ab"c`
  - `ab``c` `->` `ab``c` in non-pedantic mode or ```ab````c``` in pedantic mode
  With quoteChar="\"":
  - null `->` null
  - abc `->` "abc"
  - ab`c `->` "ab`c"
  - ab"c `->` "ab""c"
  - "ab""c" `->` "ab""c" in non-pedantic mode or """ab""""c""" in pedantic mode

#### quoteIdentifier

    public static String quoteIdentifier(String identifier,
                                         boolean isPedantic)

Surrounds identifier with "`" and duplicates these symbols inside the identifier.

Parameters:
  `identifier` - in pedantic mode (connection property pedantic=true) identifier is treated as unquoted (as it is stored in the database) even if it starts and ends with "`"; in non-pedantic mode if identifier starts and ends with "`" method treats it as already quoted and doesn't modify.
  `isPedantic` - are we in pedantic mode
Returns:
  - null `->` null
  - abc `->` `abc`
  - ab`c `->` `ab``c`
  - ab"c `->` `ab"c`
  - `ab``c` `->` `ab``c` in non-pedantic mode or ```ab````c``` in pedantic mode

#### unQuoteIdentifier

    public static String unQuoteIdentifier(String identifier,
                                           String quoteChar)

Trims the identifier, removes quote chars from first and last positions and replaces double occurrences of quote char from entire identifier, i.e. converts quoted identifier into the form as it is stored in database.

Parameters:
  `identifier` - identifier
  `quoteChar` - ` or "
Returns:
  - null `->` null
  - abc `->` abc
  - `abc` `->` abc
  - `ab``c` `->` ab`c
  - `"ab`c"` `->` "ab`c"
  - `ab"c` `->` ab"c
  - "abc" `->` abc
  - "`ab""c`" `->` `ab"c`
  - "ab`c" `->` ab`c

#### indexOfQuoteDoubleAware

    public static int indexOfQuoteDoubleAware(String searchIn,
                                              String quoteChar,
                                              int startFrom)

#### toString

    public static String toString(byte[] value,
                                  int offset,
                                  int length,
                                  String encoding)

#### toString

    public static String toString(byte[] value,
                                  String encoding)

#### toString

    public static String toString(byte[] value,
                                  Charset charset)

#### toString

    public static String toString(byte[] value,
                                  int offset,
                                  int length)

#### toString

    public static String toString(byte[] value)

#### getBytes

    public static byte[] getBytes(char[] value)

Returns the byte[] representation of subset of the given char[] using the default/platform encoding.

Parameters:
  `value` - chars
Returns:
  bytes

#### getBytes

    public static byte[] getBytes(char[] c,
                                  String encoding)

Returns the byte[] representation of subset of the given char[] using the given encoding.

Parameters:
  `c` - chars
  `encoding` - java encoding
Returns:
  bytes

#### getBytes

    public static byte[] getBytes(char[] value,
                                  int offset,
                                  int length)

#### getBytes

    public static byte[] getBytes(char[] value,
                                  int offset,
                                  int length,
                                  String encoding)

Returns the byte[] representation of subset of the given char[] using the given encoding.

Parameters:
  `value` - chars
  `offset` - offset
  `length` - length
  `encoding` - java encoding
Returns:
  bytes

#### getBytes

    public static byte[] getBytes(String value)

#### getBytes

    public static byte[] getBytes(String value,
                                  int offset,
                                  int length)

#### getBytes

    public static byte[] getBytes(String value,
                                  int offset,
                                  int length,
                                  String encoding)

#### isValidIdChar

    public static final boolean isValidIdChar(char c)

#### hexEscapeBlock

    public static final void hexEscapeBlock(byte[] buf,
                                            int size,
                                            BiConsumer<Byte,Byte> bc)

Used to escape binary data with hex

Parameters:
  `buf` - source bytes
  `size` - number of bytes to read
  `bc` - consumer for low and high bits of each byte

#### appendAsHex

    public static void appendAsHex(StringBuilder builder,
                                   byte[] bytes)

#### appendAsHex

    public static void appendAsHex(StringBuilder builder,
                                   int value)

#### getBytesNullTerminated

    public static byte[] getBytesNullTerminated(String value,
                                                String encoding)

#### canHandleAsServerPreparedStatementNoCache

    public static boolean canHandleAsServerPreparedStatementNoCache(String sql,
                                                                    ServerVersion serverVersion,
                                                                    boolean allowMultiQueries,
                                                                    boolean noBackslashEscapes,
                                                                    boolean useAnsiQuotes)

#### padString

    public static String padString(String stringVal,
                                   int requiredLength)

#### zeroFill

    public static String zeroFill(String value,
                                  int length)

#### safeIntParse

    public static int safeIntParse(String intAsString)

#### isStrictlyNumeric

    public static boolean isStrictlyNumeric(CharSequence cs)

Checks is the CharSequence contains digits only. No leading sign and thousands or decimal separators are allowed.

Parameters:
  `cs` - The CharSequence to check.
Returns:
  `true` if the CharSequence not empty and contains only digits, `false` otherwise.

#### safeTrim

    public static String safeTrim(String toTrim)

#### stringArrayToString

    public static String stringArrayToString(String[] elems,
                                             String prefix,
                                             String midDelimiter,
                                             String lastDelimiter,
                                             String suffix)

Constructs a String containing all the elements in the String array bounded and joined by the provided concatenation elements. The last element uses a different delimiter.

Parameters:
  `elems` - the String array from where to take the elements.
  `prefix` - the prefix of the resulting String.
  `midDelimiter` - the delimiter to be used between the N-1 elements
  `lastDelimiter` - the delimiter to be used before the last element.
  `suffix` - the suffix of the resulting String.
Returns:
  a String built from the provided String array and concatenation elements.

#### hasWildcards

    public static boolean hasWildcards(String src)

Does the string contain wildcard symbols ('%' or '_'). Used in DatabaseMetaData.

Parameters:
  `src` - string
Returns:
  true if src contains wildcard symbols

#### getUniqueSavepointId

    public static String getUniqueSavepointId()

#### joinWithSerialComma

    public static String joinWithSerialComma(List<?> elements)

Joins all elements of the given list using serial comma (Oxford comma) rules. E.g.: - "A" - "A and B" - "A, B, and C"

Parameters:
  `elements` - the elements to join
Returns:
  the String with all elements, joined by commas and "and".

#### unquoteBytes

    public static byte[] unquoteBytes(byte[] bytes)

#### quoteBytes

    public static byte[] quoteBytes(byte[] bytes)

#### escapeString

    public static StringBuilder escapeString(StringBuilder buf,
                                             String x,
                                             boolean useAnsiQuotedIdentifiers,
                                             CharsetEncoder charsetEncoder)

#### escapeBytes

    public static void escapeBytes(ByteArrayOutputStream bOut,
                                   byte[] x)

#### urlEncode

    public static String urlEncode(String stringToEncode)

URL-encode the given string.

Parameters:
  `stringToEncode` - the string to encode
Returns:
  the encoded string

Copyright © 2016, 2024, Oracle and/or its affiliates.