mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Preserve query in geo URI
git-svn-id: https://zxing.googlecode.com/svn/trunk@1514 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ffb33d4c74
commit
0a5e8e9298
|
@ -24,12 +24,14 @@ public final class GeoParsedResult extends ParsedResult {
|
|||
private final double latitude;
|
||||
private final double longitude;
|
||||
private final double altitude;
|
||||
private final String query;
|
||||
|
||||
GeoParsedResult(double latitude, double longitude, double altitude) {
|
||||
GeoParsedResult(double latitude, double longitude, double altitude, String query) {
|
||||
super(ParsedResultType.GEO);
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public String getGeoURI() {
|
||||
|
@ -42,6 +44,10 @@ public final class GeoParsedResult extends ParsedResult {
|
|||
result.append(',');
|
||||
result.append(altitude);
|
||||
}
|
||||
if (query != null) {
|
||||
result.append('?');
|
||||
result.append(query);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
@ -66,8 +72,15 @@ public final class GeoParsedResult extends ParsedResult {
|
|||
return altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return query string associated with geo URI or null if none exists
|
||||
*/
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuffer result = new StringBuffer(20);
|
||||
result.append(latitude);
|
||||
result.append(", ");
|
||||
result.append(longitude);
|
||||
|
@ -76,6 +89,11 @@ public final class GeoParsedResult extends ParsedResult {
|
|||
result.append(altitude);
|
||||
result.append('m');
|
||||
}
|
||||
if (query != null) {
|
||||
result.append(" (");
|
||||
result.append(query);
|
||||
result.append(')');
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,15 @@ final class GeoResultParser extends ResultParser {
|
|||
}
|
||||
// Drop geo, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String geoURIWithoutQuery = queryStart < 0 ? rawText.substring(4) : rawText.substring(4, queryStart);
|
||||
String query;
|
||||
String geoURIWithoutQuery;
|
||||
if (queryStart < 0) {
|
||||
query = null;
|
||||
geoURIWithoutQuery = rawText.substring(4);
|
||||
} else {
|
||||
query = rawText.substring(queryStart + 1);
|
||||
geoURIWithoutQuery = rawText.substring(4, queryStart);
|
||||
}
|
||||
int latitudeEnd = geoURIWithoutQuery.indexOf(',');
|
||||
if (latitudeEnd < 0) {
|
||||
return null;
|
||||
|
@ -63,7 +71,7 @@ final class GeoResultParser extends ResultParser {
|
|||
} catch (NumberFormatException nfe) {
|
||||
return null;
|
||||
}
|
||||
return new GeoParsedResult(latitude, longitude, altitude);
|
||||
return new GeoParsedResult(latitude, longitude, altitude, query);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,12 +28,17 @@ import junit.framework.TestCase;
|
|||
public final class GeoParsedResultTestCase extends TestCase {
|
||||
|
||||
public void testGeo() {
|
||||
doTest("geo:1,2", 1.0, 2.0, 0.0);
|
||||
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35);
|
||||
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01);
|
||||
doTest("geo:1,2", 1.0, 2.0, 0.0, null);
|
||||
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35, null);
|
||||
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01, null);
|
||||
doTest("geo:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar");
|
||||
}
|
||||
|
||||
private static void doTest(String contents, double latitude, double longitude, double altitude) {
|
||||
private static void doTest(String contents,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double altitude,
|
||||
String query) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.GEO, result.getType());
|
||||
|
|
Loading…
Reference in a new issue