A few String utility functions.
| Methods |
| static String |
addAsterisk(String s, int index)
Add an asterisk ('[*]') at the given position.
|
| static String |
addAsterisk(String s, int index)
Add an asterisk ('[*]') at the given position. This format is used to
show where parsing failed in a statement.
Parameters:
s - the text
index - the position
Returns:
the text with asterisk
|
| static void |
appendZeroPadded(StringBuilder buff, int length, long positiveValue)
Append a zero-padded number to a string builder.
|
| static void |
appendZeroPadded(StringBuilder buff, int length, long positiveValue)
Append a zero-padded number to a string builder.
Parameters:
buff - the string builder
length - the number of characters to append
positiveValue - the number to append
|
| static String |
arrayCombine(String[] list, char separatorChar)
Combine an array of strings to one array using the given separator
character.
|
| static String |
arrayCombine(String[] list, char separatorChar)
Combine an array of strings to one array using the given separator
character. A backslash and the separator character and escaped using a
backslash.
Parameters:
list - the string array
separatorChar - the separator character
Returns:
the combined string
|
| static String[] |
arraySplit(String s, char separatorChar, boolean trim)
Split a string into an array of strings using the given separator.
|
| static String[] |
arraySplit(String s, char separatorChar, boolean trim)
Split a string into an array of strings using the given separator. A null
string will result in a null array, and an empty string in a zero element
array.
Parameters:
s - the string to split
separatorChar - the separator character
trim - whether each element should be trimmed
Returns:
the array list
|
| static String |
cache(String s)
Get the string from the cache if possible.
|
| static String |
cache(String s)
Get the string from the cache if possible. If the string has not been
found, it is added to the cache. If there is such a string in the cache,
that one is returned.
Parameters:
s - the original string
Returns:
a string with the same content, if possible from the cache
|
| static void |
clearCache()
Clear the cache.
|
| static void |
clearCache()
Clear the cache. This method is used for testing.
|
| static char[] |
cloneCharArray(char[] chars)
Create a new char array and copy all the data.
|
| static char[] |
cloneCharArray(char[] chars)
Create a new char array and copy all the data. If the size of the byte
array is zero, the same array is returned.
Parameters:
chars - the char array (may be null)
Returns:
a new char array
|
| static String |
convertBytesToHex(byte[] value)
Convert a byte array to a hex encoded string.
|
| static String |
convertBytesToHex(byte[] value)
Convert a byte array to a hex encoded string.
Parameters:
value - the byte array
Returns:
the hex encoded string
|
| static String |
convertBytesToHex(byte[] value, int len)
Convert a byte array to a hex encoded string.
|
| static String |
convertBytesToHex(byte[] value, int len)
Convert a byte array to a hex encoded string.
Parameters:
value - the byte array
len - the number of bytes to encode
Returns:
the hex encoded string
|
| static byte[] |
convertHexToBytes(String s)
Convert a hex encoded string to a byte array.
|
| static byte[] |
convertHexToBytes(String s)
Convert a hex encoded string to a byte array.
Parameters:
s - the hex encoded string
Returns:
the byte array
|
| static String |
enclose(String s)
Enclose a string with '(' and ')' if this is not yet done.
|
| static String |
enclose(String s)
Enclose a string with '(' and ')' if this is not yet done.
Parameters:
s - the string
Returns:
the enclosed string
|
| static String |
escapeMetaDataPattern(String pattern)
Escape table or schema patterns used for DatabaseMetaData functions.
|
| static String |
escapeMetaDataPattern(String pattern)
Escape table or schema patterns used for DatabaseMetaData functions.
Parameters:
pattern - the pattern
Returns:
the escaped pattern
|
| static String |
indent(String s)
Indents a string with 4 spaces.
|
| static String |
indent(String s)
Indents a string with 4 spaces.
Parameters:
s - the string
Returns:
the indented string
|
| static String |
indent(String s, int spaces, boolean newline)
Indents a string with spaces.
|
| static String |
indent(String s, int spaces, boolean newline)
Indents a string with spaces.
Parameters:
s - the string
spaces - the number of spaces
newline - append a newline if there is none
Returns:
the indented string
|
| static boolean |
isNullOrEmpty(String s)
Check if a String is null or empty (the length is null).
|
| static boolean |
isNullOrEmpty(String s)
Check if a String is null or empty (the length is null).
Parameters:
s - the string to check
Returns:
true if it is null or empty
|
| static boolean |
isNumber(String s)
Check if this string is a decimal number.
|
| static boolean |
isNumber(String s)
Check if this string is a decimal number.
Parameters:
s - the string
Returns:
true if it is
|
| static String |
javaDecode(String s)
Decode a text that is encoded as a Java string literal.
|
| static String |
javaDecode(String s)
Decode a text that is encoded as a Java string literal. The Java
properties file format and Java source code format is supported.
Parameters:
s - the encoded string
Returns:
the string
|
| static String |
javaEncode(String s)
Convert a string to a Java literal using the correct escape sequences.
|
| static String |
javaEncode(String s)
Convert a string to a Java literal using the correct escape sequences.
The literal is not enclosed in double quotes. The result can be used in
properties files or in Java source code.
Parameters:
s - the text to convert
Returns:
the Java representation
|
| static String |
pad(String string, int n, String padding, boolean right)
Pad a string.
|
| static String |
pad(String string, int n, String padding, boolean right)
Pad a string. This method is used for the SQL function RPAD and LPAD.
Parameters:
string - the original string
n - the target length
padding - the padding string
right - true if the padding should be appended at the end
Returns:
the padded string
|
| static String |
quoteIdentifier(String s)
Enclose a string with double quotes.
|
| static String |
quoteIdentifier(String s)
Enclose a string with double quotes. A double quote inside the string is
escaped using a double quote.
Parameters:
s - the text
Returns:
the double quoted text
|
| static String |
quoteJavaIntArray(int[] array)
Convert an int array to the Java source code that represents this array.
|
| static String |
quoteJavaIntArray(int[] array)
Convert an int array to the Java source code that represents this array.
Null will be converted to 'null'.
Parameters:
array - the int array
Returns:
the Java source code (including new int[]{})
|
| static String |
quoteJavaString(String s)
Convert a string to the Java literal and enclose it with double quotes.
|
| static String |
quoteJavaString(String s)
Convert a string to the Java literal and enclose it with double quotes.
Null will result in "null" (without double quotes).
Parameters:
s - the text to convert
Returns:
the Java representation
|
| static String |
quoteJavaStringArray(String[] array)
Convert a string array to the Java source code that represents this
array.
|
| static String |
quoteJavaStringArray(String[] array)
Convert a string array to the Java source code that represents this
array. Null will be converted to 'null'.
Parameters:
array - the string array
Returns:
the Java source code (including new String[]{})
|
| static String |
(String sql)
In a string, replace block comment marks with /++ ..
|
| static String |
(String sql)
In a string, replace block comment marks with /++ .. ++/.
Parameters:
sql - the string
Returns:
the resulting string
|
| static String |
quoteStringSQL(String s)
Convert a string to a SQL literal.
|
| static String |
quoteStringSQL(String s)
Convert a string to a SQL literal. Null is converted to NULL. The text is
enclosed in single quotes. If there are any special characters, the
method STRINGDECODE is used.
Parameters:
s - the text to convert.
Returns:
the SQL literal
|
| static String |
replaceAll(String s, String before, String after)
Replace all occurrences of the before string with the after string.
|
| static String |
replaceAll(String s, String before, String after)
Replace all occurrences of the before string with the after string. Unlike
{@link String#replaceAll(String, String)} this method reads {@code before}
and {@code after} arguments as plain strings and if {@code before} argument
is an empty string this method returns original string {@code s}.
Parameters:
s - the string
before - the old text
after - the new text
Returns:
the string with the before string replaced
|
| static boolean |
startsWithIgnoreCase(String s, String start)
Check is a string starts with another string, ignoring the case.
|
| static boolean |
startsWithIgnoreCase(String s, String start)
Check is a string starts with another string, ignoring the case.
Parameters:
s - the string to check (must be longer than start)
start - the prefix of s
Returns:
true if start is a prefix of s
|
| static String |
toLowerEnglish(String s)
Convert a string to lowercase using the English locale.
|
| static String |
toLowerEnglish(String s)
Convert a string to lowercase using the English locale.
Parameters:
s - the text to convert
Returns:
the lowercase text
|
| static String |
toUpperEnglish(String s)
Convert a string to uppercase using the English locale.
|
| static String |
toUpperEnglish(String s)
Convert a string to uppercase using the English locale.
Parameters:
s - the test to convert
Returns:
the uppercase text
|
| static String |
trim(String s, boolean leading, boolean trailing, String sp)
Trim a character from a string.
|
| static String |
trim(String s, boolean leading, boolean trailing, String sp)
Trim a character from a string.
Parameters:
s - the string
leading - if leading characters should be removed
trailing - if trailing characters should be removed
sp - what to remove (only the first character is used)
or null for a space
Returns:
the trimmed string
|
| static String |
unEnclose(String s)
Remove enclosing '(' and ')' if this text is enclosed.
|
| static String |
unEnclose(String s)
Remove enclosing '(' and ')' if this text is enclosed.
Parameters:
s - the potentially enclosed string
Returns:
the string
|
| static String |
urlDecode(String encoded)
Decode the URL to a string.
|
| static String |
urlDecode(String encoded)
Decode the URL to a string.
Parameters:
encoded - the encoded URL
Returns:
the decoded string
|
| static String |
urlEncode(String s)
Encode the string as an URL.
|
| static String |
urlEncode(String s)
Encode the string as an URL.
Parameters:
s - the string to encode
Returns:
the encoded string
|
| static String |
xmlAttr(String name, String value)
Creates an XML attribute of the form name="value".
|
| static String |
xmlAttr(String name, String value)
Creates an XML attribute of the form name="value".
A single space is prepended to the name,
so that multiple attributes can be concatenated.
Parameters:
name - the attribute name
value - the attribute value
Returns:
the attribute
|
| static String |
xmlCData(String data)
Converts the data to a CDATA element.
|
| static String |
xmlCData(String data)
Converts the data to a CDATA element.
If the data contains ']]>', it is escaped as a text element.
Parameters:
data - the text data
Returns:
<![CDATA[data]]>
|
| static String |
(String data)
Escapes a comment.
|
| static String |
(String data)
Escapes a comment.
If the data contains '--', it is converted to '- -'.
The data is indented with 4 spaces if it contains a newline character.
Parameters:
data - the comment text
Returns:
<!-- data -->
|
| static String |
xmlNode(String name, String attributes, String content)
Create an XML node with optional attributes and content.
|
| static String |
xmlNode(String name, String attributes, String content)
Create an XML node with optional attributes and content.
The data is indented with 4 spaces if it contains a newline character.
Parameters:
name - the element name
attributes - the attributes (may be null)
content - the content (may be null)
Returns:
the node
|
| static String |
xmlNode(String name, String attributes, String content, boolean indent)
Create an XML node with optional attributes and content.
|
| static String |
xmlNode(String name, String attributes, String content, boolean indent)
Create an XML node with optional attributes and content. The data is
indented with 4 spaces if it contains a newline character and the indent
parameter is set to true.
Parameters:
name - the element name
attributes - the attributes (may be null)
content - the content (may be null)
indent - whether to indent the content if it contains a newline
Returns:
the node
|
| static String |
xmlStartDoc()
Returns <?xml version="1.0"?>
|
| static String |
xmlStartDoc()
Returns <?xml version="1.0"?>
Returns:
<?xml version="1.0"?>
|
| static String |
xmlText(String text)
Escapes an XML text element.
|
| static String |
xmlText(String text)
Escapes an XML text element.
Parameters:
text - the text data
Returns:
the escaped text
|
| static String |
xmlText(String text, boolean escapeNewline)
Escapes an XML text element.
|
| static String |
xmlText(String text, boolean escapeNewline)
Escapes an XML text element.
Parameters:
text - the text data
escapeNewline - whether to escape newlines
Returns:
the escaped text
|