* Removes spaces (char <= 32) from end of this String, handling
* null
by returning null
.
*
* StringUtils.trimRight(null) = null * StringUtils.trimRight("") = "" * StringUtils.trimRight(" ") = "" * StringUtils.trimRight("abc") = "abc" * StringUtils.trimRight(" abc ") = " abc" ** * @param str the String to be trimmed, may be null * @param escapedSpace The last escaped space, if any * @return the trimmed string,
null
if null String input
*/
public static final String trimRight( String str, int escapedSpace )
{
if ( isEmpty( str ) )
{
return "";
}
int length = str.length();
int end = length;
while ( ( end > 0 ) && ( str.charAt( end - 1 ) == ' ' ) && ( end > escapedSpace ) )
{
if ( ( end > 1 ) && ( str.charAt( end - 2 ) == '\\' ) )
{
break;
}
end--;
}
return ( end == length ? str : str.substring( 0, end ) );
}
/**
* * Checks if a String is empty ("") or null. *
* ** StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false ** *
* NOTE: This method changed in Lang version 2.0. It no longer trims the * String. That functionality is available in isBlank(). *
* * @param str * the String to check, may be null * @returntrue
if the String is empty or null
*/
public static final boolean isEmpty( String str )
{
return str == null || str.length() == 0;
}
}