summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@google.com> 2023-11-15 15:13:33 -0700
committer Jeff Sharkey <jsharkey@google.com> 2023-11-16 09:26:58 -0700
commitcb4a047ed5d0ce8cc9dbb2cdabc30940a630093d (patch)
tree850124990e7834dc8fa5be8dc69545bbaad42a39
parent41cfbb3f010ca14bc952615e9b79a91bd0ddf921 (diff)
Support TextUtils for Ravenwood, with CTS.
A handful of TextUtils utility methods are fully supportable on a typical host JVM, so this change marks them as being available. It also brings along the relevant CTS to ensure consistency with how a real device behaves. Bug: 292141694 Test: atest-dev CtsTextTestCasesRavenwood CtsTextTestCases Change-Id: I460719c67ac4bde9e8baee0ac72d3062401d7d67
-rw-r--r--core/java/android/text/TextUtils.java55
-rw-r--r--ravenwood/framework-minus-apex-ravenwood-policies.txt4
-rw-r--r--ravenwood/ravenwood-annotation-allowed-classes.txt3
3 files changed, 53 insertions, 9 deletions
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index c0a5629f9220..6ea462eb969f 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -68,6 +68,7 @@ import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.text.style.UpdateAppearance;
+import android.util.EmptyArray;
import android.util.Log;
import android.util.Printer;
import android.view.View;
@@ -141,9 +142,9 @@ public class TextUtils {
return (method == TextUtils.TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL;
}
-
private TextUtils() { /* cannot be instantiated */ }
+ @android.ravenwood.annotation.RavenwoodKeep
public static void getChars(CharSequence s, int start, int end,
char[] dest, int destoff) {
Class<? extends CharSequence> c = s.getClass();
@@ -162,10 +163,12 @@ public class TextUtils {
}
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, char ch) {
return indexOf(s, ch, 0);
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, char ch, int start) {
Class<? extends CharSequence> c = s.getClass();
@@ -175,6 +178,7 @@ public class TextUtils {
return indexOf(s, ch, start, s.length());
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, char ch, int start, int end) {
Class<? extends CharSequence> c = s.getClass();
@@ -212,10 +216,12 @@ public class TextUtils {
return -1;
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int lastIndexOf(CharSequence s, char ch) {
return lastIndexOf(s, ch, s.length() - 1);
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int lastIndexOf(CharSequence s, char ch, int last) {
Class<? extends CharSequence> c = s.getClass();
@@ -225,6 +231,7 @@ public class TextUtils {
return lastIndexOf(s, ch, 0, last);
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int lastIndexOf(CharSequence s, char ch,
int start, int last) {
if (last < 0)
@@ -270,14 +277,17 @@ public class TextUtils {
return -1;
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, CharSequence needle) {
return indexOf(s, needle, 0, s.length());
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, CharSequence needle, int start) {
return indexOf(s, needle, start, s.length());
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static int indexOf(CharSequence s, CharSequence needle,
int start, int end) {
int nlen = needle.length();
@@ -305,6 +315,7 @@ public class TextUtils {
return -1;
}
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean regionMatches(CharSequence one, int toffset,
CharSequence two, int ooffset,
int len) {
@@ -337,6 +348,7 @@ public class TextUtils {
* in that it does not preserve any style runs in the source sequence,
* allowing a more efficient implementation.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String substring(CharSequence source, int start, int end) {
if (source instanceof String)
return ((String) source).substring(start, end);
@@ -409,6 +421,7 @@ public class TextUtils {
* calling object.toString(). If tokens is null, a NullPointerException will be thrown. If
* tokens is an empty array, an empty string will be returned.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String join(@NonNull CharSequence delimiter, @NonNull Object[] tokens) {
final int length = tokens.length;
if (length == 0) {
@@ -432,6 +445,7 @@ public class TextUtils {
* calling object.toString(). If tokens is null, a NullPointerException will be thrown. If
* tokens is empty, an empty string will be returned.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens) {
final Iterator<?> it = tokens.iterator();
if (!it.hasNext()) {
@@ -464,9 +478,10 @@ public class TextUtils {
*
* @throws NullPointerException if expression or text is null
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String[] split(String text, String expression) {
if (text.length() == 0) {
- return EMPTY_STRING_ARRAY;
+ return EmptyArray.STRING;
} else {
return text.split(expression, -1);
}
@@ -489,9 +504,10 @@ public class TextUtils {
*
* @throws NullPointerException if expression or text is null
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String[] split(String text, Pattern pattern) {
if (text.length() == 0) {
- return EMPTY_STRING_ARRAY;
+ return EmptyArray.STRING;
} else {
return pattern.split(text, -1);
}
@@ -526,6 +542,7 @@ public class TextUtils {
* be returned for the empty string after that delimeter. That is, splitting <tt>"a,b,"</tt> on
* comma will return <tt>"a", "b"</tt>, not <tt>"a", "b", ""</tt>.
*/
+ @android.ravenwood.annotation.RavenwoodKeepWholeClass
public static class SimpleStringSplitter implements StringSplitter, Iterator<String> {
private String mString;
private char mDelimiter;
@@ -589,26 +606,31 @@ public class TextUtils {
* @param str the string to be examined
* @return true if str is null or zero length
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isEmpty(@Nullable CharSequence str) {
return str == null || str.length() == 0;
}
/** {@hide} */
+ @android.ravenwood.annotation.RavenwoodKeep
public static String nullIfEmpty(@Nullable String str) {
return isEmpty(str) ? null : str;
}
/** {@hide} */
+ @android.ravenwood.annotation.RavenwoodKeep
public static String emptyIfNull(@Nullable String str) {
return str == null ? "" : str;
}
/** {@hide} */
+ @android.ravenwood.annotation.RavenwoodKeep
public static String firstNotEmpty(@Nullable String a, @NonNull String b) {
return !isEmpty(a) ? a : Preconditions.checkStringNotEmpty(b);
}
/** {@hide} */
+ @android.ravenwood.annotation.RavenwoodKeep
public static int length(@Nullable String s) {
return s != null ? s.length() : 0;
}
@@ -617,6 +639,7 @@ public class TextUtils {
* @return interned string if it's null.
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String safeIntern(String s) {
return (s != null) ? s.intern() : null;
}
@@ -626,6 +649,7 @@ public class TextUtils {
* spaces and ASCII control characters were trimmed from the start and end,
* as by {@link String#trim}.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static int getTrimmedLength(CharSequence s) {
int len = s.length();
@@ -650,6 +674,7 @@ public class TextUtils {
* @param b second CharSequence to check
* @return true if a and b are equal
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean equals(CharSequence a, CharSequence b) {
if (a == b) return true;
int length;
@@ -1679,6 +1704,7 @@ public class TextUtils {
return true;
}
+ @android.ravenwood.annotation.RavenwoodReplace
/* package */ static char[] obtain(int len) {
char[] buf;
@@ -1693,6 +1719,11 @@ public class TextUtils {
return buf;
}
+ /* package */ static char[] obtain$ravenwood(int len) {
+ return new char[len];
+ }
+
+ @android.ravenwood.annotation.RavenwoodReplace
/* package */ static void recycle(char[] temp) {
if (temp.length > 1000)
return;
@@ -1702,11 +1733,16 @@ public class TextUtils {
}
}
+ /* package */ static void recycle$ravenwood(char[] temp) {
+ // Handled by typical GC
+ }
+
/**
* Html-encode the string.
* @param s the string to be encoded
* @return the encoded string
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static String htmlEncode(String s) {
StringBuilder sb = new StringBuilder();
char c;
@@ -1793,6 +1829,7 @@ public class TextUtils {
/**
* Returns whether the given CharSequence contains any printable characters.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isGraphic(CharSequence str) {
final int len = str.length();
for (int cp, i=0; i<len; i+=Character.charCount(cp)) {
@@ -1819,6 +1856,7 @@ public class TextUtils {
* @deprecated Use {@link #isGraphic(CharSequence)} instead.
*/
@Deprecated
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isGraphic(char c) {
int gc = Character.getType(c);
return gc != Character.CONTROL
@@ -1833,6 +1871,7 @@ public class TextUtils {
/**
* Returns whether the given CharSequence contains only digits.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isDigitsOnly(CharSequence str) {
final int len = str.length();
for (int cp, i = 0; i < len; i += Character.charCount(cp)) {
@@ -1847,6 +1886,7 @@ public class TextUtils {
/**
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isPrintableAscii(final char c) {
final int asciiFirst = 0x20;
final int asciiLast = 0x7E; // included
@@ -1857,6 +1897,7 @@ public class TextUtils {
* @hide
*/
@UnsupportedAppUsage
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isPrintableAsciiOnly(final CharSequence str) {
final int len = str.length();
for (int i = 0; i < len; i++) {
@@ -1908,6 +1949,7 @@ public class TextUtils {
* {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and
* {@link #CAP_MODE_SENTENCES}.
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static int getCapsMode(CharSequence cs, int off, int reqModes) {
if (off < 0) {
return 0;
@@ -2153,6 +2195,7 @@ public class TextUtils {
* match the supported grammar described above.
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static @NonNull String formatSimple(@NonNull String format, Object... args) {
final StringBuilder sb = new StringBuilder(format);
int j = 0;
@@ -2342,6 +2385,7 @@ public class TextUtils {
}
/** @hide */
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isNewline(int codePoint) {
int type = Character.getType(codePoint);
return type == Character.PARAGRAPH_SEPARATOR || type == Character.LINE_SEPARATOR
@@ -2349,16 +2393,19 @@ public class TextUtils {
}
/** @hide */
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isWhitespace(int codePoint) {
return Character.isWhitespace(codePoint) || codePoint == NBSP_CODE_POINT;
}
/** @hide */
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isWhitespaceExceptNewline(int codePoint) {
return isWhitespace(codePoint) && !isNewline(codePoint);
}
/** @hide */
+ @android.ravenwood.annotation.RavenwoodKeep
public static boolean isPunctuation(int codePoint) {
int type = Character.getType(codePoint);
return type == Character.CONNECTOR_PUNCTUATION
@@ -2608,6 +2655,4 @@ public class TextUtils {
private static Object sLock = new Object();
private static char[] sTemp = null;
-
- private static String[] EMPTY_STRING_ARRAY = new String[]{};
}
diff --git a/ravenwood/framework-minus-apex-ravenwood-policies.txt b/ravenwood/framework-minus-apex-ravenwood-policies.txt
index aa2d470d7d9c..28639d4960a4 100644
--- a/ravenwood/framework-minus-apex-ravenwood-policies.txt
+++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt
@@ -129,7 +129,3 @@ class android.net.UriCodec stubclass
# Context: just enough to support wrapper, no further functionality
class android.content.Context stub
method <init> ()V stub
-
-# Text
-class android.text.TextUtils stub
- method isEmpty (Ljava/lang/CharSequence;)Z stub
diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt
index 128155cc63df..df44fde2ed72 100644
--- a/ravenwood/ravenwood-annotation-allowed-classes.txt
+++ b/ravenwood/ravenwood-annotation-allowed-classes.txt
@@ -35,3 +35,6 @@ android.database.MatrixCursor
android.database.MatrixCursor$RowBuilder
android.database.MergeCursor
android.database.Observable
+
+android.text.TextUtils
+android.text.TextUtils$SimpleStringSplitter