[PATCH 3/3] Correctly parse translated cardinal directions

Dirk Hohndel dirk at hohndel.org
Sun Feb 3 11:42:52 PST 2013


Sergey Starosek <sergey.starosek at gmail.com> writes:

> Along with comparing to translated strings, text pointer has to be
> incremented by the length of these strings, not chars.

Your diagnosis is correct, the implementation is wrong. My foolish first
attempt (that assumed that the translated strings would also be just one
char, which is correct in most Western languages but wrong in most
others) still ALSO compares to the more typical single byte chars.

So these comparisons need to be split and the increment needs to be done
accordingly.

> Not sure whether optional minutes parsing logic has to be modified
> since it uses untranslated 'E' and 'W' char constants.

It does. I clearly tried to fix this too quickly - and didn't have a an
easy way to test this with a non-Western language as I can't read any of
them...


/D

> diff --git a/info.c b/info.c
> index 3736d29..5207ef7 100644
> --- a/info.c
> +++ b/info.c
> @@ -403,10 +403,10 @@ static gboolean parse_gps_text(const char *gps_text, double *latitude, double *l
>  	/* ok, let's parse by hand - first degrees of latitude */
>  	if (g_unichar_toupper(g_utf8_get_char(text)) == 'N' ||
>  	    !strncmp(text, _("N"), strlen(_("N"))))
> -		text++;
> +		text+=strlen(_("N"));
>  	if (g_unichar_toupper(g_utf8_get_char(text)) == 'S' ||
>  	    !strncmp(text, _("S"), strlen(_("S")))) {
> -		text++;
> +		text+=strlen(_("S"));
>  		south = TRUE;
>  	}
>  	parselat = strtod(text, &endptr);
> @@ -437,10 +437,10 @@ static gboolean parse_gps_text(const char *gps_text, double *latitude, double *l
>  	/* next degrees of longitude */
>  	if (g_unichar_toupper(g_utf8_get_char(text)) == 'E' ||
>  	    !strncmp(text, _("E"), strlen(_("E"))))
> -		text++;
> +		text+=strlen(_("E"));
>  	if (g_unichar_toupper(g_utf8_get_char(text)) == 'W' ||
>  	    !strncmp(text, _("W"), strlen(_("W")))) {
> -		text++;
> +		text+=strlen(_("W"));
>  		west = TRUE;
>  	}
>  	parselong = strtod(text, &endptr);
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface


More information about the subsurface mailing list