Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cs2cs_emulation_setup: fix issue with non C-locale #1136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pj_utils.c
Expand Up @@ -105,6 +105,8 @@ PJ *pj_latlong_from_proj( PJ *pj_in )
{
char* ptr = defn+strlen(defn);
sprintf( ptr, " +es=%.16g", pj_in->es );
/* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
/* to be locale unaware */
for(; *ptr; ptr++)
{
if( *ptr == ',' )
Expand Down
11 changes: 11 additions & 0 deletions src/proj_4D_api.c
Expand Up @@ -519,6 +519,17 @@ Returns 1 on success, 0 on failure
if (P->is_geocent || P->helmert || do_cart) {
char def[150];
sprintf (def, "break_cs2cs_recursion proj=cart a=%40.20g es=%40.20g", P->a_orig, P->es_orig);
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is stylistically quite different from its surroundings. I would prefer something like this (untested):

if (P->is_geocent || P->helmert || do_cart) {
    char def[150];
    char *next_pos = def;

    sprintf (def, "break_cs2cs_recursion     proj=cart   a=%40.20g  es=%40.20g", P->a_orig, P->es_orig);

    /* In case the current locale does not use dot but comma as decimal */
    /* separator, replace it with dot, so that proj_atof() behaves */
    /* correctly. */
    /* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
    /* to be locale unaware */
    while ( (next_pos =  strchr (next_pos, ',')))
        *next_pos++ = '.';

    ...

or even a for rather than while:

for (next_pos = def; next_pos = strchr (next_pos, ','); next_pos++)
    *next_pos = '.'

Alternatively, we could build comma-dot agnosticism into the alternative proj_strtod in proj_strtod.c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, taken into account

/* In case the current locale does not use dot but comma as decimal */
/* separator, replace it with dot, so that proj_atof() behaves */
/* correctly. */
/* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
/* to be locale unaware */
char* next_pos;
for (next_pos = def; (next_pos = strchr (next_pos, ',')) != NULL; next_pos++) {
*next_pos = '.';
}
}
Q = proj_create (P->ctx, def);
if (0==Q)
return 0;
Expand Down