diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2010-09-10 16:07:52 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@android.com> | 2010-09-12 10:58:38 -0700 |
commit | 11fe181e16501103d7c0f70344661ea2ef5d3df9 (patch) | |
tree | 8a9a1f7dd9786f7bc5ec74c4d76025ad63b21235 /core/java/android/text/TextUtils.java | |
parent | 26cab06472badee374ac854f5a210991c37c4493 (diff) | |
download | frameworks_base-11fe181e16501103d7c0f70344661ea2ef5d3df9.zip frameworks_base-11fe181e16501103d7c0f70344661ea2ef5d3df9.tar.gz frameworks_base-11fe181e16501103d7c0f70344661ea2ef5d3df9.tar.bz2 |
Add faster TextUtil function for searching delimited lists.
The previous version in Settings allocated memory.
Change-Id: I0f821112dc8f830689489f201ce268195f9e6cbd
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 9589bf3..8675d05 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; } |