diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2010-03-15 16:20:35 -0700 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2010-03-15 16:20:35 -0700 |
commit | e0bbba6a6026b2577e62097ea8f8f7ebe48da8f5 (patch) | |
tree | fa6939bd75ae9f6f44804d1899463d94062e8125 /src/com/android/providers | |
parent | 42aff67de3f0f4b8664a74fe6ff63ae191aa51bf (diff) | |
download | packages_providers_ContactsProvider-e0bbba6a6026b2577e62097ea8f8f7ebe48da8f5.zip packages_providers_ContactsProvider-e0bbba6a6026b2577e62097ea8f8f7ebe48da8f5.tar.gz packages_providers_ContactsProvider-e0bbba6a6026b2577e62097ea8f8f7ebe48da8f5.tar.bz2 |
Allowing "-" to occur in contact lookup key
Change-Id: I3402f0ec6ae6196615d428395d27f454fe026fd6
Diffstat (limited to 'src/com/android/providers')
-rw-r--r-- | src/com/android/providers/contacts/ContactLookupKey.java | 109 |
1 files changed, 73 insertions, 36 deletions
diff --git a/src/com/android/providers/contacts/ContactLookupKey.java b/src/com/android/providers/contacts/ContactLookupKey.java index 63b9a6c..5f4bd64 100644 --- a/src/com/android/providers/contacts/ContactLookupKey.java +++ b/src/com/android/providers/contacts/ContactLookupKey.java @@ -109,7 +109,7 @@ public class ContactLookupKey { int length = string.length(); int hashCode = 0; int lookupType = -1; - boolean escaped; + boolean escaped = false; String rawContactId = null; String key; @@ -135,59 +135,96 @@ public class ContactLookupKey { escaped = true; } else if (c == 'n') { lookupType = LOOKUP_TYPE_DISPLAY_NAME; - escaped = false; } else if (c == 'r') { lookupType = LOOKUP_TYPE_RAW_CONTACT_ID; - escaped = false; } else { throw new IllegalArgumentException("Invalid lookup id: " + lookupKey); } // Parse the source ID or normalized display name - if (escaped) { - StringBuffer sb = new StringBuffer(); - while (offset < length) { - c = string.charAt(offset++); - - if (c == '.') { + switch (lookupType) { + case LOOKUP_TYPE_SOURCE_ID: { + if (escaped) { + StringBuffer sb = new StringBuffer(); + while (offset < length) { + c = string.charAt(offset++); + + if (c == '.') {contactId + if (offset == length) { + throw new IllegalArgumentException("Invalid lookup id: " + + lookupKey); + } + c = string.charAt(offset); + + if (c == '.') { + sb.append('.'); + offset++; + } else { + break; + } + } else { + sb.append(c); + } + } + key = sb.toString(); + } else { + int start = offset; + while (offset < length) { + c = string.charAt(offset++); + if (c == '.') { + break; + } + } if (offset == length) { - throw new IllegalArgumentException("Invalid lookup id: " + lookupKey); + key = string.substring(start); + } else { + key = string.substring(start, offset - 1); } - c = string.charAt(offset); - + } + break; + } + case LOOKUP_TYPE_DISPLAY_NAME: { + int start = offset; + while (offset < length) { + c = string.charAt(offset++); if (c == '.') { - sb.append('.'); - offset++; - } else { break; } + } + if (offset == length) { + key = string.substring(start); } else { - sb.append(c); + key = string.substring(start, offset - 1); } + break; } - key = sb.toString(); - } else { - int dash = -1; - int start = offset; - while (offset < length) { - c = string.charAt(offset); - if (c == '-' && dash == -1) { - dash = offset; + case LOOKUP_TYPE_RAW_CONTACT_ID: { + int dash = -1; + int start = offset; + while (offset < length) { + c = string.charAt(offset); + if (c == '-' && dash == -1) { + dash = offset; + } + offset++; + if (c == '.') { + break; + } } - offset++; - if (c == '.') { - break; + if (dash != -1) { + rawContactId = string.substring(start, dash); + start = dash + 1; } + if (offset == length) { + key = string.substring(start); + } else { + key = string.substring(start, offset - 1); + } + break; } - if (dash != -1) { - rawContactId = string.substring(start, dash); - start = dash + 1; - } - if (offset == length) { - key = string.substring(start); - } else { - key = string.substring(start, offset - 1); - } + default: + // Will never happen + throw new IllegalStateException(); } LookupKeySegment segment = new LookupKeySegment(); |