Skip to content

Commit

Permalink
Perl_langinfo: Teach about YESSTR and NOSTR
Browse files Browse the repository at this point in the history
These are items that nl_langinfo() used to be required to return, but
are considered obsolete.  Nonetheless, this drop-in replacement for that
function should know about them for backward compatibility.
  • Loading branch information
khwilliamson committed Jan 13, 2018
1 parent 79f6951 commit fad4af7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ext/XS-APItest/t/locale.t
Expand Up @@ -83,12 +83,14 @@ my %correct_C_responses = (
MON_8 => 'August',
MON_9 => 'September',
NOEXPR => undef,
NOSTR => undef,
PM_STR => 'PM',
RADIXCHAR => '.',
THOUSEP => '',
T_FMT => undef,
T_FMT_AMPM => undef,
YESEXPR => undef,
YESSTR => undef,
);

my $hdr = "../../perl_langinfo.h";
Expand Down
26 changes: 20 additions & 6 deletions locale.c
Expand Up @@ -1275,11 +1275,15 @@ Unimplemented, so returns C<"">.
=item C<YESEXPR>
=item C<YESSTR>
=item C<NOEXPR>
Only the values for English are returned. Earlier POSIX standards also
specified C<YESSTR> and C<NOSTR>, but these have been removed from POSIX 2008,
and aren't supported by C<Perl_langinfo>.
=item C<NOSTR>
Only the values for English are returned. C<YESSTR> and C<NOSTR> have been
removed from POSIX 2008, and are retained for backwards compatibility. Your
platform's C<nl_langinfo> may not support them.
=item C<D_FMT>
Expand Down Expand Up @@ -1409,8 +1413,6 @@ S_my_nl_langinfo(const int item, bool toggle)

LOCALE_UNLOCK;

return PL_langinfo_buf;

# else /* Use nl_langinfo_l(), avoiding both a mutex and changing the locale */

bool do_free = FALSE;
Expand All @@ -1434,9 +1436,19 @@ S_my_nl_langinfo(const int item, bool toggle)
freelocale(cur);
}

# endif

if (strEQ(PL_langinfo_buf, "")) {
if (item == PERL_YESSTR) {
return "yes";
}
if (item == PERL_NOSTR) {
return "no";
}
}

return PL_langinfo_buf;

# endif
#else /* Below, emulate nl_langinfo as best we can */
# ifdef HAS_LOCALECONV

Expand Down Expand Up @@ -1472,7 +1484,9 @@ S_my_nl_langinfo(const int item, bool toggle)

/* We use only an English set, since we don't know any more */
case PERL_YESEXPR: return "^[+1yY]";
case PERL_YESSTR: return "yes";
case PERL_NOEXPR: return "^[-0nN]";
case PERL_NOSTR: return "no";

# ifdef HAS_LOCALECONV

Expand Down
14 changes: 12 additions & 2 deletions perl_langinfo.h
Expand Up @@ -283,15 +283,25 @@
#else
# define PERL_YESEXPR -53
#endif
#ifdef YESSTR
# define PERL_YESSTR YESSTR
#else
# define PERL_YESSTR -54
#endif
#ifdef NOEXPR
# define PERL_NOEXPR NOEXPR
#else
# define PERL_NOEXPR -54
# define PERL_NOEXPR -55
#endif
#ifdef NOSTR
# define PERL_NOSTR NOSTR
#else
# define PERL_NOSTR -56
#endif
#ifdef CRNCYSTR
# define PERL_CRNCYSTR CRNCYSTR
#else
# define PERL_CRNCYSTR -55
# define PERL_CRNCYSTR -57
#endif

#endif

0 comments on commit fad4af7

Please sign in to comment.