summaryrefslogtreecommitdiff
path: root/t/loc_tools.pl
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-03-04 10:45:05 -0700
committerKarl Williamson <khw@cpan.org>2018-03-04 11:53:10 -0700
commit83858d2d408dc98bdf12d8fa5ac20bf69c6bc02f (patch)
tree454b46623706f7ac66f422c2cded8fc1e682d26a /t/loc_tools.pl
parentbaaa1581ffc78898fdc1873d0c5dd97f51e60e4e (diff)
downloadperl-83858d2d408dc98bdf12d8fa5ac20bf69c6bc02f.tar.gz
t/loc_tools.pl: Add fcn to return valid locale cats
This new function will return the locale categories known to this platform.
Diffstat (limited to 't/loc_tools.pl')
-rw-r--r--t/loc_tools.pl25
1 files changed, 20 insertions, 5 deletions
diff --git a/t/loc_tools.pl b/t/loc_tools.pl
index db0bface64..8623e12b90 100644
--- a/t/loc_tools.pl
+++ b/t/loc_tools.pl
@@ -15,6 +15,11 @@ use strict;
eval { require POSIX; import POSIX 'locale_h'; };
my $has_locale_h = ! $@;
+my @known_categories = ( qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY
+ LC_NUMERIC LC_TIME LC_ADDRESS LC_IDENTIFICATION
+ LC_MEASUREMENT LC_PAPER LC_TELEPHONE));
+my @platform_categories;
+
# LC_ALL can be -1 on some platforms. And, in fact the implementors could
# legally use any integer to represent any category. But it makes the most
# sense for them to have used small integers. Below, we create new locale
@@ -30,9 +35,8 @@ my %category_name;
my %category_number;
if ($has_locale_h) {
my $number_for_missing_category = $max_bad_category_number;
- foreach my $name (qw(ALL COLLATE CTYPE MESSAGES MONETARY NUMERIC TIME)) {
- my $number = eval "&POSIX::LC_$name";
-
+ foreach my $name (@known_categories) {
+ my $number = eval "&POSIX::$name";
if ($@) {
# Use a negative number (smaller than any legitimate category
# number) if the platform doesn't support this category, so we
@@ -45,9 +49,13 @@ if ($has_locale_h) {
{
# We think this should be an int. And it has to be larger than
# any of our synthetic numbers.
- die "Unexpected locale category number '$number' for LC_$name"
+ die "Unexpected locale category number '$number' for $name"
+ }
+ else {
+ push @platform_categories, $name;
}
+ $name =~ s/LC_//;
$category_name{$number} = "$name";
$category_number{$name} = $number;
}
@@ -160,6 +168,13 @@ sub _decode_encodings { # For use only by other functions in this file!
return @enc;
}
+sub valid_locale_categories() {
+ # Returns a list of the locale categories (expressed as strings, like
+ # "LC_ALL) known to this program that are available on this platform.
+
+ return @platform_categories;
+}
+
sub locales_enabled(;$) {
# Returns 0 if no locale handling is available on this platform; otherwise
# 1.
@@ -170,7 +185,7 @@ sub locales_enabled(;$) {
# taken to be the C enum for the category (e.g., &POSIX::LC_CTYPE).
# Otherwise it should be a string name of the category, like 'LC_TIME'.
# The initial 'LC_' is optional. It is a fatal error to call this with
- # something that isn't a known category to the platform.
+ # something that isn't a known category to this file.
#
# This optional parameter denotes which POSIX locale categories must be
# available on the platform. If any aren't available, this function