aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/geopoint
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/geopoint')
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java6
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java19
2 files changed, 16 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index 547ad29..f21df01 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -300,7 +300,7 @@ public final class Geopoint implements ICoordinates, Parcelable {
/**
* Returns formatted coordinates with default format.
* Default format is decimalminutes, e.g. N 52° 36.123 E 010° 03.456
- *
+ *
* @return formatted coordinates
*/
@Override
@@ -364,8 +364,8 @@ public final class Geopoint implements ICoordinates, Parcelable {
}
/**
- * Get longitude chararcter (E or W).
- *
+ * Get longitude character (E or W).
+ *
* @return
*/
public char getLonDir() {
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.