diff options
| author | Brad Fitzpatrick <bradfitz@android.com> | 2010-09-12 11:03:48 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-12 11:03:48 -0700 |
| commit | 171c83f47ddf01792371e1eb7587a99b2f192575 (patch) | |
| tree | 1ffbd0428d2d9ef8d3dbde49373e4a024d33ddeb /core/java/android/text/TextUtils.java | |
| parent | 12e08f3a8853ef4248ee9c18583c3b4917dd0c40 (diff) | |
| parent | 11fe181e16501103d7c0f70344661ea2ef5d3df9 (diff) | |
am 11fe181e: Add faster TextUtil function for searching delimited lists.
Merge commit '11fe181e16501103d7c0f70344661ea2ef5d3df9' into gingerbread-plus-aosp
* commit '11fe181e16501103d7c0f70344661ea2ef5d3df9':
Add faster TextUtil function for searching delimited lists.
Diffstat (limited to 'core/java/android/text/TextUtils.java')
| -rw-r--r-- | core/java/android/text/TextUtils.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 9589bf369e6e..8675d05f3116 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -1651,7 +1651,36 @@ public class TextUtils { return mode; } - + + /** + * Does a comma-delimited list 'delimitedString' contain a certain item? + * (without allocating memory) + * + * @hide + */ + public static boolean delimitedStringContains( + String delimitedString, char delimiter, String item) { + if (isEmpty(delimitedString) || isEmpty(item)) { + return false; + } + int pos = -1; + int length = delimitedString.length(); + while ((pos = delimitedString.indexOf(item, pos + 1)) != -1) { + if (pos > 0 && delimitedString.charAt(pos - 1) != delimiter) { + continue; + } + int expectedDelimiterPos = pos + item.length(); + if (expectedDelimiterPos == length) { + // Match at end of string. + return true; + } + if (delimitedString.charAt(expectedDelimiterPos) == delimiter) { + return true; + } + } + return false; + } + private static Object sLock = new Object(); private static char[] sTemp = null; } |
