aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-10-12 10:45:04 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-10-12 10:45:04 +0200
commit863ca04913920a4473c127b6017aa84f04dd5b59 (patch)
tree7f6c8af47611b43a89e63d0d88ec8489cb2c5fc4
parent51aae851f35e4bbd04cbfc898b906a27ff54c83f (diff)
downloadcgeo-863ca04913920a4473c127b6017aa84f04dd5b59.zip
cgeo-863ca04913920a4473c127b6017aa84f04dd5b59.tar.gz
cgeo-863ca04913920a4473c127b6017aa84f04dd5b59.tar.bz2
fix failing test
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
index 136664c..c043d6f 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -110,6 +110,12 @@ class GeopointParser {
final Pattern pattern = LatLon.LAT == latlon ? PATTERN_LAT : PATTERN_LON;
matcher = new MatcherWrapper(pattern, replaceSpaceAfterComma);
+ try {
+ return new ResultWrapper(Double.valueOf(replaceSpaceAfterComma), 0, text.length());
+ } catch (NumberFormatException e1) {
+ // fall through to advanced parsing
+ }
+
if (matcher.find()) {
final double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0 : 1.0;
final double degree = Integer.valueOf(matcher.group(2)).doubleValue();
@@ -131,13 +137,14 @@ class GeopointParser {
}
- // Nothing found with "N 52...", try to match string as decimal degree
+ // Nothing found with "N 52...", try to match string as decimal degree parts (i.e. multiple doubles)
try {
final String[] items = StringUtils.split(text.trim());
- if (items.length > 0) {
+ if (items.length > 0 && items.length <= 2) {
final int index = (latlon == LatLon.LON ? items.length - 1 : 0);
- final int pos = (latlon == LatLon.LON ? text.lastIndexOf(items[index]) : text.indexOf(items[index]));
- return new ResultWrapper(Double.parseDouble(items[index]), pos, items[index].length());
+ final String textPart = items[index];
+ final int pos = (latlon == LatLon.LON ? text.lastIndexOf(textPart) : text.indexOf(textPart));
+ return new ResultWrapper(Double.parseDouble(textPart), pos, textPart.length());
}
} catch (NumberFormatException e) {
// The right exception will be raised below.