@groovy.transform.CompileStatic abstract class GrailsStringUtils extends StringUtils
Extra methods for string manipulation
Constructor and description |
---|
GrailsStringUtils() |
Type Params | Return Type | Name and description |
---|---|---|
|
static java.lang.String |
getFileBasename(java.lang.String path) Obtains the base name of a file excluding path and extension |
|
static boolean |
isBlank(java.lang.String str) Same as StringUtils#isEmpty(java.lang.Object) but trims the string for surrounding whitespace |
|
static boolean |
isNotBlank(java.lang.String str) Opposite of GrailsStringUtils.isBlank |
|
static boolean |
isNotEmpty(java.lang.String str) Opposite of GrailsStringUtils.isEmpty |
|
static java.lang.String |
substringAfter(java.lang.String str, java.lang.String token) Returns a substring after the given token |
|
static java.lang.String |
substringAfterLast(java.lang.String str, java.lang.String token) Returns a substring after the last occurrence of the given token |
|
static java.lang.String |
substringBefore(java.lang.String str, java.lang.String token) Returns a substring before the given token |
|
static java.lang.String |
substringBeforeLast(java.lang.String str, java.lang.String token) Returns a substring before the last occurance of the given token |
|
static boolean |
toBoolean(java.lang.String str) Converts a string to a boolean. |
|
static java.lang.String |
trimStart(java.lang.String str, java.lang.String start) Trims the start of the string |
|
static java.lang.String |
trimToNull(java.lang.String str) Removes all space from both ends of this String returning null if the String is empty ("") after the trim
or if it is null . |
Obtains the base name of a file excluding path and extension
path
- The pathSame as StringUtils#isEmpty(java.lang.Object) but trims the string for surrounding whitespace
Opposite of GrailsStringUtils.isBlank
Opposite of GrailsStringUtils.isEmpty
Returns a substring after the given token GrailsStringUtils.substringAfter(null, *) = null GrailsStringUtils.substringAfter("", *) = "" GrailsStringUtils.substringAfter(*, null) = "" GrailsStringUtils.substringAfter("abc", "a") = "bc" GrailsStringUtils.substringAfter("abcba", "b") = "cba" GrailsStringUtils.substringAfter("abc", "c") = "" GrailsStringUtils.substringAfter("abc", "d") = "" GrailsStringUtils.substringAfter("abc", "") = "abc"
str
- The string to apply the substringtoken
- The token to matchReturns a substring after the last occurrence of the given token GrailsStringUtils.substringAfter(null, *) = null GrailsStringUtils.substringAfter("", *) = "" GrailsStringUtils.substringAfter(*, null) = "" GrailsStringUtils.substringAfter("abc", "a") = "bc" GrailsStringUtils.substringAfter("abcba", "b") = "cba" GrailsStringUtils.substringAfter("abc", "c") = "" GrailsStringUtils.substringAfter("abc", "d") = "" GrailsStringUtils.substringAfter("abc", "") = "abc"
str
- The string to apply the substringtoken
- The token to matchReturns a substring before the given token GrailsStringUtils.substringBefore(null, *) = null GrailsStringUtils.substringBefore("", *) = "" GrailsStringUtils.substringBefore("abc", "a") = "" GrailsStringUtils.substringBefore("abcba", "b") = "a" GrailsStringUtils.substringBefore("abc", "c") = "ab" GrailsStringUtils.substringBefore("abc", "d") = "abc" GrailsStringUtils.substringBefore("abc", "") = "" GrailsStringUtils.substringBefore("abc", null) = "abc"
str
- The string to apply the substringtoken
- The token to matchReturns a substring before the last occurance of the given token GrailsStringUtils.substringBefore(null, *) = null GrailsStringUtils.substringBefore("", *) = "" GrailsStringUtils.substringBefore("abc", "a") = "" GrailsStringUtils.substringBefore("abcba", "b") = "a" GrailsStringUtils.substringBefore("abc", "c") = "ab" GrailsStringUtils.substringBefore("abc", "d") = "abc" GrailsStringUtils.substringBefore("abc", "") = "" GrailsStringUtils.substringBefore("abc", null) = "abc"
str
- The string to apply the substringtoken
- The token to matchConverts a string to a boolean. The values 'true', 'on', 'yes' and '1' result in true being returned, otherwise false is returned
str
- The stringTrims the start of the string
str
- The string to trimstart
- The start to trim Removes all space from both ends of this String returning
null
if the String is empty ("") after the trim
or if it is null
.
The String is trimmed using java.lang.String#trim().
GrailsStringUtils.trimToNull(null) = null GrailsStringUtils.trimToNull("") = null GrailsStringUtils.trimToNull(" ") = null GrailsStringUtils.trimToNull("xyz") = "xyz" GrailsStringUtils.trimToNull(" xyz ") = "xyz"based on https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java#L8838
str
- the String to be trimmed, may be nullnull
if only containing space, empty or null String input