Class StringUtils
- Object
-
- org.thymeleaf.util.StringUtils
-
public final class StringUtils extends Object
Utility methods for String objects.
This class is used as a basis for the methods offered by
Strings
, which in turn are the methods offered by the#strings
utility object in variable expressions.- Since:
- 1.0
- Author:
- Daniel Fernández, Le Roux Bernard, Soraya Sánchez Labandeira
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
abbreviate(Object target, int maxSize)
static String
append(Object target, String suffix)
static String
capitalize(Object target)
Convert the first letter of target to uppercase (title-case, in fact).static String
capitalizeWords(Object target)
Convert all the first letter of the words of target to uppercase (title-case, in fact).static String
capitalizeWords(Object target, Object delimiters)
Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.static String
concat(Object... values)
static String
concatReplaceNulls(String nullValue, Object... values)
static Boolean
contains(Object target, String fragment)
static Boolean
containsIgnoreCase(Object target, String fragment, Locale locale)
static Boolean
endsWith(Object target, String suffix)
static Boolean
equals(Object first, Object second)
static Boolean
equalsIgnoreCase(Object first, Object second)
static String
escapeJava(Object target)
Escapes the specified target text as required for Java code.static String
escapeJavaScript(Object target)
Escapes the specified target text as required for JavaScript code.static String
escapeXml(Object target)
XML-escapes the specified text.static Integer
indexOf(Object target, String fragment)
static boolean
isEmpty(String target)
static boolean
isEmptyOrWhitespace(String target)
static String
join(Iterable<?> target, char separator)
static String
join(Iterable<?> target, String separator)
static String
join(Object[] target, String separator)
static Integer
length(Object target)
static String
pack(String target)
Removes all whitespaces and control chars at all positions, and transforms to lower case.static String
prepend(Object target, String prefix)
static String
randomAlphanumeric(int count)
static String
repeat(Object target, int times)
static String
replace(Object target, String before, String after)
static String[]
split(Object target, String separator)
static Boolean
startsWith(Object target, String prefix)
static String
substring(Object target, int beginIndex)
copy a part of target start beginIndex to the end of target.static String
substring(Object target, int beginIndex, int endIndex)
static String
substringAfter(Object target, String substr)
static String
substringBefore(Object target, String substr)
static String
toLowerCase(Object target, Locale locale)
static String
toString(Object target)
Performs a null-safetoString()
operation.static String
toUpperCase(Object target, Locale locale)
static String
trim(Object target)
static String
unCapitalize(Object target)
Convert the first letter of target to lowercase.static String
unescapeJava(Object target)
Un-escapes the specified Java-escaped target text back to normal form.static String
unescapeJavaScript(Object target)
Un-escapes the specified JavaScript-escaped target text back to normal form.
-
-
-
Method Detail
-
toString
public static String toString(Object target)
Performs a null-safe
toString()
operation.- Parameters:
target
- the object on which toString will be executed- Returns:
- the result of calling
target.toString()
if target is not null,null
if target is null. - Since:
- 2.0.12
-
equals
public static Boolean equals(Object first, Object second)
- Parameters:
first
- firstsecond
- second- Returns:
- the result
- Since:
- 2.0.16
-
equalsIgnoreCase
public static Boolean equalsIgnoreCase(Object first, Object second)
- Parameters:
first
- firstsecond
- second- Returns:
- the result
- Since:
- 2.0.16
-
containsIgnoreCase
public static Boolean containsIgnoreCase(Object target, String fragment, Locale locale)
-
substring
public static String substring(Object target, int beginIndex)
copy a part of target start beginIndex to the end of target. If non-String object, toString() will be called.
- Parameters:
target
- source of the copy.beginIndex
- index where the copy start.- Returns:
- part of target, or
null
if target is null. - Since:
- 1.1.2
-
repeat
public static String repeat(Object target, int times)
- Parameters:
target
- targettimes
- times- Returns:
- the result
- Since:
- 2.1.0
-
concat
public static String concat(Object... values)
- Parameters:
values
- values- Returns:
- the result
- Since:
- 2.0.16
-
concatReplaceNulls
public static String concatReplaceNulls(String nullValue, Object... values)
- Parameters:
nullValue
- nullValuevalues
- values- Returns:
- the result
- Since:
- 2.0.16
-
isEmpty
public static boolean isEmpty(String target)
- Parameters:
target
- target- Returns:
- the result
- Since:
- 2.1.0
-
isEmptyOrWhitespace
public static boolean isEmptyOrWhitespace(String target)
-
pack
public static String pack(String target)
Removes all whitespaces and control chars at all positions, and transforms to lower case.- Parameters:
target
- the string to be packed- Returns:
- the packed string
- Since:
- 3.0.12
-
capitalize
public static String capitalize(Object target)
Convert the first letter of target to uppercase (title-case, in fact).
- Parameters:
target
- the String to be capitalized. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
unCapitalize
public static String unCapitalize(Object target)
Convert the first letter of target to lowercase.
- Parameters:
target
- the String to be uncapitalized. If non-String object, toString() will be called.- Returns:
- String the result of uncapitalizing the target.
- Since:
- 1.1.2
-
capitalizeWords
public static String capitalizeWords(Object target)
Convert all the first letter of the words of target to uppercase (title-case, in fact). The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java doc).
- Parameters:
target
- the String to be capitalized. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
capitalizeWords
public static String capitalizeWords(Object target, Object delimiters)
Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.
- Parameters:
target
- the String to be capitalized. If non-String object, toString() will be called.delimiters
- delimiters of the words. If non-String object, toString() will be called.- Returns:
- String the result of capitalizing the target.
- Since:
- 1.1.2
-
escapeXml
public static String escapeXml(Object target)
XML-escapes the specified text.
- Parameters:
target
- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.9
-
escapeJavaScript
public static String escapeJavaScript(Object target)
Escapes the specified target text as required for JavaScript code.
- Parameters:
target
- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
escapeJava
public static String escapeJava(Object target)
Escapes the specified target text as required for Java code.
- Parameters:
target
- the text to be escaped- Returns:
- the escaped text.
- Since:
- 2.0.11
-
unescapeJavaScript
public static String unescapeJavaScript(Object target)
Un-escapes the specified JavaScript-escaped target text back to normal form.
- Parameters:
target
- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
unescapeJava
public static String unescapeJava(Object target)
Un-escapes the specified Java-escaped target text back to normal form.
- Parameters:
target
- the text to be unescaped- Returns:
- the unescaped text.
- Since:
- 2.0.11
-
randomAlphanumeric
public static String randomAlphanumeric(int count)
-
-