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) {
int paramStart = uri.indexOf('?');
if (paramStart < 0) {
address = formatAddress(address);
String org = matchSingleVCardPrefixedField("ORG", rawText, true);
String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true);
- if (birthday != null && !isStringOfDigits(birthday, 8)) {
+ if (!isLikeVCardDate(birthday)) {
return null;
}
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
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) {
if (address == null) {
return null;