Package liquibase.util
Class StringUtil
java.lang.Object
liquibase.util.StringUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
Deprecated.static boolean
Deprecated.useStringUtils.endsWith(CharSequence, CharSequence)
insteadstatic 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 spacesstatic boolean
equalsWordNull
(String value) Check whether the value is 'null' (case insensitive)static String
escapeHtml
(String str) static byte[]
getBytesWithEncoding
(String string) static String
getLastBlockComment
(String sqlString) Retrieves the last block comment in a SQL string, if any.static String
getLastLineComment
(String sqlString) Returns the last line comment from a given SQL string, if there is one.static boolean
hasLowerCase
(String string) static boolean
hasUpperCase
(String string) static String
static String
static boolean
isAscii
(char ch) Deprecated.useCharUtils.isAscii(char)
insteadstatic boolean
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
(CharSequence cs) Deprecated.useStringUtils.isEmpty(CharSequence)
static boolean
Deprecated.useStringUtils.isEmpty(CharSequence)
insteadstatic 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) Deprecated.useStringUtils.isNotEmpty(CharSequence)
insteadstatic boolean
Deprecated.useStringUtils.isNumeric(CharSequence)
insteadstatic boolean
isWhitespace
(CharSequence string) Returns true if the given string only consists of whitespace characters (null-safe)static String
Deprecated.useStringUtils.join(int[], char)
insteadstatic String
Deprecated.useStringUtils.join(Object[], String)
insteadstatic String
join
(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter) static String
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
static String
join
(Map map, String delimiter, StringUtil.StringUtilFormatter formatter) static String
join
(ExtensibleObject extensibleObject, String delimiter) static String
join
(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter) static String
Adds spaces to the left of the input value until the string has reached the given length.static String
static String
lowerCaseFirst
(String string) Deprecated.useStringUtils.uncapitalize(String)
insteadstatic String
Adds spaces to the right of the input value until the string has reached the given length.static String[]
processMultiLineSQL
(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.static String[]
processMultiLineSQL
(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.static String[]
processMutliLineSQL
(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)
(String)}static String[]
processMutliLineSQL
(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)
(String)}static String
randomIdentifer
(int len) Deprecated.static String
randomIdentifier
(int len) Produce a random identifier of the given length, consisting only of uppercase letters.static String
Deprecated.useStringUtils.repeat(String, int)
insteadsplitAndTrim
(String s, String regex) static String[]
splitCamelCase
(String str) Deprecated.useStringUtils.splitByCharacterTypeCamelCase(String)
insteadstatic String[]
Splits a candidate multi-line SQL statement along ;'s and "go"'s.static String[]
Splits a candidate multi-line SQL statement along ;'s and "go"'s.splitToChunks
(String input, int chunkSize) Split the input string into chunks no larger than the supplied chunkSize.static String
standardizeLineEndings
(String string) static boolean
startsWith
(String value, String startsWith) Deprecated.useStringUtils.startsWith(CharSequence, CharSequence)
insteadstatic 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\n (to support the ANSI standard commenting of -- at the end of a line). static String
stripComments
(String multiLineSQL, ChangeSet changeSet) Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). static String
stripEnclosingQuotes
(String string) static String
stripSqlCommentsAndWhitespacesFromTheEnd
(String sqlString) Strips the comments and white spaces from the end of given SQL string.static String
toCamelCase
(String string) Converts a kabob-case or underscore_case string to a camel-case onestatic String
toKabobCase
(String string) Converts a camelCase string to a kabob-case onestatic String
toLowerWithoutWhitespaces
(String value) Deprecated.useStringUtils.toRootLowerCase(String)
andStringUtils.deleteWhitespace(String)
insteadstatic String
Trimswhitespace
characters from the end of specifiedstring
static String
trimToEmpty
(String string) Deprecated.useStringUtils.trimToEmpty(String)
insteadstatic String
trimToNull
(String string) Deprecated.useStringUtils.trimToNull(String)
insteadstatic String
upperCaseFirst
(String string) Deprecated.useStringUtils.capitalize(String)
insteadstatic String
Deprecated.Liquibase does not wrap any console output, and instead lets the terminal handle its own wrapping.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
trimToEmpty
Deprecated.useStringUtils.trimToEmpty(String)
insteadReturns the trimmed (left and right) version of the input string. If null is passed, an empty string is returned.- Parameters:
string
- the input string to trim- Returns:
- the trimmed string, or an empty string if the input was null.
-
trimToNull
Deprecated.useStringUtils.trimToNull(String)
insteadReturns the trimmed (left and right) form of the input string. If the string is empty after trimming (or null was passed in the first place), null is returned, i.e. the input string is reduced to nothing.- Parameters:
string
- the string to trim- Returns:
- the trimmed string or null
-
processMultiLineSQL
public static String[] processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.- Parameters:
multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the code
-
processMultiLineSQL
public static String[] processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.- Parameters:
multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the codechangeSet
- the changeset associated with the sql being parsed
-
processMutliLineSQL
@Deprecated public static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)
(String)}Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.- Parameters:
multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the code
-
processMutliLineSQL
@Deprecated public static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)
(String)}Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)
and then extracts each individual statement usingsplitSQL(String, String, ChangeSet)
.- Parameters:
multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the codechangeSet
- the changeset associated with the sql being parsed
-
isDelimiter
Returns true if the input is a delimiter in one of the popular RDBMSs. Recognized delimiters are: semicolon (;), a slash (as the only content) or the word GO (as the only content).- Parameters:
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)
-
wrap
Deprecated.Liquibase does not wrap any console output, and instead lets the terminal handle its own wrapping. If you wish to use this method, consider whether its usage is truly necessary.Add new lines to the input string to cause output to wrap. Optional line padding can be passed in for the additional lines that are created- Parameters:
inputStr
- The string to split and wrapwrapPoint
- The point at which to split the linesextraLinePadding
- Any additional spaces to add- Returns:
- String Output string with new lines
-
splitSQL
Splits a candidate multi-line SQL statement along ;'s and "go"'s. -
splitSQL
Splits a candidate multi-line SQL statement along ;'s and "go"'s.- Parameters:
changeSet
- the changeset associated with the sql being parsed
-
stripComments
Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). - Returns:
- The String without the comments in
-
stripComments
Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). - Parameters:
changeSet
- the changeset associated with the sql being parsed- Returns:
- The String without the comments in
-
join
public static String join(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter) -
join
-
join
-
join
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter) -
join
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter, boolean sorted) -
join
-
join
-
join
-
join
-
join
public static String join(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter) -
splitAndTrim
-
repeat
Deprecated.useStringUtils.repeat(String, int)
instead -
join
Deprecated.useStringUtils.join(Object[], String)
instead -
join
Deprecated.useStringUtils.join(int[], char)
instead -
indent
-
indent
-
lowerCaseFirst
Deprecated.useStringUtils.uncapitalize(String)
instead -
upperCaseFirst
Deprecated.useStringUtils.capitalize(String)
instead -
hasUpperCase
-
hasLowerCase
-
standardizeLineEndings
-
isAscii
-
isAscii
Deprecated.useCharUtils.isAscii(char)
insteadReturns true if ch is a "7-bit-clean" ASCII character (ordinal number < 128).- Parameters:
ch
- the character to test- Returns:
- true if 7 bit-clean, false otherwise.
-
escapeHtml
-
pad
Adds spaces to the right of the input value until the string has reached the given length. Nothing is done if the string already has the given length or if the string is even longer.- Parameters:
value
- The string to pad (if necessary)length
- the desired length- Returns:
- the input string, padded if necessary.
-
leftPad
Adds spaces to the left of the input value until the string has reached the given length. Nothing is done if the string already has the given length or if the string is even longer.- Parameters:
value
- The string to pad (if necessary)length
- the desired length- Returns:
- the input string, padded if necessary.
-
contains
Deprecated.useStringUtils.contains(CharSequence, CharSequence)
insteadReturns true if the input string contains the specified value- Parameters:
value
- String to be checkedcontainsValue
- String to look for- Returns:
- true if String contains the value
-
isEmpty
Deprecated.useStringUtils.isEmpty(CharSequence)
insteadReturns true if the input string is the empty string (null-safe).- Parameters:
value
- String to be checked- Returns:
- true if String is null or empty
-
isNotEmpty
Deprecated.useStringUtils.isNotEmpty(CharSequence)
insteadReturns true if the input string is NOT the empty string. If the string is null, false is returned.- Parameters:
value
- String to be checked- Returns:
- true if string is not null and not empty (length > 0)
-
startsWith
Deprecated.useStringUtils.startsWith(CharSequence, CharSequence)
insteadChecks whether the givenvalue
starts with the specifiedstartsWith
string.- Parameters:
value
- the string to checkstartsWith
- the prefix to check for- Returns:
true
ifvalue
starts withstartsWith
,false
otherwise. Returnsfalse
if either argument isnull
.
-
endsWith
Deprecated.useStringUtils.endsWith(CharSequence, CharSequence)
insteadChecks whether the givenvalue
ends with the specifiedendsWith
string.- Parameters:
value
- the string to checkendsWith
- the prefix to check for- Returns:
true
ifvalue
ends withendsWith
,false
otherwise. Returnsfalse
if either argument isnull
.
-
isWhitespace
Returns true if the given string only consists of whitespace characters (null-safe)- Parameters:
string
- the string to test- Returns:
- true if the string is null or only consists of whitespaces.
-
isMinimumVersion
public 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.- Parameters:
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 part- Returns:
- true if candidateMajor.candidateMinor.candidatePatch >= minimumVersion or false if not
-
limitSize
-
randomIdentifer
Deprecated.Produce a random identifier of the given length, consisting only of uppercase letters.- Parameters:
len
- desired length of the string- Returns:
- an identifier of the desired length
-
randomIdentifier
Produce a random identifier of the given length, consisting only of uppercase letters.- Parameters:
len
- desired length of the string- Returns:
- an identifier of the desired length
-
toKabobCase
Converts a camelCase string to a kabob-case one -
toCamelCase
Converts a kabob-case or underscore_case string to a camel-case one -
equalsIgnoreCaseAndEmpty
Returns if two strings are equal, ignoring:- case (uppercase/lowercase)
- difference between null, and empty string, and a string that only has spaces
- Parameters:
s1
- the first String to compare (or null)s2
- the second String to compare (or null)- Returns:
- true if the Strings are equal by the above criteria, false in all other cases
-
trimRight
Trimswhitespace
characters from the end of specifiedstring
- Parameters:
string
- String to trim- Returns:
- new String without the whitespace at the end
-
getLastBlockComment
Retrieves the last block comment in a SQL string, if any.- Parameters:
sqlString
- the SQL string to search for the last block comment- Returns:
- the last block comment in the SQL string, or
null
if none was found
-
getLastLineComment
Returns the last line comment from a given SQL string, if there is one.- Parameters:
sqlString
- the SQL string to search- Returns:
- the last line comment from the SQL string, or
null
if there is no line comment
-
stripSqlCommentsAndWhitespacesFromTheEnd
Strips the comments and white spaces from the end of given SQL string.- Parameters:
sqlString
- the SQL string to strip- Returns:
- the stripped SQL string
-
concatConsistentCase
Concatenates the addition string to the baseString string, adjusting the case of "addition" to match the base string. If the string is all caps, append addition in all caps. If all lower case, append in all lower case. If baseString is mixed case, make no changes to addition. -
stripEnclosingQuotes
-
equalsWordNull
Check whether the value is 'null' (case insensitive) -
splitCamelCase
Deprecated.useStringUtils.splitByCharacterTypeCamelCase(String)
insteadSplits a camel-case string into words based on the came casing.
- Parameters:
str
- the String to split, may benull
- Returns:
- an array of parsed Strings,
null
if null String input
-
getBytesWithEncoding
-
toLowerWithoutWhitespaces
Deprecated.useStringUtils.toRootLowerCase(String)
andStringUtils.deleteWhitespace(String)
instead- Parameters:
value
- string to process- Returns:
- string without any whitespaces formatted to lowercase.
-
isNumeric
Deprecated.useStringUtils.isNumeric(CharSequence)
insteadChecks whether the char sequence is numeric by checking that all chars in the sequence are numbers, so (-1, 1.0 and 1F) will return false
- Parameters:
cs
- the arg to check if it is numeric- Returns:
- true if convertible to numeric and false otherwise
-
isEmpty
Deprecated.useStringUtils.isEmpty(CharSequence)
-
splitToChunks
Split the input string into chunks no larger than the supplied chunkSize. If the string is shorter than the chunkSize, the resultant list will contain only a single entry.
-
StringUtils.contains(CharSequence, CharSequence)
instead