From fad4af7fd1be4672fd916249ef5887768094456c Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 18 Nov 2017 17:34:25 -0700 Subject: [PATCH] Perl_langinfo: Teach about YESSTR and NOSTR 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. --- ext/XS-APItest/t/locale.t | 2 ++ locale.c | 26 ++++++++++++++++++++------ perl_langinfo.h | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ext/XS-APItest/t/locale.t b/ext/XS-APItest/t/locale.t index 6306fea83bab..064627d424d2 100644 --- a/ext/XS-APItest/t/locale.t +++ b/ext/XS-APItest/t/locale.t @@ -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"; diff --git a/locale.c b/locale.c index e85bbe8e5383..05a05ba29ef4 100644 --- a/locale.c +++ b/locale.c @@ -1275,11 +1275,15 @@ Unimplemented, so returns C<"">. =item C +=item C + =item C -Only the values for English are returned. Earlier POSIX standards also -specified C and C, but these have been removed from POSIX 2008, -and aren't supported by C. +=item C + +Only the values for English are returned. C and C have been +removed from POSIX 2008, and are retained for backwards compatibility. Your +platform's C may not support them. =item C @@ -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; @@ -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 @@ -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 diff --git a/perl_langinfo.h b/perl_langinfo.h index a93874f8abd1..cd6eb07de5d4 100644 --- a/perl_langinfo.h +++ b/perl_langinfo.h @@ -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