[geos-devel] Delocalizing the WKT writer?

sgillies at frii.com sgillies at frii.com
Thu Aug 28 12:43:39 EDT 2008


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()?

capi/geos_c.cpp:

char*
GEOSWKTWriter_write(WKTWriter *writer, const Geometry *geom)
{
    try
	{
                // switch to C locale
                std::setlocale(LC_ALL, "C");
		std::string s = writer->write(geom);

		char *result;
		result = (char*) std::malloc( s.length() + 1);
		std::strcpy(result, s.c_str() );
                // switch back to native locale
                std::setlocale(LC_ALL, "");
		return result;
	}
	catch (const std::exception &e)
	{
		ERROR_MESSAGE("%s", e.what());
		return NULL;
	}

	catch (...)
	{
		ERROR_MESSAGE("Unknown exception thrown");
		return NULL;
	}
}

Sure, it would be nice to work this down into the C++ code, but the
WKTWriter class is a nightmare.

Sean



More information about the geos-devel mailing list