mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
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:
parent
ad24a551aa
commit
65ce3f0896
|
@ -59,7 +59,7 @@ public final class VCardResultParser extends ResultParser {
|
||||||
List<List<String>> names = matchVCardPrefixedField("FN", rawText, true, false);
|
List<List<String>> names = matchVCardPrefixedField("FN", rawText, true, false);
|
||||||
if (names == null) {
|
if (names == null) {
|
||||||
// If no display names found, look for regular name fields and format them
|
// 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);
|
formatNames(names);
|
||||||
}
|
}
|
||||||
List<String> nicknameString = matchSingleVCardPrefixedField("NICKNAME", rawText, true, false);
|
List<String> nicknameString = matchSingleVCardPrefixedField("NICKNAME", rawText, true, false);
|
||||||
|
@ -328,7 +328,7 @@ public final class VCardResultParser extends ResultParser {
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end;
|
int end;
|
||||||
int componentIndex = 0;
|
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);
|
components[componentIndex] = name.substring(start, end);
|
||||||
componentIndex++;
|
componentIndex++;
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
|
@ -346,8 +346,10 @@ public final class VCardResultParser extends ResultParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void maybeAppendComponent(String[] components, int i, StringBuilder newName) {
|
private static void maybeAppendComponent(String[] components, int i, StringBuilder newName) {
|
||||||
if (components[i] != null) {
|
if (components[i] != null && !components[i].isEmpty()) {
|
||||||
newName.append(' ');
|
if (newName.length() > 0) {
|
||||||
|
newName.append(' ');
|
||||||
|
}
|
||||||
newName.append(components[i]);
|
newName.append(components[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
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
|
@Test
|
||||||
public void testVCardCaseInsensitive() {
|
public void testVCardCaseInsensitive() {
|
||||||
doTest("begin:vcard\r\nadr;HOME:123 Main St\r\nVersion:2.1\r\nn:Owen;Sean\r\nEND:VCARD",
|
doTest("begin:vcard\r\nadr;HOME:123 Main St\r\nVersion:2.1\r\nn:Owen;Sean\r\nEND:VCARD",
|
||||||
|
|
Loading…
Reference in a new issue