[geos-devel] Delocalizing the WKT writer?

Frank Warmerdam warmerdam at pobox.com
Thu Aug 28 12:57:32 EDT 2008


On Thu, Aug 28, 2008 at 12:43 PM,  <sgillies at frii.com> wrote:
> Can one of the C++ gurus explain why delocalizing the writer (to fix bug
> 201) isn't as simple as bracing the guts of this function with calls to
> setlocale()?

>                // switch to C locale
>                std::setlocale(LC_ALL, "C");
...
>                // switch back to native locale
>                std::setlocale(LC_ALL, "");

Sean,

This would seem ok to me, except that you need to ensure
you restore the original locale setting, not just blindly set "".
In my CPLLocaleC class from GDAL I do something like this
to reset, and then restore the locale.

    pszOldLocale = strdup(setlocale(LC_NUMERIC,NULL));
    if( setlocale(LC_NUMERIC,"C") == NULL )
        pszOldLocale = NULL;

...

    if( pszOldLocale != NULL )
    {
        setlocale( LC_NUMERIC, pszOldLocale );
        CPLFree( pszOldLocale );
    }

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent


More information about the geos-devel mailing list