Skip to content

Commit

Permalink
Made our parsing code handle uppercase prefixes for a variety of loos…
Browse files Browse the repository at this point in the history
…ely-defined formats.

git-svn-id: http://zxing.googlecode.com/svn/trunk@779 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information
dswitkin committed Dec 8, 2008
1 parent 609ef6b commit 7871911
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
Expand Up @@ -34,7 +34,7 @@ public static EmailAddressParsedResult parse(Result result) {
return null;
}
String emailAddress;
if (rawText.startsWith("mailto:")) {
if (rawText.startsWith("mailto:") || rawText.startsWith("MAILTO:")) {
// If it starts with mailto:, assume it is definitely trying to be an email address
emailAddress = rawText.substring(7);
int queryStart = emailAddress.indexOf('?');
Expand Down
Expand Up @@ -33,7 +33,7 @@ private GeoResultParser() {

public static GeoParsedResult parse(Result result) {
String rawText = result.getText();
if (rawText == null || !rawText.startsWith("geo:")) {
if (rawText == null || (!rawText.startsWith("geo:") && !rawText.startsWith("GEO:"))) {
return null;
}
// Drop geo, query portion
Expand Down
Expand Up @@ -42,7 +42,8 @@ public static SMSParsedResult parse(Result result) {
return null;
}
int prefixLength;
if (rawText.startsWith("sms:") || rawText.startsWith("mms:")) {
if (rawText.startsWith("sms:") || rawText.startsWith("SMS:") ||
rawText.startsWith("mms:") || rawText.startsWith("MMS:")) {
prefixLength = 4;
} else if (rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:")) {
Expand Down
Expand Up @@ -30,7 +30,7 @@ private TelResultParser() {

public static TelParsedResult parse(Result result) {
String rawText = result.getText();
if (rawText == null || !rawText.startsWith("tel:")) {
if (rawText == null || (!rawText.startsWith("tel:") && !rawText.startsWith("TEL:"))) {
return null;
}
String telURI = rawText;
Expand Down
Expand Up @@ -32,7 +32,7 @@ private URLTOResultParser() {

public static URIParsedResult parse(Result result) {
String rawText = result.getText();
if (rawText == null || !rawText.startsWith("URLTO:")) {
if (rawText == null || (!rawText.startsWith("urlto:") && !rawText.startsWith("URLTO:"))) {
return null;
}
int titleEnd = rawText.indexOf(':', 6);
Expand Down
Expand Up @@ -42,6 +42,7 @@ public void testBookmarkType() {
}

public void testURLTOType() {
doTestResult("urlto:foo:bar.com", ParsedResultType.URI);
doTestResult("URLTO:foo:bar.com", ParsedResultType.URI);
doTestResult("URLTO::bar.com", ParsedResultType.URI);
doTestResult("URLTO::http://bar.com", ParsedResultType.URI);
Expand All @@ -58,6 +59,7 @@ public void testEmailType() {
public void testEmailAddressType() {
doTestResult("srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("mailto:srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MAILTO:srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("srowen@example", ParsedResultType.TEXT);
doTestResult("srowen", ParsedResultType.TEXT);
doTestResult("Let's meet @ 2", ParsedResultType.TEXT);
Expand All @@ -67,7 +69,7 @@ public void testAddressBookType() {
doTestResult("MECARD:N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedResultType.ADDRESSBOOK);
doTestResult("TEL:+12125551212;N:Sean Owen;;", ParsedResultType.TEXT);
doTestResult("N:Sean Owen;TEL:+12125551212;;", ParsedResultType.TEXT);
}

public void testAddressBookAUType() {
Expand Down Expand Up @@ -108,13 +110,15 @@ public void testURI() {

public void testGeo() {
doTestResult("geo:1,2", ParsedResultType.GEO);
doTestResult("GEO:1,2", ParsedResultType.GEO);
doTestResult("geo:1,2,3", ParsedResultType.GEO);
doTestResult("geo:100.33,-32.3344,3.35", ParsedResultType.GEO);
doTestResult("geography", ParsedResultType.TEXT);
}

public void testTel() {
doTestResult("tel:+15551212", ParsedResultType.TEL);
doTestResult("TEL:+15551212", ParsedResultType.TEL);
doTestResult("tel:212 555 1212", ParsedResultType.TEL);
doTestResult("tel:2125551212", ParsedResultType.TEL);
doTestResult("telephone", ParsedResultType.TEXT);
Expand Down Expand Up @@ -157,6 +161,7 @@ public void testVEvent() {

public void testSMS() {
doTestResult("sms:+15551212", ParsedResultType.SMS);
doTestResult("SMS:+15551212", ParsedResultType.SMS);
doTestResult("SMSTO:+15551212", ParsedResultType.SMS);
doTestResult("smsto:+15551212", ParsedResultType.SMS);
doTestResult("sms:+15551212;via=999333", ParsedResultType.SMS);
Expand All @@ -166,6 +171,7 @@ public void testSMS() {

public void testMMS() {
doTestResult("mms:+15551212", ParsedResultType.SMS);
doTestResult("MMS:+15551212", ParsedResultType.SMS);
doTestResult("MMSTO:+15551212", ParsedResultType.SMS);
doTestResult("mmsto:+15551212", ParsedResultType.SMS);
doTestResult("mms:+15551212;via=999333", ParsedResultType.SMS);
Expand Down

0 comments on commit 7871911

Please sign in to comment.