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, boolean trim) {
} else {
return null;
}
+
+ // Check up front if this is a URI syntax string with query arguments
+ Hashtable nameValuePairs = parseNameValuePairs(rawText);
+ String subject = null;
+ String body = null;
+ boolean querySyntax = false;
+ if (nameValuePairs != null && nameValuePairs.size() > 0) {
+ subject = (String) nameValuePairs.get("subject");
+ body = (String) nameValuePairs.get("body");
+ querySyntax = true;
+ }
+
// Drop sms, query portion
int queryStart = rawText.indexOf('?', prefixLength);
String smsURIWithoutQuery;
- if (queryStart < 0) {
+ // If it's not query syntax, the question mark is part of the subject or message
+ if (queryStart < 0 || !querySyntax) {
smsURIWithoutQuery = rawText.substring(prefixLength);
} else {
smsURIWithoutQuery = rawText.substring(prefixLength, queryStart);
via = null;
}
}
- Hashtable nameValuePairs = parseNameValuePairs(rawText);
- String subject = null;
- String body = null;
- if (nameValuePairs != null) {
- subject = (String) nameValuePairs.get("subject");
- body = (String) nameValuePairs.get("body");
- }
+
// Thanks to dominik.wild for suggesting this enhancement to support
// smsto:number:body URIs
if (body == null) {
doTestResult("TEL:+15551212", ParsedResultType.TEL);
doTestResult("tel:212 555 1212", ParsedResultType.TEL);
doTestResult("tel:2125551212", ParsedResultType.TEL);
+ doTestResult("tel:212-555-1212", ParsedResultType.TEL);
doTestResult("telephone", ParsedResultType.TEXT);
}
doTestResult("sms:+15551212;via=999333", ParsedResultType.SMS);
doTestResult("sms:+15551212?subject=foo&body=bar", ParsedResultType.SMS);
doTestResult("sms:+15551212:subject", ParsedResultType.SMS);
+ // Need to handle question mark in the subject
+ doTestResult("sms:+15551212:What's up?", ParsedResultType.SMS);
+ doTestResult("sms:212-555-1212:Here's a longer message. Should be fine.", ParsedResultType.SMS);
}
public void testMMS() {
doTestResult("mms:+15551212;via=999333", ParsedResultType.SMS);
doTestResult("mms:+15551212?subject=foo&body=bar", ParsedResultType.SMS);
doTestResult("mms:+15551212:subject", ParsedResultType.SMS);
+ doTestResult("mms:+15551212:What's up?", ParsedResultType.SMS);
+ doTestResult("mms:212-555-1212:Here's a longer message. Should be fine.", ParsedResultType.SMS);
}
/*
import com.google.zxing.MultiFormatReader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
+import com.google.zxing.client.result.ParsedResult;
+import com.google.zxing.client.result.ResultParser;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URI;
-import java.util.Hashtable;
import java.nio.charset.Charset;
+import java.util.Hashtable;
/**
* <p>This simple command line utility decodes files, directories of files, or URIs which are passed
try {
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
Result result = new MultiFormatReader().decode(source, hints);
- System.out.println(uri.toString() + " (format: " + result.getBarcodeFormat() + "):\n" +
- result.getText());
+ ParsedResult parsedResult = ResultParser.parseResult(result);
+ System.out.println(uri.toString() + " (format: " + result.getBarcodeFormat() +
+ ", type: " + parsedResult.getType() + "):\nRaw result:\n" + result.getText() +
+ "\nParsed result:\n" + parsedResult.getDisplayResult());
return result;
} catch (ReaderException e) {
System.out.println(uri.toString() + ": No barcode found");