com.mysql.jdbc
public class StringUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static int |
WILD_COMPARE_MATCH_NO_WILD |
(package private) static int |
WILD_COMPARE_MATCH_WITH_WILD |
(package private) static int |
WILD_COMPARE_NO_MATCH |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
consistentToString(java.math.BigDecimal decimal)
Takes care of the fact that Sun changed the output of
BigDecimal.toString() between JDK-1.4 and JDK 5
|
static java.lang.String |
dumpAsHex(byte[] byteBuffer,
int length)
Dumps the given bytes to STDOUT as a hex dump (up to length bytes).
|
static byte[] |
escapeEasternUnicodeByteStream(byte[] origBytes,
java.lang.String origString,
int offset,
int length)
Unfortunately, SJIS has 0x5c as a high byte in some of its double-byte
characters, so we need to escape it.
|
static java.lang.String |
escapeQuote(java.lang.String src,
java.lang.String quotChar) |
(package private) static java.nio.charset.Charset |
findCharset(java.lang.String alias) |
static char |
firstAlphaCharUc(java.lang.String searchIn,
int startAt) |
static char |
firstNonWsCharUc(java.lang.String searchIn)
Returns the first non whitespace char, converted to upper case
|
static char |
firstNonWsCharUc(java.lang.String searchIn,
int startAt) |
static java.lang.String |
fixDecimalExponent(java.lang.String dString)
Adds '+' to decimal numbers that are positive (MySQL doesn't understand
them otherwise
|
static byte[] |
getBytes(char[] c,
SingleByteCharsetConverter converter,
java.lang.String encoding,
java.lang.String serverEncoding,
boolean parserKnowsUnicode,
ExceptionInterceptor exceptionInterceptor) |
static byte[] |
getBytes(char[] c,
SingleByteCharsetConverter converter,
java.lang.String encoding,
java.lang.String serverEncoding,
int offset,
int length,
boolean parserKnowsUnicode,
ExceptionInterceptor exceptionInterceptor) |
static byte[] |
getBytes(char[] c,
java.lang.String encoding,
java.lang.String serverEncoding,
boolean parserKnowsUnicode,
MySQLConnection conn,
ExceptionInterceptor exceptionInterceptor) |
static byte[] |
getBytes(java.lang.String value) |
static byte[] |
getBytes(java.lang.String s,
SingleByteCharsetConverter converter,
java.lang.String encoding,
java.lang.String serverEncoding,
boolean parserKnowsUnicode,
ExceptionInterceptor exceptionInterceptor)
Returns the byte[] representation of the given string (re)using the given
charset converter, and the given encoding.
|
static byte[] |
getBytes(java.lang.String s,
SingleByteCharsetConverter converter,
java.lang.String encoding,
java.lang.String serverEncoding,
int offset,
int length,
boolean parserKnowsUnicode,
ExceptionInterceptor exceptionInterceptor)
DOCUMENT ME!
|
static byte[] |
getBytes(java.lang.String value,
java.lang.String encoding) |
static byte[] |
getBytes(java.lang.String s,
java.lang.String encoding,
java.lang.String serverEncoding,
boolean parserKnowsUnicode,
MySQLConnection conn,
ExceptionInterceptor exceptionInterceptor)
Returns the byte[] representation of the given string using given
encoding.
|
static byte[] |
getBytesWrapped(java.lang.String s,
char beginWrap,
char endWrap,
SingleByteCharsetConverter converter,
java.lang.String encoding,
java.lang.String serverEncoding,
boolean parserKnowsUnicode,
ExceptionInterceptor exceptionInterceptor) |
static int |
getInt(byte[] buf) |
static int |
getInt(byte[] buf,
int offset,
int endPos) |
static long |
getLong(byte[] buf) |
static long |
getLong(byte[] buf,
int offset,
int endpos) |
static short |
getShort(byte[] buf) |
static int |
indexOf(byte[] s,
char c) |
static int |
indexOfIgnoreCase(int startingPosition,
java.lang.String searchIn,
java.lang.String searchFor) |
static int |
indexOfIgnoreCase(java.lang.String searchIn,
java.lang.String searchFor)
DOCUMENT ME!
|
static int |
indexOfIgnoreCaseRespectMarker(int startAt,
java.lang.String src,
java.lang.String target,
java.lang.String marker,
java.lang.String markerCloses,
boolean allowBackslashEscapes) |
static int |
indexOfIgnoreCaseRespectQuotes(int startAt,
java.lang.String src,
java.lang.String target,
char quoteChar,
boolean allowBackslashEscapes) |
static boolean |
isEmptyOrWhitespaceOnly(java.lang.String str) |
static boolean |
isNullOrEmpty(java.lang.String toTest) |
static boolean |
isValidIdChar(char c) |
static int |
lastIndexOf(byte[] s,
char c) |
(package private) static byte[] |
s2b(java.lang.String s,
MySQLConnection conn) |
static java.lang.String |
sanitizeProcOrFuncName(java.lang.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 java.util.List<java.lang.String> |
split(java.lang.String stringToSplit,
java.lang.String delimitter,
boolean trim)
Splits stringToSplit into a list, using the given delimitter
|
static java.util.List<java.lang.String> |
split(java.lang.String stringToSplit,
java.lang.String delimiter,
java.lang.String markers,
java.lang.String markerCloses,
boolean trim)
Splits stringToSplit into a list, using the given delimitter
|
static java.util.List<java.lang.String> |
splitDBdotName(java.lang.String src,
java.lang.String cat,
java.lang.String quotId,
boolean isNoBslashEscSet)
Next we check if there is anything to split.
|
static boolean |
startsWithIgnoreCase(java.lang.String searchIn,
int startAt,
java.lang.String searchFor)
Determines whether or not the string 'searchIn' contains the string
'searchFor', dis-regarding case starting at 'startAt' Shorthand for a
String.regionMatch(...)
|
static boolean |
startsWithIgnoreCase(java.lang.String searchIn,
java.lang.String searchFor)
Determines whether or not the string 'searchIn' contains the string
'searchFor', dis-regarding case.
|
static boolean |
startsWithIgnoreCaseAndNonAlphaNumeric(java.lang.String searchIn,
java.lang.String searchFor)
Determines whether or not the sting 'searchIn' contains the string
'searchFor', disregarding case,leading whitespace and non-alphanumeric
characters.
|
static boolean |
startsWithIgnoreCaseAndWs(java.lang.String searchIn,
java.lang.String searchFor)
Determines whether or not the sting 'searchIn' contains the string
'searchFor', disregarding case and leading whitespace
|
static boolean |
startsWithIgnoreCaseAndWs(java.lang.String searchIn,
java.lang.String searchFor,
int beginPos)
Determines whether or not the sting 'searchIn' contains the string
'searchFor', disregarding case and leading whitespace
|
static java.lang.String |
stripComments(java.lang.String src,
java.lang.String stringOpens,
java.lang.String stringCloses,
boolean slashStarComments,
boolean slashSlashComments,
boolean hashComments,
boolean dashDashComments)
Returns the given string, with comments removed
|
static byte[] |
stripEnclosure(byte[] source,
java.lang.String prefix,
java.lang.String suffix) |
static java.lang.String |
toAsciiString(byte[] buffer)
Returns the bytes as an ASCII String.
|
static java.lang.String |
toAsciiString(byte[] buffer,
int startPos,
int length)
Returns the bytes as an ASCII String.
|
static java.lang.String |
toString(byte[] value) |
static java.lang.String |
toString(byte[] value,
int offset,
int length) |
static java.lang.String |
toString(byte[] value,
int offset,
int length,
java.lang.String encoding) |
static java.lang.String |
toString(byte[] value,
java.lang.String encoding) |
static int |
wildCompare(java.lang.String searchIn,
java.lang.String searchForWildcard)
Compares searchIn against searchForWildcard with wildcards (heavily
borrowed from strings/ctype-simple.c in the server sources)
|
static final int WILD_COMPARE_MATCH_NO_WILD
static final int WILD_COMPARE_MATCH_WITH_WILD
static final int WILD_COMPARE_NO_MATCH
static java.nio.charset.Charset findCharset(java.lang.String alias) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String consistentToString(java.math.BigDecimal decimal)
decimal
- the big decimal to stringifypublic static final java.lang.String dumpAsHex(byte[] byteBuffer, int length)
byteBuffer
- the data to print as hexlength
- the number of bytes to printpublic static byte[] escapeEasternUnicodeByteStream(byte[] origBytes, java.lang.String origString, int offset, int length)
origBytes
- the original bytes in SJIS formatorigString
- the string that had .getBytes() called on itoffset
- where to start converting fromlength
- how many characters to convert.public static char firstNonWsCharUc(java.lang.String searchIn)
searchIn
- the string to search inpublic static char firstNonWsCharUc(java.lang.String searchIn, int startAt)
public static char firstAlphaCharUc(java.lang.String searchIn, int startAt)
public static final java.lang.String fixDecimalExponent(java.lang.String dString)
dString
- The value as a stringpublic static final byte[] getBytes(char[] c, SingleByteCharsetConverter converter, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
java.sql.SQLException
public static final byte[] getBytes(char[] c, SingleByteCharsetConverter converter, java.lang.String encoding, java.lang.String serverEncoding, int offset, int length, boolean parserKnowsUnicode, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
java.sql.SQLException
public static final byte[] getBytes(char[] c, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode, MySQLConnection conn, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
java.sql.SQLException
public static final byte[] getBytes(java.lang.String s, SingleByteCharsetConverter converter, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
s
- the string to convertconverter
- the converter to reuseencoding
- the character encoding to useserverEncoding
- DOCUMENT ME!parserKnowsUnicode
- DOCUMENT ME!java.sql.SQLException
- if an encoding unsupported by the JVM is supplied.public static final byte[] getBytesWrapped(java.lang.String s, char beginWrap, char endWrap, SingleByteCharsetConverter converter, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
java.sql.SQLException
public static final byte[] getBytes(java.lang.String s, SingleByteCharsetConverter converter, java.lang.String encoding, java.lang.String serverEncoding, int offset, int length, boolean parserKnowsUnicode, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
s
- DOCUMENT ME!converter
- DOCUMENT ME!encoding
- DOCUMENT ME!serverEncoding
- DOCUMENT ME!offset
- DOCUMENT ME!length
- DOCUMENT ME!parserKnowsUnicode
- DOCUMENT ME!java.sql.SQLException
- DOCUMENT ME!public static final byte[] getBytes(java.lang.String s, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode, MySQLConnection conn, ExceptionInterceptor exceptionInterceptor) throws java.sql.SQLException
s
- the string to convertencoding
- the character encoding to useparserKnowsUnicode
- DOCUMENT ME!java.sql.SQLException
- if an encoding unsupported by the JVM is supplied.public static int getInt(byte[] buf, int offset, int endPos) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static int getInt(byte[] buf) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static long getLong(byte[] buf) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static long getLong(byte[] buf, int offset, int endpos) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static short getShort(byte[] buf) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static final int indexOfIgnoreCase(int startingPosition, java.lang.String searchIn, java.lang.String searchFor)
public static final int indexOfIgnoreCase(java.lang.String searchIn, java.lang.String searchFor)
searchIn
- DOCUMENT ME!searchFor
- DOCUMENT ME!public static int indexOfIgnoreCaseRespectMarker(int startAt, java.lang.String src, java.lang.String target, java.lang.String marker, java.lang.String markerCloses, boolean allowBackslashEscapes)
public static int indexOfIgnoreCaseRespectQuotes(int startAt, java.lang.String src, java.lang.String target, char quoteChar, boolean allowBackslashEscapes)
public static final java.util.List<java.lang.String> split(java.lang.String stringToSplit, java.lang.String delimitter, boolean trim)
stringToSplit
- the string to splitdelimitter
- the string to split ontrim
- should the split strings be whitespace trimmed?java.lang.IllegalArgumentException
- DOCUMENT ME!public static final java.util.List<java.lang.String> split(java.lang.String stringToSplit, java.lang.String delimiter, java.lang.String markers, java.lang.String markerCloses, boolean trim)
stringToSplit
- the string to splitdelimitter
- the string to split ontrim
- should the split strings be whitespace trimmed?java.lang.IllegalArgumentException
- DOCUMENT ME!public static boolean startsWithIgnoreCase(java.lang.String searchIn, int startAt, java.lang.String searchFor)
searchIn
- the string to search instartAt
- the position to start atsearchFor
- the string to search forpublic static boolean startsWithIgnoreCase(java.lang.String searchIn, java.lang.String searchFor)
searchIn
- the string to search insearchFor
- the string to search forpublic static boolean startsWithIgnoreCaseAndNonAlphaNumeric(java.lang.String searchIn, java.lang.String searchFor)
searchIn
- the string to search insearchFor
- the string to search forpublic static boolean startsWithIgnoreCaseAndWs(java.lang.String searchIn, java.lang.String searchFor)
searchIn
- the string to search insearchFor
- the string to search forpublic static boolean startsWithIgnoreCaseAndWs(java.lang.String searchIn, java.lang.String searchFor, int beginPos)
searchIn
- the string to search insearchFor
- the string to search forbeginPos
- where to start searchingpublic static byte[] stripEnclosure(byte[] source, java.lang.String prefix, java.lang.String suffix)
bytesToStrip
- prefix
- suffix
- public static final java.lang.String toAsciiString(byte[] buffer)
buffer
- the bytes representing the stringpublic static final java.lang.String toAsciiString(byte[] buffer, int startPos, int length)
buffer
- the bytes to convertstartPos
- the position to start convertinglength
- the length of the string to convertpublic static int wildCompare(java.lang.String searchIn, java.lang.String searchForWildcard)
searchIn
- the string to search insearchForWildcard
- the string to search for, using the 'standard' SQL wildcard
chars of '%' and '_'static byte[] s2b(java.lang.String s, MySQLConnection conn) throws java.sql.SQLException
java.sql.SQLException
public static int lastIndexOf(byte[] s, char c)
public static int indexOf(byte[] s, char c)
public static boolean isNullOrEmpty(java.lang.String toTest)
public static java.lang.String stripComments(java.lang.String src, java.lang.String stringOpens, java.lang.String stringCloses, boolean slashStarComments, boolean slashSlashComments, boolean hashComments, boolean dashDashComments)
src
- the source stringstringOpens
- characters which delimit the "open" of a stringstringCloses
- characters which delimit the "close" of a string, in
counterpart order to stringOpens
slashStarComments
- strip slash-star type "C" style commentsslashSlashComments
- strip slash-slash C++ style comments to end-of-linehashComments
- strip #-style comments to end-of-linedashDashComments
- strip "--" style comments to end-of-linepublic static java.lang.String sanitizeProcOrFuncName(java.lang.String src)
src
- the source stringpublic static java.util.List<java.lang.String> splitDBdotName(java.lang.String src, java.lang.String cat, java.lang.String quotId, boolean isNoBslashEscSet)
src
- the source stringcat
- Catalog, if availablequotId
- quoteId as defined on serverisNoBslashEscSet
- Is our connection in BackSlashEscape modepublic static final boolean isEmptyOrWhitespaceOnly(java.lang.String str)
public static java.lang.String escapeQuote(java.lang.String src, java.lang.String quotChar)
public static java.lang.String toString(byte[] value, int offset, int length, java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String toString(byte[] value, java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String toString(byte[] value, int offset, int length)
public static java.lang.String toString(byte[] value)
public static byte[] getBytes(java.lang.String value, java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static byte[] getBytes(java.lang.String value)
public static final boolean isValidIdChar(char c)