Issue 1788 additional fix for vCard delimited name parsing

git-svn-id: https://zxing.googlecode.com/svn/trunk@2900 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-10-13 23:05:14 +00:00
parent ad24a551aa
commit 65ce3f0896
2 changed files with 24 additions and 4 deletions

View file

@ -59,7 +59,7 @@ public final class VCardResultParser extends ResultParser {
List<List<String>> names = matchVCardPrefixedField("FN", rawText, true, false);
if (names == null) {
// If no display names found, look for regular name fields and format them
names = matchVCardPrefixedField("N", rawText, true, true);
names = matchVCardPrefixedField("N", rawText, true, false);
formatNames(names);
}
List<String> nicknameString = matchSingleVCardPrefixedField("NICKNAME", rawText, true, false);
@ -328,7 +328,7 @@ public final class VCardResultParser extends ResultParser {
int start = 0;
int end;
int componentIndex = 0;
while (componentIndex < components.length - 1 && (end = name.indexOf(';', start)) > 0) {
while (componentIndex < components.length - 1 && (end = name.indexOf(';', start)) >= 0) {
components[componentIndex] = name.substring(start, end);
componentIndex++;
start = end + 1;
@ -346,8 +346,10 @@ public final class VCardResultParser extends ResultParser {
}
private static void maybeAppendComponent(String[] components, int i, StringBuilder newName) {
if (components[i] != null) {
newName.append(' ');
if (components[i] != null && !components[i].isEmpty()) {
if (newName.length() > 0) {
newName.append(' ');
}
newName.append(components[i]);
}
}

View file

@ -48,6 +48,24 @@ public final class AddressBookParsedResultTestCase extends Assert {
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, null, null, null, null, null, null);
}
@Test
public void testVCardFullN() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;T;Mr.;Esq.\r\nEND:VCARD",
null, new String[] {"Mr. Sean T Owen Esq."}, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardFullN2() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;;;\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardFullN3() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:;Sean;;;\r\nEND:VCARD",
null, new String[] {"Sean"}, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardCaseInsensitive() {
doTest("begin:vcard\r\nadr;HOME:123 Main St\r\nVersion:2.1\r\nn:Owen;Sean\r\nEND:VCARD",