8200436: String::isBlank

Reviewed-by: sundar
This commit is contained in:
Jim Laskey 2018-05-18 08:43:49 -03:00
parent 003b10c2bc
commit a455811dca
2 changed files with 99 additions and 0 deletions

View file

@ -2728,6 +2728,31 @@ public final class String
return ret == null ? this : ret;
}
/**
* Returns {@code true} if the string is empty or contains only
* {@link Character#isWhitespace(int) white space} codepoints,
* otherwise {@code false}.
*
* @return {@code true} if the string is empty or contains only
* {@link Character#isWhitespace(int) white space} codepoints,
* otherwise {@code false}
*
* @see Character#isWhitespace(int)
*
* @since 11
*/
public boolean isBlank() {
return indexOfNonWhitespace() == length();
}
private int indexOfNonWhitespace() {
if (isLatin1()) {
return StringLatin1.indexOfNonWhitespace(value);
} else {
return StringUTF16.indexOfNonWhitespace(value);
}
}
/**
* This object (which is already a string!) is itself returned.
*