diff options
| author | 2018-06-27 13:53:12 +0000 | |
|---|---|---|
| committer | 2018-06-27 13:53:12 +0000 | |
| commit | b5f35aeaf38ff5547d6ed7a6ee78f2313f64b5e2 (patch) | |
| tree | 00ebf3a0b0e3a0cb58311e72d5cb733e27e83c05 | |
| parent | bc38909bf3790331532c329a867d5a22fbf94016 (diff) | |
| parent | 3e76c04c964e798723c4686e82425c4c182aa57b (diff) | |
Merge "TextUtils: track behavior change of Pattern.split() when targeting > 28."
| -rw-r--r-- | core/java/android/text/TextUtils.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 3e64af47c276..aca2bb834e10 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -333,8 +333,16 @@ public class TextUtils { } /** - * String.split() returns [''] when the string to be split is empty. This returns []. This does - * not remove any empty strings from the result. For example split("a,", "," ) returns {"a", ""}. + * + * This method yields the same result as {@code text.split(expression, -1)} except that if + * {@code text.isEmpty()} then this method returns an empty array whereas + * {@code "".split(expression, -1)} would have returned an array with a single {@code ""}. + * + * The {@code -1} means that trailing empty Strings are not removed from the result; for + * example split("a,", "," ) returns {"a", ""}. Note that whether a leading zero-width match + * can result in a leading {@code ""} depends on whether your app + * {@link android.content.pm.ApplicationInfo#targetSdkVersion targets an SDK version} + * {@code <= 28}; see {@link Pattern#split(CharSequence, int)}. * * @param text the string to split * @param expression the regular expression to match @@ -351,8 +359,16 @@ public class TextUtils { } /** - * Splits a string on a pattern. String.split() returns [''] when the string to be - * split is empty. This returns []. This does not remove any empty strings from the result. + * Splits a string on a pattern. This method yields the same result as + * {@code pattern.split(text, -1)} except that if {@code text.isEmpty()} then this method + * returns an empty array whereas {@code pattern.split("", -1)} would have returned an array + * with a single {@code ""}. + * + * The {@code -1} means that trailing empty Strings are not removed from the result; + * Note that whether a leading zero-width match can result in a leading {@code ""} depends + * on whether your app {@link android.content.pm.ApplicationInfo#targetSdkVersion targets + * an SDK version} {@code <= 28}; see {@link Pattern#split(CharSequence, int)}. + * * @param text the string to split * @param pattern the regular expression to match * @return an array of strings. The array will be empty if text is empty |