From 26e3f68ae8342cedd57353e399e7d0e920228a4e Mon Sep 17 00:00:00 2001 From: mindyp Date: Mon, 27 Aug 2012 10:32:17 -0700 Subject: Deal with commas within quoted text If there is a comma within quoted text, it is NOT a chip ending token Fixes b/7001805 Names appended to email ids like "Mathew, Deepthi E" are split into two chips while replying Change-Id: I87f34a44282b3baf8d106dd21f8211ad301395be --- .../com/android/ex/chips/RecipientEditTextView.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'chips/src') diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index 618c215..9aefaaf 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -100,6 +100,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements private static final char COMMIT_CHAR_COMMA = ','; + private static final char NAME_WRAPPER_CHAR = '"'; + private static final char COMMIT_CHAR_SEMICOLON = ';'; private static final char COMMIT_CHAR_SPACE = ' '; @@ -347,9 +349,20 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } super.append(text, start, end); if (!TextUtils.isEmpty(text) && TextUtils.getTrimmedLength(text) > 0) { - final String displayString = text.toString(); - int seperatorPos = displayString.indexOf(COMMIT_CHAR_COMMA); - if (seperatorPos != 0 && !TextUtils.isEmpty(displayString) + String displayString = text.toString(); + int separatorPos = displayString.indexOf(COMMIT_CHAR_COMMA); + // Verify that the separator pos is not within ""; if it is, look + // past the closing quote. If there is no comma past ", this string + // will resolve to an error chip. + if (separatorPos > -1) { + displayString = displayString.substring(separatorPos); + int endQuotedTextPos = displayString.indexOf(NAME_WRAPPER_CHAR); + if (endQuotedTextPos > separatorPos) { + displayString = displayString.substring(endQuotedTextPos); + separatorPos = displayString.indexOf(COMMIT_CHAR_COMMA); + } + } + if (separatorPos > 0 && !TextUtils.isEmpty(displayString) && TextUtils.getTrimmedLength(displayString) > 0) { mPendingChipsCount++; mPendingChips.add(text.toString()); -- cgit v1.2.3