AddressBookAUResultParser.java (zxing-zxing-3.4.0) | : | AddressBookAUResultParser.java (zxing-zxing-3.4.1) | ||
---|---|---|---|---|
skipping to change at line 47 | skipping to change at line 47 | |||
// MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF | // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF | |||
if (!rawText.contains("MEMORY") || !rawText.contains("\r\n")) { | if (!rawText.contains("MEMORY") || !rawText.contains("\r\n")) { | |||
return null; | return null; | |||
} | } | |||
// NAME1 and NAME2 have specific uses, namely written name and pronunciation , respectively. | // NAME1 and NAME2 have specific uses, namely written name and pronunciation , respectively. | |||
// Therefore we treat them specially instead of as an array of names. | // Therefore we treat them specially instead of as an array of names. | |||
String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true); | String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true); | |||
String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', tru e); | String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', tru e); | |||
String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true); | String[] phoneNumbers = matchMultipleValuePrefix("TEL", rawText); | |||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true); | String[] emails = matchMultipleValuePrefix("MAIL", rawText); | |||
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false); | String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false); | |||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true); | String address = matchSinglePrefixedField("ADD:", rawText, '\r', true); | |||
String[] addresses = address == null ? null : new String[] {address}; | String[] addresses = address == null ? null : new String[] {address}; | |||
return new AddressBookParsedResult(maybeWrap(name), | return new AddressBookParsedResult(maybeWrap(name), | |||
null, | null, | |||
pronunciation, | pronunciation, | |||
phoneNumbers, | phoneNumbers, | |||
null, | null, | |||
emails, | emails, | |||
null, | null, | |||
skipping to change at line 70 | skipping to change at line 70 | |||
note, | note, | |||
addresses, | addresses, | |||
null, | null, | |||
null, | null, | |||
null, | null, | |||
null, | null, | |||
null, | null, | |||
null); | null); | |||
} | } | |||
private static String[] matchMultipleValuePrefix(String prefix, | private static String[] matchMultipleValuePrefix(String prefix, String rawText | |||
int max, | ) { | |||
String rawText, | ||||
boolean trim) { | ||||
List<String> values = null; | List<String> values = null; | |||
for (int i = 1; i <= max; i++) { | // For now, always 3, and always trim | |||
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', t | for (int i = 1; i <= 3; i++) { | |||
rim); | String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', t | |||
rue); | ||||
if (value == null) { | if (value == null) { | |||
break; | break; | |||
} | } | |||
if (values == null) { | if (values == null) { | |||
values = new ArrayList<>(max); // lazy init | values = new ArrayList<>(3); // lazy init | |||
} | } | |||
values.add(value); | values.add(value); | |||
} | } | |||
if (values == null) { | if (values == null) { | |||
return null; | return null; | |||
} | } | |||
return values.toArray(EMPTY_STR_ARRAY); | return values.toArray(EMPTY_STR_ARRAY); | |||
} | } | |||
} | } | |||
End of changes. 4 change blocks. | ||||
10 lines changed or deleted | 9 lines changed or added |