Skip to content

Commit

Permalink
locale.c: Fix currency symbol derivation
Browse files Browse the repository at this point in the history
On platforms without nl_langinfo(), we derive the currency symbol from
localeconv().  The symbol must be tweaked to conform to nl_langinfo()
standards.  Prior to this commit, it guessed at how to tweak a rare
circumstance.  I found evidence this guess was wrong, so looked around,
and copied the way cygwin does it.

This also no longer returns just an empty string in certain cases.
nl_langinfo() itself doesn't, so conform to that.
  • Loading branch information
khwilliamson committed Apr 29, 2021
1 parent e647b0a commit 725c75e
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions locale.c
Expand Up @@ -3105,28 +3105,21 @@ S_my_langinfo(const nl_item item, bool toggle)

lc = localeconv();

if ( ! lc
|| ! lc->currency_symbol
|| strEQ("", lc->currency_symbol))
{
LOCALECONV_UNLOCK;
return "";
}
const char * currency = (lc && lc->currency_symbol)
? lc->currency_symbol
: "";
char precedes = (lc->p_cs_precedes)
/* khw couldn't find any documentation that
* CHAR_MAX is the signal, but cygwin uses it
* thusly */
? ((lc->p_cs_precedes == CHAR_MAX)
? '.' : '-')
: '+';
break;

/* Leave the first spot empty to be filled in below */
retval = save_to_buffer(lc->currency_symbol, &PL_langinfo_buf,
&PL_langinfo_bufsize, 1);
if (lc->mon_decimal_point && strEQ(lc->mon_decimal_point, ""))
{ /* khw couldn't figure out how the localedef specifications
would show that the $ should replace the radix; this is
just a guess as to how it might work.*/
PL_langinfo_buf[0] = '.';
}
else if (lc->p_cs_precedes) {
PL_langinfo_buf[0] = '-';
}
else {
PL_langinfo_buf[0] = '+';
retval = save_to_buffer(Perl_form(aTHX_ "%c%s", precedes, currency),
&PL_langinfo_buf, &PL_langinfo_bufsize, 0);
}

# ifdef TS_W32_BROKEN_LOCALECONV
Expand Down

0 comments on commit 725c75e

Please sign in to comment.