* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
* on exception-based mechanisms during parsing.</p>
*
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
*/
public abstract class ResultParser {
return result;
} else if ((result = EmailDoCoMoResultParser.parse(theResult)) != null) {
return result;
- } else if ((result = EmailAddressResultParser.parse(theResult)) != null) {
- return result;
} else if ((result = AddressBookAUResultParser.parse(theResult)) != null) {
return result;
} else if ((result = VCardResultParser.parse(theResult)) != null) {
return result;
} else if ((result = BizcardResultParser.parse(theResult)) != null) {
return result;
+ } else if ((result = VEventResultParser.parse(theResult)) != null) {
+ return result;
+ } else if ((result = EmailAddressResultParser.parse(theResult)) != null) {
+ return result;
+ } else if ((result = SMTPResultParser.parse(theResult)) != null) {
+ return result;
} else if ((result = TelResultParser.parse(theResult)) != null) {
return result;
} else if ((result = SMSMMSResultParser.parse(theResult)) != null) {
return result;
+ } else if ((result = SMSTOMMSTOResultParser.parse(theResult)) != null) {
+ return result;
} else if ((result = GeoResultParser.parse(theResult)) != null) {
return result;
+ } else if ((result = WifiResultParser.parse(theResult)) != null) {
+ return result;
} else if ((result = URLTOResultParser.parse(theResult)) != null) {
return result;
} else if ((result = URIResultParser.parse(theResult)) != null) {
return result;
- } else if ((result = UPCResultParser.parse(theResult)) != null) {
+ } else if ((result = ISBNResultParser.parse(theResult)) != null) {
+ // We depend on ISBN parsing coming before UPC, as it is a subset.
+ return result;
+ } else if ((result = ProductResultParser.parse(theResult)) != null) {
+ return result;
+ } else if ((result = ExpandedProductResultParser.parse(theResult)) != null) {
return result;
}
return new TextParsedResult(theResult.getText(), null);
}
}
+ protected static String[] maybeWrap(String value) {
+ return value == null ? null : new String[] { value };
+ }
+
protected static String unescapeBackslash(String escaped) {
if (escaped != null) {
int backslash = escaped.indexOf((int) '\\');
return escaped;
}
- protected static String urlDecode(String escaped) {
+ private static String urlDecode(String escaped) {
// No we can't use java.net.URLDecoder here. JavaME doesn't have it.
if (escaped == null) {
return true;
}
- protected static Hashtable parseNameValuePairs(String uri) {
+ 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) {
return null;
String value = uri.substring(separator + 1, paramEnd);
value = urlDecode(value);
result.put(key, value);
- } else {
- // key, no value
- String key = uri.substring(paramStart, paramEnd);
- result.put(key, null);
}
+ // Can't put key, null into a hashtable
}
- static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
+ static String[] matchPrefixedField(String prefix, String rawText, char endChar, boolean trim) {
Vector matches = null;
int i = 0;
int max = rawText.length();
if (matches == null) {
matches = new Vector(3); // lazy init
}
- matches.addElement(unescapeBackslash(rawText.substring(start, i)));
+ String element = unescapeBackslash(rawText.substring(start, i));
+ if (trim) {
+ element = element.trim();
+ }
+ matches.addElement(element);
i++;
done = true;
}
return toStringArray(matches);
}
- static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
- String[] matches = matchPrefixedField(prefix, rawText, endChar);
+ static String matchSinglePrefixedField(String prefix, String rawText, char endChar, boolean trim) {
+ String[] matches = matchPrefixedField(prefix, rawText, endChar, trim);
return matches == null ? null : matches[0];
}