Top Description Fields Constructors Methods
org.h2.util

public Class StringUtils

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, java.lang.ref.SoftReference, java.net.URLEncoder, java.nio.charset.StandardCharsets, java.text.Collator, java.util.ArrayList, .Arrays, .HashSet, .Locale, java.util.concurrent.TimeUnit, java.util.function.IntPredicate, org.h2.api.ErrorCode, org.h2.engine.SysProperties, org.h2.message.DbException

A few String utility functions.

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final int[]
private static SoftReference<String[]>
private static long
private static final String[][]
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the text with asterisk
addAsterisk
(String
the text
s
,
int
the position
index
)

Add an asterisk ('[*]') at the given position.

public static StringBuilder

Returns:

the specified string builder
appendHex
(StringBuilder
string builder to append to
builder
,
long
value to append
x
,
int
number of bytes to append
bytes
)

Appends specified number of trailing bytes from unsigned long value to a specified string builder.

public static StringBuilder

Returns:

the specified string builder
appendToLength
(StringBuilder
the string builder
builder
,
String
the string to append
s
,
int
the length limit
length
)

Appends the specified string or its part to the specified builder with maximum builder length limit.

public static StringBuilder

Returns:

the specified string builder
appendTwoDigits
(StringBuilder
the string builder
builder
,
int
the number to append
positiveValue
)

Append a zero-padded number from 00 to 99 to a string builder.

public static StringBuilder

Returns:

the specified string builder
appendZeroPadded
(StringBuilder
the string builder
builder
,
int
the number of characters to append
length
,
int
the number to append
positiveValue
)

Append a zero-padded number to a string builder.

public static String

Returns:

the combined string
arrayCombine
(String[]
the string array
list
,
char
the separator character
separatorChar
)

Combine an array of strings to one array using the given separator character.

public static String[]

Returns:

the array list
arraySplit
(String
the string to split
s
,
char
the separator character
separatorChar
,
boolean
whether each element should be trimmed
trim
)

Split a string into an array of strings using the given separator.

public static String

Returns:

a string with the same content, if possible from the cache
cache
(String
the original string
s
)

Get the string from the cache if possible.

public static void
clearCache()

Clear the cache.

public static char[]

Returns:

a new char array
cloneCharArray
(char[]
the char array (may be null)
chars
)

Create a new char array and copy all the data.

public static String

Returns:

the hex encoded string
convertBytesToHex
(byte[]
the byte array
value
)

Convert a byte array to a hex encoded string.

public static String

Returns:

the hex encoded string
convertBytesToHex
(byte[]
the byte array
value
,
int
the number of bytes to encode
len
)

Convert a byte array to a hex encoded string.

public static StringBuilder

Returns:

the hex encoded string
convertBytesToHex
(StringBuilder
string builder to append to
builder
,
byte[]
the byte array
value
)

Convert a byte array to a hex encoded string and appends it to a specified string builder.

public static StringBuilder

Returns:

the hex encoded string
convertBytesToHex
(StringBuilder
string builder to append to
builder
,
byte[]
the byte array
value
,
int
the number of bytes to encode
len
)

Convert a byte array to a hex encoded string and appends it to a specified string builder.

public static byte[]

Returns:

the byte array
convertHexToBytes
(String
the hex encoded string
s
)

Convert a hex encoded string to a byte array.

public static ByteArrayOutputStream

Returns:

the specified output stream or a new output stream
convertHexWithSpacesToBytes
(ByteArrayOutputStream
the output stream, or null
baos
,
String
the hex encoded string
s
,
int
the start index
start
,
int
the end index, exclusive
end
)

Parses a hex encoded string with possible space separators and appends the decoded binary string to the specified output stream.

public static String

Returns:

the decoded string
decodeUnicodeStringSQL
(String
the string to decode
s
,
int
the code point of UENCODE character, or '\\'
uencode
)

Decodes a Unicode SQL string.

public static String

Returns:

the escaped pattern
escapeMetaDataPattern
(String
the pattern
pattern
)

Escape table or schema patterns used for DatabaseMetaData functions.

private static String[]
private static DbException
private static DbException
getHexStringException(int code, String s, int start, int end)

public static StringBuilder

Returns:

the specified string builder
indent
(StringBuilder
string builder to append to
builder
,
String
the string
s
,
int
the number of spaces
spaces
,
boolean
append a newline if there is none
newline
)

Indents a string with spaces and appends it to a specified builder.

public static boolean

Returns:

true if it is null or empty
isNullOrEmpty
(String
the string to check
s
)

Check if a String is null or empty (the length is null).

public static boolean

Returns:

true if it is
isNumber
(String
the string
s
)

Check if this string is a decimal number.

public static boolean

Returns:

whether the specified string is empty or contains only whitespace
isWhitespaceOrEmpty
(String
the string
s
)

Check if the specified string is empty or contains only whitespace.

public static String

Returns:

the string
javaDecode
(String
the encoded string
s
)

Decode a text that is encoded as a Java string literal.

public static String

Returns:

the Java representation
javaEncode
(String
the text to convert
s
)

Convert a string to a Java literal using the correct escape sequences.

public static void
javaEncode(String
the text to convert
s
,
StringBuilder
the Java representation to return
buff
,
boolean
true if we embedding this inside a STRINGDECODE SQL command
forSQL
)

Convert a string to a Java literal using the correct escape sequences.

public static String

Returns:

the padded string
pad
(String
the original string
string
,
int
the target length
n
,
String
the padding string
padding
,
boolean
true if the padding should be appended at the end
right
)

Pad a string.

public static int

Returns:

the unsigned int not greater than Integer#MAX_VALUE.
parseUInt31
(String
string to parse
s
,
int
the beginning index, inclusive
start
,
int
the ending index, exclusive
end
)

Parses an unsigned 31-bit integer.

public static String

Returns:

the double quoted text
quoteIdentifier
(String
the text
s
)

Enclose a string with double quotes.

public static StringBuilder

Returns:

the specified builder
quoteIdentifier
(StringBuilder
string builder to append to
builder
,
String
the text
s
)

Enclose a string with double quotes and append it to the specified string builder.

private static StringBuilder
public static String

Returns:

the Java source code (including new int[]{})
quoteJavaIntArray
(int[]
the int array
array
)

Convert an int array to the Java source code that represents this array.

public static String

Returns:

the Java representation
quoteJavaString
(String
the text to convert
s
)

Convert a string to the Java literal and enclose it with double quotes.

public static String

Returns:

the Java source code (including new String[]{})
quoteJavaStringArray
(String[]
the string array
array
)

Convert a string array to the Java source code that represents this array.

public static String

Returns:

the SQL literal
quoteStringSQL
(String
the text to convert.
s
)

Convert a string to a SQL literal.

public static StringBuilder

Returns:

the specified string builder
quoteStringSQL
(StringBuilder
string builder to append result to
builder
,
String
the text to convert
s
)

Convert a string to a SQL character string literal.

public static String

Returns:

the string with the before string replaced
replaceAll
(String
the string
s
,
String
the old text
before
,
String
the new text
after
)

Replace all occurrences of the before string with the after string.

public static boolean

Returns:

TRUE only if text starts with the prefix
startsWith
(String
the full text starting with a prefix
text
,
String
the full text starting with a prefix
prefix
)

Case-sensitive check if a {@param text} starts with a {@param prefix}.

public static boolean

Returns:

TRUE only if text starts with the prefix
startsWithIgnoringCase
(String
the full text starting with a prefix
text
,
String
the full text starting with a prefix
prefix
)

Case-Insensitive check if a {@param text} starts with a {@param prefix}.

public static String

Returns:

the lowercase text
toLowerEnglish
(String
the text to convert
s
)

Convert a string to lowercase using the English locale.

public static String

Returns:

the uppercase text
toUpperEnglish
(String
the test to convert
s
)

Convert a string to uppercase using the English locale.

public static String

Returns:

the trimmed string
trim
(String
the string
s
,
boolean
if leading characters should be removed
leading
,
boolean
if trailing characters should be removed
trailing
,
String
what to remove or null for a space
characters
)

Trim a character from a string.

private static String
trim(String s, boolean leading, boolean trailing, IntPredicate test)

public static String

Returns:

the trimmed string
trim
(String
the string
s
,
boolean
if leading characters should be removed
leading
,
boolean
if trailing characters should be removed
trailing
,
char
what to remove
character
)

Trim a character from a string.

public static String

Returns:

trimmed substring
trimSubstring
(String
the string
s
,
int
start index of substring (inclusive)
beginIndex
)

Trim a whitespace from a substring.

public static String

Returns:

trimmed substring
trimSubstring
(String
the string
s
,
int
start index of substring (inclusive)
beginIndex
,
int
end index of substring (exclusive)
endIndex
)

Trim a whitespace from a substring.

public static StringBuilder

Returns:

the specified builder
trimSubstring
(StringBuilder
string builder to append to
builder
,
String
the string
s
,
int
start index of substring (inclusive)
beginIndex
,
int
end index of substring (exclusive)
endIndex
)

Trim a whitespace from a substring and append it to a specified string builder.

public static String

Returns:

the specified string if it isn't longer than the specified maximum length, and the truncated string otherwise
truncateString
(String
the string to truncate
s
,
int
the maximum length in characters
maximumLength
)

Truncates the specified string to the specified length.

public static String

Returns:

the decoded string
urlDecode
(String
the encoded URL
encoded
)

Decode the URL to a string.

public static String

Returns:

the encoded string
urlEncode
(String
the string to encode
s
)

Encode the string as a URL.

public static String

Returns:

the attribute
xmlAttr
(String
the attribute name
name
,
String
the attribute value
value
)

Creates an XML attribute of the form name="value".

public static String

Returns:

<![CDATA[data]]>
xmlCData
(String
the text data
data
)

Converts the data to a CDATA element.

public static String

Returns:

<!-- data -->
xmlComment
(String
the comment text
data
)

Escapes a comment.

public static String

Returns:

the node
xmlNode
(String
the element name
name
,
String
the attributes (may be null)
attributes
,
String
the content (may be null)
content
)

Create an XML node with optional attributes and content.

public static String

Returns:

the node
xmlNode
(String
the element name
name
,
String
the attributes (may be null)
attributes
,
String
the content (may be null)
content
,
boolean
whether to indent the content if it contains a newline
indent
)

Create an XML node with optional attributes and content.

public static String

Returns:

<?xml version="1.0"?>
xmlStartDoc
()

Returns <?xml version="1.0"?

public static String

Returns:

the escaped text
xmlText
(String
the text data
text
)

Escapes an XML text element.

public static String

Returns:

the escaped text
xmlText
(String
the text data
text
,
boolean
whether to escape newlines
escapeNewline
)

Escapes an XML text element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait