X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fresult%2FResultParser.java;h=bdcc4d09b748de6c1347d505083ef1867e25a51b;hp=fdac7c73892548edc73af42d788f9489d54efe74;hb=10276c1fd6c1871565ad6d6c87f0249f1c0b7e5c;hpb=ed4df5179ca5848b9ea9869ccb36033edbcfb0d6 diff --git a/core/src/com/google/zxing/client/result/ResultParser.java b/core/src/com/google/zxing/client/result/ResultParser.java index fdac7c73..bdcc4d09 100644 --- a/core/src/com/google/zxing/client/result/ResultParser.java +++ b/core/src/com/google/zxing/client/result/ResultParser.java @@ -30,7 +30,7 @@ import java.util.Vector; *

Thanks to Jeff Griffin for proposing rewrite of these classes that relies less * on exception-based mechanisms during parsing.

* - * @author srowen@google.com (Sean Owen) + * @author Sean Owen */ public abstract class ResultParser { @@ -45,8 +45,6 @@ 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) { @@ -55,19 +53,30 @@ public abstract class ResultParser { 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 = ISBNResultParser.parse(theResult)) != null) { + // We depend on ISBN parsing coming before UPC, as it is a subset. return result; - } else if ((result = UPCResultParser.parse(theResult)) != null) { + } else if ((result = ProductResultParser.parse(theResult)) != null) { + return result; + } else if ((result = ExpandedProductResultParser.parse(theResult)) != null) { return result; } return new TextParsedResult(theResult.getText(), null); @@ -89,6 +98,10 @@ public abstract class ResultParser { } } + 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) '\\'); @@ -112,7 +125,7 @@ public abstract class ResultParser { return escaped; } - 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) { @@ -203,6 +216,24 @@ public abstract class ResultParser { 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) { @@ -227,14 +258,11 @@ public abstract class ResultParser { 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(); @@ -260,7 +288,11 @@ public abstract class ResultParser { 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; } @@ -272,8 +304,8 @@ public abstract class ResultParser { 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]; }