public class StringUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addAsterisk(java.lang.String s,
int index)
Add an asterisk ('[*]') at the given position.
|
static java.lang.StringBuilder |
appendHex(java.lang.StringBuilder builder,
long x,
int bytes)
Appends specified number of trailing bytes from unsigned long value to a
specified string builder.
|
static void |
appendZeroPadded(java.lang.StringBuilder buff,
int length,
long positiveValue)
Append a zero-padded number to a string builder.
|
static java.lang.String |
arrayCombine(java.lang.String[] list,
char separatorChar)
Combine an array of strings to one array using the given separator
character.
|
static java.lang.String[] |
arraySplit(java.lang.String s,
char separatorChar,
boolean trim)
Split a string into an array of strings using the given separator.
|
static java.lang.String |
cache(java.lang.String s)
Get the string from the cache if possible.
|
static void |
clearCache()
Clear the cache.
|
static char[] |
cloneCharArray(char[] chars)
Create a new char array and copy all the data.
|
static java.lang.String |
convertBytesToHex(byte[] value)
Convert a byte array to a hex encoded string.
|
static java.lang.String |
convertBytesToHex(byte[] value,
int len)
Convert a byte array to a hex encoded string.
|
static java.lang.StringBuilder |
convertBytesToHex(java.lang.StringBuilder builder,
byte[] value)
Convert a byte array to a hex encoded string and appends it to a specified string builder.
|
static java.lang.StringBuilder |
convertBytesToHex(java.lang.StringBuilder builder,
byte[] value,
int len)
Convert a byte array to a hex encoded string and appends it to a specified string builder.
|
static byte[] |
convertHexToBytes(java.lang.String s)
Convert a hex encoded string to a byte array.
|
static java.io.ByteArrayOutputStream |
convertHexWithSpacesToBytes(java.io.ByteArrayOutputStream baos,
java.lang.String s)
Parses a hex encoded string with possible space separators and appends
the decoded binary string to the specified output stream.
|
static java.lang.String |
escapeMetaDataPattern(java.lang.String pattern)
Escape table or schema patterns used for DatabaseMetaData functions.
|
static java.lang.StringBuilder |
indent(java.lang.StringBuilder builder,
java.lang.String s,
int spaces,
boolean newline)
Indents a string with spaces and appends it to a specified builder.
|
static boolean |
isNullOrEmpty(java.lang.String s)
Check if a String is null or empty (the length is null).
|
static boolean |
isNumber(java.lang.String s)
Check if this string is a decimal number.
|
static boolean |
isWhitespaceOrEmpty(java.lang.String s)
Check if the specified string is empty or contains only whitespace.
|
static java.lang.String |
javaDecode(java.lang.String s)
Decode a text that is encoded as a Java string literal.
|
static java.lang.String |
javaEncode(java.lang.String s)
Convert a string to a Java literal using the correct escape sequences.
|
static void |
javaEncode(java.lang.String s,
java.lang.StringBuilder buff,
boolean forSQL)
Convert a string to a Java literal using the correct escape sequences.
|
static java.lang.StringBuilder |
join(java.lang.StringBuilder builder,
java.util.ArrayList<java.lang.String> strings,
java.lang.String separator)
Join specified strings and add them to the specified string builder.
|
static java.lang.String |
pad(java.lang.String string,
int n,
java.lang.String padding,
boolean right)
Pad a string.
|
static int |
parseUInt31(java.lang.String s,
int start,
int end)
Parses an unsigned 31-bit integer.
|
static java.lang.String |
quoteIdentifier(java.lang.String s)
Enclose a string with double quotes.
|
static java.lang.StringBuilder |
quoteIdentifier(java.lang.StringBuilder builder,
java.lang.String s)
Enclose a string with double quotes and append it to the specified
string builder.
|
static java.lang.String |
quoteJavaIntArray(int[] array)
Convert an int array to the Java source code that represents this array.
|
static java.lang.String |
quoteJavaString(java.lang.String s)
Convert a string to the Java literal and enclose it with double quotes.
|
static java.lang.String |
quoteJavaStringArray(java.lang.String[] array)
Convert a string array to the Java source code that represents this
array.
|
static java.lang.String |
quoteRemarkSQL(java.lang.String sql)
In a string, replace block comment marks with /++ ..
|
static java.lang.String |
quoteStringSQL(java.lang.String s)
Convert a string to a SQL literal.
|
static java.lang.StringBuilder |
quoteStringSQL(java.lang.StringBuilder builder,
java.lang.String s)
Convert a string to a SQL literal.
|
static java.lang.String |
replaceAll(java.lang.String s,
java.lang.String before,
java.lang.String after)
Replace all occurrences of the before string with the after string.
|
static java.lang.String |
toLowerEnglish(java.lang.String s)
Convert a string to lowercase using the English locale.
|
static java.lang.String |
toUpperEnglish(java.lang.String s)
Convert a string to uppercase using the English locale.
|
static java.lang.String |
trim(java.lang.String s,
boolean leading,
boolean trailing,
java.lang.String sp)
Trim a character from a string.
|
static java.lang.StringBuilder |
trimSubstring(java.lang.StringBuilder builder,
java.lang.String s,
int beginIndex,
int endIndex)
Trim a whitespace from a substring and append it to a specified string
builder.
|
static java.lang.String |
trimSubstring(java.lang.String s,
int beginIndex)
Trim a whitespace from a substring.
|
static java.lang.String |
trimSubstring(java.lang.String s,
int beginIndex,
int endIndex)
Trim a whitespace from a substring.
|
static java.lang.String |
unEnclose(java.lang.String s)
Remove enclosing '(' and ')' if this text is enclosed.
|
static java.lang.String |
urlDecode(java.lang.String encoded)
Decode the URL to a string.
|
static java.lang.String |
urlEncode(java.lang.String s)
Encode the string as a URL.
|
static java.lang.String |
xmlAttr(java.lang.String name,
java.lang.String value)
Creates an XML attribute of the form name="value".
|
static java.lang.String |
xmlCData(java.lang.String data)
Converts the data to a CDATA element.
|
static java.lang.String |
xmlComment(java.lang.String data)
Escapes a comment.
|
static java.lang.String |
xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content)
Create an XML node with optional attributes and content.
|
static java.lang.String |
xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content,
boolean indent)
Create an XML node with optional attributes and content.
|
static java.lang.String |
xmlStartDoc()
Returns <?xml version="1.0"?>
|
static java.lang.String |
xmlText(java.lang.String text)
Escapes an XML text element.
|
static java.lang.String |
xmlText(java.lang.String text,
boolean escapeNewline)
Escapes an XML text element.
|
public static java.lang.String toUpperEnglish(java.lang.String s)
s - the test to convertpublic static java.lang.String toLowerEnglish(java.lang.String s)
s - the text to convertpublic static java.lang.String quoteStringSQL(java.lang.String s)
s - the text to convert.public static java.lang.StringBuilder quoteStringSQL(java.lang.StringBuilder builder,
java.lang.String s)
builder - string builder to append result tos - the text to convert.public static java.lang.String javaEncode(java.lang.String s)
s - the text to convertpublic static void javaEncode(java.lang.String s,
java.lang.StringBuilder buff,
boolean forSQL)
s - the text to convertbuff - the Java representation to returnforSQL - true if we embedding this inside a STRINGDECODE SQL commandpublic static java.lang.String addAsterisk(java.lang.String s,
int index)
s - the textindex - the positionpublic static java.lang.String javaDecode(java.lang.String s)
s - the encoded stringpublic static java.lang.String quoteJavaString(java.lang.String s)
s - the text to convertpublic static java.lang.String quoteJavaStringArray(java.lang.String[] array)
array - the string arraypublic static java.lang.String quoteJavaIntArray(int[] array)
array - the int arraypublic static java.lang.String unEnclose(java.lang.String s)
s - the potentially enclosed stringpublic static java.lang.String urlEncode(java.lang.String s)
s - the string to encodepublic static java.lang.String urlDecode(java.lang.String encoded)
encoded - the encoded URLpublic static java.lang.String[] arraySplit(java.lang.String s,
char separatorChar,
boolean trim)
s - the string to splitseparatorChar - the separator charactertrim - whether each element should be trimmedpublic static java.lang.String arrayCombine(java.lang.String[] list,
char separatorChar)
list - the string arrayseparatorChar - the separator characterpublic static java.lang.StringBuilder join(java.lang.StringBuilder builder,
java.util.ArrayList<java.lang.String> strings,
java.lang.String separator)
builder - string builderstrings - strings to joinseparator - separatorpublic static java.lang.String xmlAttr(java.lang.String name,
java.lang.String value)
name - the attribute namevalue - the attribute valuepublic static java.lang.String xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content)
name - the element nameattributes - the attributes (may be null)content - the content (may be null)public static java.lang.String xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content,
boolean indent)
name - the element nameattributes - the attributes (may be null)content - the content (may be null)indent - whether to indent the content if it contains a newlinepublic static java.lang.StringBuilder indent(java.lang.StringBuilder builder,
java.lang.String s,
int spaces,
boolean newline)
builder - string builder to append tos - the stringspaces - the number of spacesnewline - append a newline if there is nonepublic static java.lang.String xmlComment(java.lang.String data)
data - the comment textpublic static java.lang.String xmlCData(java.lang.String data)
data - the text datapublic static java.lang.String xmlStartDoc()
public static java.lang.String xmlText(java.lang.String text)
text - the text datapublic static java.lang.String xmlText(java.lang.String text,
boolean escapeNewline)
text - the text dataescapeNewline - whether to escape newlinespublic static java.lang.String replaceAll(java.lang.String s,
java.lang.String before,
java.lang.String after)
String.replaceAll(String, String) this method reads before
and after arguments as plain strings and if before argument
is an empty string this method returns original string s.s - the stringbefore - the old textafter - the new textpublic static java.lang.String quoteIdentifier(java.lang.String s)
s - the textpublic static java.lang.StringBuilder quoteIdentifier(java.lang.StringBuilder builder,
java.lang.String s)
builder - string builder to append tos - the textpublic static boolean isNullOrEmpty(java.lang.String s)
s - the string to checkpublic static java.lang.String quoteRemarkSQL(java.lang.String sql)
sql - the stringpublic static java.lang.String pad(java.lang.String string,
int n,
java.lang.String padding,
boolean right)
string - the original stringn - the target lengthpadding - the padding stringright - true if the padding should be appended at the endpublic static char[] cloneCharArray(char[] chars)
chars - the char array (may be null)public static java.lang.String trim(java.lang.String s,
boolean leading,
boolean trailing,
java.lang.String sp)
s - the stringleading - if leading characters should be removedtrailing - if trailing characters should be removedsp - what to remove (only the first character is used)
or null for a spacepublic static java.lang.String trimSubstring(java.lang.String s,
int beginIndex)
substring(beginIndex).trim().s - the stringbeginIndex - start index of substring (inclusive)public static java.lang.String trimSubstring(java.lang.String s,
int beginIndex,
int endIndex)
substring(beginIndex, endIndex).trim().s - the stringbeginIndex - start index of substring (inclusive)endIndex - end index of substring (exclusive)public static java.lang.StringBuilder trimSubstring(java.lang.StringBuilder builder,
java.lang.String s,
int beginIndex,
int endIndex)
builder.append(substring(beginIndex, endIndex).trim()).builder - string builder to append tos - the stringbeginIndex - start index of substring (inclusive)endIndex - end index of substring (exclusive)public static java.lang.String cache(java.lang.String s)
s - the original stringpublic static void clearCache()
public static int parseUInt31(java.lang.String s,
int start,
int end)
s - string to parsestart - the beginning index, inclusiveend - the ending index, exclusiveint not greater than Integer.MAX_VALUE.public static byte[] convertHexToBytes(java.lang.String s)
s - the hex encoded stringpublic static java.io.ByteArrayOutputStream convertHexWithSpacesToBytes(java.io.ByteArrayOutputStream baos,
java.lang.String s)
baos - the output stream, or nulls - the hex encoded stringpublic static java.lang.String convertBytesToHex(byte[] value)
value - the byte arraypublic static java.lang.String convertBytesToHex(byte[] value,
int len)
value - the byte arraylen - the number of bytes to encodepublic static java.lang.StringBuilder convertBytesToHex(java.lang.StringBuilder builder,
byte[] value)
builder - string builder to append tovalue - the byte arraypublic static java.lang.StringBuilder convertBytesToHex(java.lang.StringBuilder builder,
byte[] value,
int len)
builder - string builder to append tovalue - the byte arraylen - the number of bytes to encodepublic static java.lang.StringBuilder appendHex(java.lang.StringBuilder builder,
long x,
int bytes)
builder - string builder to append tox - value to appendbytes - number of bytes to appendpublic static boolean isNumber(java.lang.String s)
s - the stringpublic static boolean isWhitespaceOrEmpty(java.lang.String s)
s - the stringpublic static void appendZeroPadded(java.lang.StringBuilder buff,
int length,
long positiveValue)
buff - the string builderlength - the number of characters to appendpositiveValue - the number to appendpublic static java.lang.String escapeMetaDataPattern(java.lang.String pattern)
pattern - the pattern