public class StringUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.DefaultFormatter |
static interface |
StringUtil.StringUtilFormatter<Type> |
static class |
StringUtil.ToStringFormatter |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
concatConsistentCase(String baseString,
String addition)
Concatenates the addition string to the baseString string, adjusting the case of "addition" to match the base string.
|
static boolean |
equalsIgnoreCaseAndEmpty(String s1,
String s2)
Returns if two strings are equal, ignoring:
case (uppercase/lowercase)
difference between null, and empty string, and a string that only has spaces
|
static String |
escapeHtml(String str) |
static String |
escapeXml(CharSequence s) |
static String |
getLastBlockComment(String sqlString) |
static String |
getLastLineComment(String sqlString) |
static boolean |
hasLowerCase(String string) |
static boolean |
hasUpperCase(String string) |
static String |
indent(String string) |
static String |
indent(String string,
int padding) |
static boolean |
isAscii(char ch)
Returns true if ch is a "7-bit-clean" ASCII character (ordinal number < 128).
|
static boolean |
isAscii(String string) |
protected static boolean |
isDelimiter(String piece,
String previousPiece,
String endDelimiter)
Returns true if the input is a delimiter in one of the popular RDBMSs.
|
static boolean |
isEmpty(String value)
Returns true if the input string is the empty string (null-safe).
|
static boolean |
isMinimumVersion(String minimumVersion,
int candidateMajor,
int candidateMinor,
int candidatePatch)
Compares a minimum version number given in string form (only the first three parts are considered) with a
candidate version given as the three ints major, minor and patch.
|
static boolean |
isNotEmpty(String value)
Returns true if the input string is NOT the empty string.
|
static boolean |
isWhitespace(CharSequence string)
Returns true if the given string only consists of whitespace characters (null-safe)
|
static String |
join(Collection<String> collection,
String delimiter) |
static String |
join(Collection<String> collection,
String delimiter,
boolean sorted) |
static String |
join(Collection collection,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(Collection collection,
String delimiter,
StringUtil.StringUtilFormatter formatter,
boolean sorted) |
static String |
join(ExtensibleObject extensibleObject,
String delimiter) |
static String |
join(ExtensibleObject extensibleObject,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(int[] array,
String delimiter) |
static String |
join(Integer[] array,
String delimiter) |
static String |
join(Map map,
String delimiter) |
static String |
join(Map map,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(Object[] array,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(String[] array,
String delimiter) |
static String |
leftPad(String value,
int length)
Adds spaces to the left of the input value until the string has reached the given length.
|
static String |
limitSize(String string,
int maxLength) |
static String |
lowerCaseFirst(String string) |
static String |
pad(String value,
int length)
Adds spaces to the right of the input value until the string has reached the given length.
|
static String[] |
processMutliLineSQL(String multiLineSQL,
boolean stripComments,
boolean splitStatements,
String endDelimiter)
Removes any comments from multiple line SQL using
stripComments(String)
and then extracts each individual statement using splitSQL(String, String) . |
static String |
randomIdentifer(int len)
Produce a random identifer of the given length, consisting only of uppercase letters.
|
static String |
repeat(String string,
int times) |
static List<String> |
splitAndTrim(String s,
String regex) |
static String[] |
splitSQL(String multiLineSQL,
String endDelimiter)
Splits a candidate multi-line SQL statement along ;'s and "go"'s.
|
static String |
standardizeLineEndings(String string) |
static boolean |
startsWith(String value,
String startsWith)
Checks if
value starts with startsWith . |
static String |
stripComments(String multiLineSQL)
Searches through a String which contains SQL code and strips out
any comments that are between \/**\/ or anything that matches
SP--SP
|
static String |
stripSqlCommentsAndWhitespacesFromTheEnd(String sqlString)
Strips the comments and whitespaces from the end of given sql string.
|
static String |
substring(String str,
int start,
int end)
From commonslang3 -> StringUtil
|
static String |
trimRight(String string)
Trims
whitespace characters from the
end of specified string |
static String |
trimToEmpty(String string)
Returns the trimmed (left and right) version of the input string.
|
static String |
trimToNull(String string)
Returns the trimmed (left and right) form of the input string.
|
static String |
upperCaseFirst(String string) |
public static String trimToEmpty(String string)
string
- the input string to trimpublic static String trimToNull(String string)
string
- the string to trimpublic static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter)
stripComments(String)
and then extracts each individual statement using splitSQL(String, String)
.multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the codeprotected static boolean isDelimiter(String piece, String previousPiece, String endDelimiter)
piece
- the input line to testpreviousPiece
- the characters in the input stream that came before pieceendDelimiter
- ??? (need to see this in a debugger to find out)public static String[] splitSQL(String multiLineSQL, String endDelimiter)
public static String stripComments(String multiLineSQL)
public static String join(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(Collection<String> collection, String delimiter)
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter, boolean sorted)
public static String join(Collection<String> collection, String delimiter, boolean sorted)
public static String join(Map map, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(ExtensibleObject extensibleObject, String delimiter)
public static String join(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter)
public static boolean hasUpperCase(String string)
public static boolean hasLowerCase(String string)
public static boolean isAscii(String string)
public static boolean isAscii(char ch)
ch
- the character to testpublic static String pad(String value, int length)
value
- The string to pad (if necessary)length
- the desired lengthpublic static String leftPad(String value, int length)
value
- The string to pad (if necessary)length
- the desired lengthpublic static boolean isEmpty(String value)
value
- String to be checkedpublic static boolean isNotEmpty(String value)
value
- String to be checkedpublic static boolean startsWith(String value, String startsWith)
value
starts with startsWith
.value
- startsWith
- value
starts with startsWith
, otherwise false. If any of arguments is null returns falsepublic static boolean isWhitespace(CharSequence string)
string
- the string to testpublic static boolean isMinimumVersion(String minimumVersion, int candidateMajor, int candidateMinor, int candidatePatch)
minimumVersion
- The minimum version that is required, given as a string with up to 3 parts, e.g. "7.4" or "9.6.3"candidateMajor
- the version number to be tested, major partcandidateMinor
- the version number to be tested, minor partcandidatePatch
- the version number to be tested, patch partpublic static String randomIdentifer(int len)
len
- desired length of the stringpublic static boolean equalsIgnoreCaseAndEmpty(String s1, String s2)
s1
- the first String to compare (or null)s2
- the second String to compare (or null)public static String trimRight(String string)
whitespace
characters from the
end of specified string
string
- String to trimpublic static String getLastBlockComment(String sqlString)
sqlString
- public static String getLastLineComment(String sqlString)
sqlString
- public static String stripSqlCommentsAndWhitespacesFromTheEnd(String sqlString)
sqlString
- public static String substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n
characters from the end of the String.
The returned substring starts with the character in the start
position and ends before the end
position. All position counting is
zero-based -- i.e., to start at the beginning of the string use
start = 0
. Negative start and end positions can be used to
specify offsets relative to the end of the String.
If start
is not strictly to the left of end
, ""
is returned.
StringUtil.substring(null, *, *) = null StringUtil.substring("", * , *) = ""; StringUtil.substring("abc", 0, 2) = "ab" StringUtil.substring("abc", 2, 0) = "" StringUtil.substring("abc", 2, 4) = "c" StringUtil.substring("abc", 4, 6) = "" StringUtil.substring("abc", 2, 2) = "" StringUtil.substring("abc", -2, -1) = "b" StringUtil.substring("abc", -4, 2) = "ab"
str
- the String to get the substring from, may be nullstart
- the position to start from, negative means
count back from the end of the String by this many charactersend
- the position to end at (exclusive), negative means
count back from the end of the String by this many charactersnull
if null String inputpublic static String escapeXml(CharSequence s)
public static String concatConsistentCase(String baseString, String addition)
Copyright © 2021 Liquibase.org. All rights reserved.