Here it is. Hopefully now everything is correct. Regards, Jose
2014-05-26 9:20 GMT+02:00 José Carlos Andreu Galán <[email protected]>: > Certainly I'm not an expert at regex. I understand what you say. > I'll resubmit the patch with the changes. Thanks for the advice! > > > 2014-05-26 0:41 GMT+02:00 Dirk Hohndel <[email protected]>: > > On Mon, May 26, 2014 at 12:02:33AM +0200, José Carlos Andreu Galán wrote: >> > 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. >> >> Thanks for that patch! >> I have a quick question - I think you may have made the reg exp more >> complicated than it needs to be... >> >> > 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+)([,\\.] >> >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> that seems silly - why not just " >> (\\d+)[" UTF*_DEGREE "\\s]\\s*(\\d+ >> >> If I'm right I think you could simplify the whole patch (as you no longer >> need those extra groups for the '|'...) >> >> Can you comment and maybe resubmit? >> >> /D >> > >
From 3942b5b4d43e857fb757f35dfc93209d1ab2a7d1 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 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qthelper.cpp b/qthelper.cpp index bcf78b5..a567a7e 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]) @@ -127,11 +128,11 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude) 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; + (r.cap(4) + QString(".") + r.cap(6)).toDouble() / 3600.0; + *longitude = r.cap(9).toInt() + r.cap(10).toInt() / 60.0 + + (r.cap(12) + QString(".") + r.cap(14)).toDouble() / 3600.0; + northSouth = 8; + eastWest = 16; 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
