类 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.
-
-
构造器概要
构造器 构造器 说明 StringUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static voidappendAsHex(StringBuilder builder, byte[] bytes)static voidappendAsHex(StringBuilder builder, int value)static booleancanHandleAsServerPreparedStatementNoCache(String sql, ServerVersion serverVersion, boolean allowMultiQueries, boolean noBackslashEscapes, boolean useAnsiQuotes)static StringdumpAsHex(byte[] byteBuffer, int length)Returns the given bytes as a hex and ASCII dump (up to length bytes).static booleanendsWithIgnoreCase(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 voidescapeBytes(ByteArrayOutputStream bOut, byte[] x)static StringescapeQuote(String str, String quotChar)static StringBuilderescapeString(StringBuilder buf, String x, boolean useAnsiQuotedIdentifiers, CharsetEncoder charsetEncoder)static charfirstAlphaCharUc(String searchIn, int startAt)static charfirstNonWsCharUc(String searchIn)Returns the first non-whitespace char, converted to upper casestatic charfirstNonWsCharUc(String searchIn, int startAt)static StringfixDecimalExponent(String dString)Adds '+' to decimal numbers that are positive (MySQL doesn't understand them otherwisestatic 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 StringgetFullyQualifiedName(String db, String entity, String quoteId, boolean isPedantic)Builds and returns a fully qualified name, quoted if necessary, for the given database entity.static StringgetUniqueSavepointId()static booleanhasWildcards(String src)Does the string contain wildcard symbols ('%' or '_').static voidhexEscapeBlock(byte[] buf, int size, java.util.function.BiConsumer<Byte,Byte> bc)Used to escape binary data with hexstatic intindexOf(byte[] s, char c)static intindexOfIgnoreCase(int startingPosition, String searchIn, String searchFor)Finds the position of a substring within a string ignoring case.static intindexOfIgnoreCase(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 intindexOfIgnoreCase(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 intindexOfIgnoreCase(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 intindexOfIgnoreCase(String searchIn, String searchFor)Finds the position of a substring within a string ignoring case.static intindexOfNextAlphanumericChar(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 intindexOfNextNonWsChar(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 intindexOfNextWsChar(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 intindexOfQuoteDoubleAware(String searchIn, String quoteChar, int startFrom)protected static booleanisCharEqualIgnoreCase(char charToCompare, char compareToCharUC, char compareToCharLC)static booleanisEmptyOrWhitespaceOnly(String str)static booleanisNullOrEmpty(String str)static booleanisStrictlyNumeric(CharSequence cs)Checks is the CharSequence contains digits only.static booleanisValidIdChar(char c)static StringjoinWithSerialComma(List<?> elements)Joins all elements of the given list using serial comma (Oxford comma) rules.static intlastIndexOf(byte[] s, char c)static booleannullSafeEqual(String str1, String str2)Two given strings are considered equal if both are null or if they have the same string value.static StringpadString(String stringVal, int requiredLength)static byte[]quoteBytes(byte[] bytes)static StringquoteIdentifier(String identifier, boolean isPedantic)Surrounds identifier with "`" and duplicates these symbols inside the identifier.static StringquoteIdentifier(String identifier, String quoteChar, boolean isPedantic)Surrounds identifier with quoteChar and duplicates these symbols inside the identifier.static booleanregionMatchesIgnoreCase(String searchIn, int startAt, String searchFor)Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and starting at 'startAt'.static intsafeIntParse(String intAsString)static StringsafeTrim(String toTrim)static StringsanitizeProcOrFuncName(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 delimiterstatic 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.static booleanstartsWithIgnoreCase(String searchIn, String searchFor)Determines whether or not the string 'searchIn' starts with the string 'searchFor', dis-regarding case.static booleanstartsWithIgnoreCaseAndNonAlphaNumeric(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 booleanstartsWithIgnoreCaseAndWs(String searchIn, String searchFor)Determines whether or not the string 'searchIn' starts with the string 'searchFor', disregarding case and leading whitespacestatic intstartsWithIgnoreCaseAndWs(String searchIn, String[] searchFor)Determines whether or not the string 'searchIn' starts with one of the strings in 'searchFor', disregarding case and leading whitespacestatic booleanstartsWithIgnoreCaseAndWs(String searchIn, String searchFor, int beginPos)Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and leading whitespacestatic StringstringArrayToString(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 StringstripCommentsAndHints(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 StringtoAsciiString(byte[] buffer)Returns the bytes as an ASCII String.static StringtoAsciiString(byte[] buffer, int startPos, int length)Returns the bytes as an ASCII String.static StringtoHexString(byte[] byteBuffer, int length)Converts the given byte array into Hex String, stopping at given length.static StringtoString(byte[] value)static StringtoString(byte[] value, int offset, int length)static StringtoString(byte[] value, int offset, int length, String encoding)static StringtoString(byte[] value, String encoding)static byte[]unquoteBytes(byte[] bytes)static StringunQuoteIdentifier(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 booleanwildCompareIgnoreCase(String searchIn, String searchFor)Compares searchIn against searchForWildcard with wildcards, in a case insensitive manner.
-
-
-
方法详细资料
-
dumpAsHex
public static String dumpAsHex(byte[] byteBuffer, int length)
Returns the given bytes as a hex and ASCII dump (up to length bytes).- 参数:
byteBuffer- the data to dump as hexlength- the number of bytes to print- 返回:
- 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.- 参数:
byteBuffer- the byte array to convertlength- the number of bytes from the given array to convert- 返回:
- a String containing the Hex representation of the given bytes
-
firstNonWsCharUc
public static char firstNonWsCharUc(String searchIn)
Returns the first non-whitespace char, converted to upper case- 参数:
searchIn- the string to search in- 返回:
- 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- 参数:
dString- The value as a string- 返回:
- 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.- 参数:
s- source stringencoding- java encoding- 返回:
- 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.- 参数:
s- source stringbeginWrap- opening char delimiterendWrap- closing char delimiterencoding- java encoding- 返回:
- bytes
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(String searchIn, String searchFor)
Finds the position of a substring within a string ignoring case.- 参数:
searchIn- the string to search insearchFor- the array of strings to search for- 返回:
- the position where
searchForis found withinsearchInstarting fromstartingPosition.
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(int startingPosition, String searchIn, String searchFor)Finds the position of a substring within a string ignoring case.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search insearchFor- the array of strings to search for- 返回:
- the position where
searchForis found withinsearchInstarting fromstartingPosition.
-
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
searchModeprovided, when searching for the second and following stringsSearchMode.SKIP_WHITE_SPACEwill be added andSearchMode.SKIP_BETWEEN_MARKERSremoved.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search insearchForSequence- searchForSequenceopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipsearchMode- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where
searchForis found withinsearchInstarting fromstartingPosition.
-
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.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search insearchFor- the string to search foropeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipsearchMode- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where
searchForis found withinsearchInstarting fromstartingPosition.
-
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.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search insearchFor- the string to search foropeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where
searchForis found withinsearchInstarting fromstartingPosition.
-
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.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search inopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where the next non-whitespace character is found within
searchInstarting fromstartingPosition.
-
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.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search inopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where the next non-whitespace character is found within
searchInstarting fromstartingPosition.
-
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.- 参数:
startingPosition- the position to start the search fromsearchIn- the string to search inopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behavior of the search- 返回:
- the position where the next whitespace character is found within
searchInstarting fromstartingPosition.
-
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- 参数:
stringToSplit- the string to splitdelimiter- the string to split ontrim- should the split strings be whitespace trimmed?- 返回:
- the list of strings, split by delimiter
- 抛出:
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.- 参数:
stringToSplit- the string to splitdelimiter- the string to split onopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skiptrim- should the split strings be whitespace trimmed?- 返回:
- the list of strings, split by delimiter
- 抛出:
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.- 参数:
stringToSplit- the string to splitdelimiter- the string to split onopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skiptrim- should the split strings be whitespace trimmed?searchMode- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behaviour of the search- 返回:
- the list of strings, split by delimiter
- 抛出:
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.- 参数:
stringToSplit- the string to splitdelimiter- the string to split onopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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?- 返回:
- the list of strings, split by delimiter
- 抛出:
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.- 参数:
stringToSplit- the string to splitdelimiter- the string to split onopeningMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipoverridingMarkers- the subset ofopeningMarkersthat override the remaining markers, e.g., ifopeningMarkers = "'("andoverridingMarkers = "'"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- aSet, ideally anEnumSet, containing the flags from the enumStringUtils.SearchModethat determine the behaviour of the search- 返回:
- the list of strings, split by delimiter
- 抛出:
IllegalArgumentException- if an error occurs
-
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(...)- 参数:
searchIn- the string to search instartAt- the position to start atsearchFor- the string to search for- 返回:
- 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(...)- 参数:
searchIn- the string to search insearchFor- the string to search for- 返回:
- 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.- 参数:
searchIn- the string to search insearchFor- the string to search for- 返回:
- 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- 参数:
searchIn- the string to search insearchFor- the string to search for- 返回:
- 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- 参数:
searchIn- the string to search insearchFor- the string to search forbeginPos- where to start searching- 返回:
- 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- 参数:
searchIn- the string to search insearchFor- the string array to search for- 返回:
- 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(...)- 参数:
searchIn- the string to search insearchFor- the string to search for- 返回:
- whether searchIn ends with searchFor, ignoring case
-
stripEnclosure
public static byte[] stripEnclosure(byte[] source, String prefix, String suffix)- 参数:
source- bytes to stripprefix- prefixsuffix- suffix- 返回:
- result bytes
-
toAsciiString
public static String toAsciiString(byte[] buffer)
Returns the bytes as an ASCII String.- 参数:
buffer- the bytes representing the string- 返回:
- The ASCII String.
-
toAsciiString
public static String toAsciiString(byte[] buffer, int startPos, int length)
Returns the bytes as an ASCII String.- 参数:
buffer- the bytes to convertstartPos- the position to start convertinglength- the length of the string to convert- 返回:
- the ASCII string
-
toAsciiCharArray
public static char[] toAsciiCharArray(byte[] buffer, int startPos, int length)Returns the bytes as an ASCII String.- 参数:
buffer- the bytes to convertstartPos- the position to start convertinglength- the length of the string to convert- 返回:
- the ASCII char array
-
wildCompareIgnoreCase
public static boolean wildCompareIgnoreCase(String searchIn, String searchFor)
Compares searchIn against searchForWildcard with wildcards, in a case insensitive manner.- 参数:
searchIn- the string to search insearchFor- the string to search for, using the 'standard' SQL wildcard chars of '%' and '_'- 返回:
- true if matches
-
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.- 参数:
str1- first string to comparestr2- fecond string to compare- 返回:
trueif 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.- 参数:
source- the query string to clean up.openingMarkers- characters that delimit the beginning of a text block to skipclosingMarkers- characters that delimit the end of a text block to skipallowBackslashEscapes- whether or not backslash escapes are allowed- 返回:
- 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...- 参数:
src- the source string- 返回:
- 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 argumentdbis used in its place andsourcecorresponds to the full entity name. If argumentsourceis NULL or wildcard (%), returns an empty list.- 参数:
source- the source stringdb- database, if availablequoteId- quote character as defined on serverisNoBslashEscSet- is our connection in no BackSlashEscape mode- 返回:
- 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.- 参数:
db- database nameentity- identifierquoteId- quote character as defined on serverisPedantic- are we in pedantic mode- 返回:
- fully qualified name
-
isEmptyOrWhitespaceOnly
public static boolean isEmptyOrWhitespaceOnly(String str)
-
quoteIdentifier
public static String quoteIdentifier(String identifier, String quoteChar, boolean isPedantic)
Surrounds identifier with quoteChar and duplicates these symbols inside the identifier.- 参数:
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- 返回:
- 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
- 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
- null
-
quoteIdentifier
public static String quoteIdentifier(String identifier, boolean isPedantic)
Surrounds identifier with "`" and duplicates these symbols inside the identifier.- 参数:
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- 返回:
- 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
- null
-
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.- 参数:
identifier- identifierquoteChar- ` or "- 返回:
- 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
- null
-
indexOfQuoteDoubleAware
public static int indexOfQuoteDoubleAware(String searchIn, String quoteChar, int startFrom)
-
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.- 参数:
value- chars- 返回:
- bytes
-
getBytes
public static byte[] getBytes(char[] c, String encoding)Returns the byte[] representation of subset of the given char[] using the given encoding.- 参数:
c- charsencoding- java encoding- 返回:
- 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.- 参数:
value- charsoffset- offsetlength- lengthencoding- java encoding- 返回:
- bytes
-
getBytes
public static byte[] getBytes(String value)
-
getBytes
public static byte[] getBytes(String value, int offset, int length)
-
isValidIdChar
public static final boolean isValidIdChar(char c)
-
hexEscapeBlock
public static final void hexEscapeBlock(byte[] buf, int size, java.util.function.BiConsumer<Byte,Byte> bc)Used to escape binary data with hex- 参数:
buf- source bytessize- number of bytes to readbc- 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)
-
canHandleAsServerPreparedStatementNoCache
public static boolean canHandleAsServerPreparedStatementNoCache(String sql, ServerVersion serverVersion, boolean allowMultiQueries, boolean noBackslashEscapes, boolean useAnsiQuotes)
-
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.- 参数:
cs- The CharSequence to check.- 返回:
trueif the CharSequence not empty and contains only digits,falseotherwise.
-
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.- 参数:
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 elementslastDelimiter- the delimiter to be used before the last element.suffix- the suffix of the resulting String.- 返回:
- 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.- 参数:
src- string- 返回:
- 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"- 参数:
elements- the elements to join- 返回:
- 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)
-
-