mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Loosen BDAY parsing for vCard results
git-svn-id: https://zxing.googlecode.com/svn/trunk@1118 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
c0c1290611
commit
f75a6ec766
|
@ -208,6 +208,24 @@ public abstract class ResultParser {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static boolean isSubstringOfDigits(String value, int offset, int length) {
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int stringLength = value.length();
|
||||||
|
int max = offset + length;
|
||||||
|
if (stringLength < max) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = offset; i < max; i++) {
|
||||||
|
char c = value.charAt(i);
|
||||||
|
if (c < '0' || c > '9') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static Hashtable parseNameValuePairs(String uri) {
|
static Hashtable parseNameValuePairs(String uri) {
|
||||||
int paramStart = uri.indexOf('?');
|
int paramStart = uri.indexOf('?');
|
||||||
if (paramStart < 0) {
|
if (paramStart < 0) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ final class VCardResultParser extends ResultParser {
|
||||||
address = formatAddress(address);
|
address = formatAddress(address);
|
||||||
String org = matchSingleVCardPrefixedField("ORG", rawText, true);
|
String org = matchSingleVCardPrefixedField("ORG", rawText, true);
|
||||||
String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true);
|
String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true);
|
||||||
if (birthday != null && !isStringOfDigits(birthday, 8)) {
|
if (!isLikeVCardDate(birthday)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
|
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
|
||||||
|
@ -114,6 +114,22 @@ final class VCardResultParser extends ResultParser {
|
||||||
return values == null ? null : values[0];
|
return values == null ? null : values[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isLikeVCardDate(String value) {
|
||||||
|
// Not really sure this is true but matches practice
|
||||||
|
// Mach YYYYMMDD
|
||||||
|
if (isStringOfDigits(value, 8)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// or YYYY-MM-DD
|
||||||
|
return
|
||||||
|
value.length() == 10 &&
|
||||||
|
value.charAt(4) == '-' &&
|
||||||
|
value.charAt(7) == '-' &&
|
||||||
|
isSubstringOfDigits(value, 0, 4) &&
|
||||||
|
isSubstringOfDigits(value, 5, 2) &&
|
||||||
|
isSubstringOfDigits(value, 8, 2);
|
||||||
|
}
|
||||||
|
|
||||||
private static String formatAddress(String address) {
|
private static String formatAddress(String address) {
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue