diff --git a/locale.c b/locale.c index 0b126262138c..018e4131a4e4 100644 --- a/locale.c +++ b/locale.c @@ -311,6 +311,7 @@ S_get_category_index(const int category, const char * locale) * elements is so far at most 12 */ unsigned int i; + const char * conditional_warn_text = "; can't set it to "; PERL_ARGS_ASSERT_GET_CATEGORY_INDEX; @@ -330,12 +331,16 @@ S_get_category_index(const int category, const char * locale) } /* Here, we don't know about this category, so can't handle it. */ + if (! locale) { - locale = "(unknown)"; + locale = ""; + conditional_warn_text = ""; } + + /* diag_listed_as: Unknown locale category %d; can't set it to %s */ Perl_warner_nocontext(packWARN(WARN_LOCALE), - "Unknown locale category %d; can't set it to %s\n", - category, locale); + "Unknown locale category %d%s%s", + category, conditional_warn_text, locale); /* Return an out-of-bounds value */ return NOMINAL_LC_ALL_INDEX + 1; @@ -344,45 +349,15 @@ S_get_category_index(const int category, const char * locale) STATIC const char * S_category_name(const int category) { - unsigned int i; - -#ifdef LC_ALL + unsigned int index; - if (category == LC_ALL) { - return "LC_ALL"; - } - -#endif + index = get_category_index(category, NULL); - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - if (category == categories[i]) { - return category_names[i]; - } + if (index <= NOMINAL_LC_ALL_INDEX) { + return category_names[index]; } - { - const char suffix[] = " (unknown)"; - int temp = category; - Size_t length = sizeof(suffix) + 1; - char * unknown; - dTHX; - - if (temp < 0) { - length++; - temp = - temp; - } - - /* Calculate the number of digits */ - while (temp >= 10) { - temp /= 10; - length++; - } - - Newx(unknown, length, char); - my_snprintf(unknown, length, "%d%s", category, suffix); - SAVEFREEPV(unknown); - return unknown; - } + return Perl_form_nocontext("%d (unknown)", category); } #endif /* ifdef USE_LOCALE */ diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 10dc400639eb..03e121cfbb8a 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -764,15 +764,11 @@ diagnostic messages, see L. =item * -L +L -This accompanies the new L feature. - -=item * - -L - -This accompanies the new L feature. +This is a shortened form of an already existing diagnostic, for use when +there is no new locale being switched to. The previous diagnostic was +misleading in such circumstances. =back diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 88df9485059e..102751afd7af 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -6804,6 +6804,8 @@ compiler does not recognize. Check your spelling. (P) Perl was about to print an error message in C<$@>, but the C<$@> variable did not exist, even after an attempt to create it. +=item Unknown locale category %d + =item Unknown locale category %d; can't set it to %s (W locale) You used a locale category that perl doesn't recognize, so it