[geos-devel] Delocalizing the WKT writer?
sgillies at frii.com
sgillies at frii.com
Thu Aug 28 13:08:06 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,
Thanks, Frank. Indeed, the writer could be used in the context of another
app that manipulates the locale.
Sean
More information about the geos-devel
mailing list