Merge "Avoid NPE in trimToLengthWithEllipsis()."
This commit is contained in:
committed by
Android (Google) Code Review
commit
389a1de0ac
@@ -2173,7 +2173,7 @@ public class TextUtils {
|
||||
public static <T extends CharSequence> T trimToLengthWithEllipsis(@Nullable T text,
|
||||
@IntRange(from = 1) int size) {
|
||||
T trimmed = trimToSize(text, size);
|
||||
if (trimmed.length() < text.length()) {
|
||||
if (text != null && trimmed.length() < text.length()) {
|
||||
trimmed = (T) (trimmed.toString() + "...");
|
||||
}
|
||||
return trimmed;
|
||||
|
||||
@@ -792,5 +792,6 @@ public class TextUtilsTest {
|
||||
assertEquals("ABC...", TextUtils.trimToLengthWithEllipsis("ABCDEF", 3));
|
||||
assertEquals("ABC", TextUtils.trimToLengthWithEllipsis("ABC", 3));
|
||||
assertEquals("", TextUtils.trimToLengthWithEllipsis("", 3));
|
||||
assertNull(TextUtils.trimToLengthWithEllipsis(null, 3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user