[PATCH] Make ISO-6709 coordinate regex less restrictive

Dirk Hohndel dirk at hohndel.org
Sun May 25 15:41:17 PDT 2014


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


More information about the subsurface mailing list