aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/geopoint/GeopointParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/geopoint/GeopointParser.java')
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
index ba86e70..c043d6f 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -25,8 +25,8 @@ class GeopointParser {
}
// ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 )
- private static final Pattern PATTERN_LAT = Pattern.compile("\\b([NS])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
- private static final Pattern PATTERN_LON = Pattern.compile("\\b([WE])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
+ private static final Pattern PATTERN_LAT = Pattern.compile("\\b([NS]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
+ private static final Pattern PATTERN_LON = Pattern.compile("\\b([WE]|)\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
private static final Pattern PATTERN_BAD_BLANK = Pattern.compile("(\\d)[,.] (\\d{2,})");
@@ -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 decimaldegree
+ // 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.