I found myself trying to copy/paste coordinates for my dives from diving
websites / forums and Subsurface did not accept them because it was
applying strictly the suggestions from ISO6709 Annex D.
Now it parses them correctly with messy whitespace and use of '' (double
simple quotes) instead of " (single char of double quotes) for the seconds
symbol which I found to be a very common mistake at this kind of sites.

Regards,
Jose
From dbd1772d45855531c137495d967c7279c19aaa41 Mon Sep 17 00:00:00 2001
From: Jose Carlos Andreu <[email protected]>
Date: Sun, 25 May 2014 23:07:22 +0200
Subject: [PATCH] Make ISO6709 coordinate regex less restrictive
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Coordinates that do not conform strictly to ISO-6709 should be parsed
and accepted.
Such as:
41° 49' 37.585"N 3° 7' 42.085"E (Incorrect whitespaces)
41° 49' 37.585''N 3° 7' 42.085''E ('' instead of " and bad whitespaces)

Signed-off-by: Jose Carlos Andreu <[email protected]>
---
 qthelper.cpp |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index bcf78b5..0dbe0fc 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -82,10 +82,11 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 	// ISO 6709 Annex D representation
 	// http://en.wikipedia.org/wiki/ISO_6709#Representation_at_the_human_interface_.28Annex_D.29
 	// e.g. 52°49'02.388"N 1°36'17.388"E
-	if (gps_text.at(0).isDigit() && (gps_text.count(",") % 2) == 0) {
+	if (gps_text.at(0).isDigit() && ((gps_text.count(",") % 2) == 0 || gps_text.count(QChar('\'')) == 6)) {
 		gpsStyle = ISO6709D;
-		regExp = QString("(\\d+)[" UTF8_DEGREE "\\s](\\d+)[\'\\s](\\d+)([,\\.](\\d+))?[\"\\s]([NS%1%2])"
-				 "\\s*(\\d+)[" UTF8_DEGREE "\\s](\\d+)[\'\\s](\\d+)([,\\.](\\d+))?[\"\\s]([EW%3%4])")
+		regExp = QString("(\\d+)([" UTF8_DEGREE "\\s]|" UTF8_DEGREE "\\s*)(\\d+)([\'\\s]|\'\\s*)(\\d+)([,\\.]
+				 (\\d+))?([\"\\s]|\'\'\\s*)([NS%1%2])""\\s*(\\d+)([" UTF8_DEGREE "\\s]|" UTF8_DEGREE "\\s*)(\\d+)
+				 ([\'\\s]|\'\\s*)(\\d+)([,\\.](\\d+))?([\"\\s]|\'\'\\s*)([EW%3%4])")
 				 .arg(trHemisphere[0])
 				 .arg(trHemisphere[1])
 				 .arg(trHemisphere[2])
@@ -126,12 +127,12 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 		// qDebug() << "Hemisphere" << r.cap(5) << "deg" << r.cap(6) << "min" << r.cap(7) << "decimal" << r.cap(8);
 		switch (gpsStyle) {
 		case ISO6709D:
-			*latitude = r.cap(1).toInt() + r.cap(2).toInt() / 60.0 +
-				    (r.cap(3) + QString(".") + r.cap(5)).toDouble() / 3600.0;
-			*longitude = r.cap(7).toInt() + r.cap(8).toInt() / 60.0 +
-				     (r.cap(9) + QString(".") + r.cap(11)).toDouble() / 3600.0;
-			northSouth = 6;
-			eastWest = 12;
+			*latitude = r.cap(1).toInt() + r.cap(3).toInt() / 60.0 +
+				    (r.cap(5) + QString(".") + r.cap(7)).toDouble() / 3600.0;
+			*longitude = r.cap(10).toInt() + r.cap(12).toInt() / 60.0 +
+				     (r.cap(14) + QString(".") + r.cap(16)).toDouble() / 3600.0;
+			northSouth = 9;
+			eastWest = 18;
 			break;
 		case SECONDS:
 			*latitude = r.cap(2).toInt() + r.cap(3).toInt() / 60.0 +
-- 
1.7.9.5

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to