Got it edited.
Now only two extra group are being added (1 for lat and 1 for lon).
Maybe the grouping ([\'\\s]|\'\\s*) could be avoided, but if it's possible
I don't know how to do it.

Regards,
Jose



2014-05-27 0:22 GMT+02:00 Dirk Hohndel <[email protected]>:

> On Tue, May 27, 2014 at 12:03:15AM +0200, José Carlos Andreu Galán wrote:
> > -             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]\\s*(\\d+)([\'\\s]|\'\\s*)(\\d+)([,\\.]"
>
> same issue, just moved down the line...
>
> ([\'\\s]|\'\\s*) is overkill
>
> * allows zero or more
> so simply do
>
> [\'\\s]\\s*
>
> that saves you the group and makes the regex easier to read
>
> /D
>
From 0d1793f060339b67e2a6926f32af65d2863504d4 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 |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index bcf78b5..cfd08f6 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]\\s*(\\d+)[\'\\s]\\s*(\\d+)([,\\.]"
+				 "(\\d+))?([\"\\s]|\'\'\\s*)([NS%1%2])\\s*(\\d+)[" UTF8_DEGREE "\\s]\\s*(\\d+)"
+				 "[\'\\s]\\s*(\\d+)([,\\.](\\d+))?([\"\\s]|\'\'\\s*)([EW%3%4])")
 				 .arg(trHemisphere[0])
 				 .arg(trHemisphere[1])
 				 .arg(trHemisphere[2])
@@ -128,10 +129,10 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 		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;
+			*longitude = r.cap(8).toInt() + r.cap(9).toInt() / 60.0 +
+				     (r.cap(10) + QString(".") + r.cap(12)).toDouble() / 3600.0;
+			northSouth = 7;
+			eastWest = 14;
 			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