In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/07dfe0a4c8603f73b447c48b9b91a04d8fb8962b?hp=bee74f4b9818f0ca72926dd6b4dfdbc6b75c59ef>
- Log ----------------------------------------------------------------- commit 07dfe0a4c8603f73b447c48b9b91a04d8fb8962b Author: Karl Williamson <[email protected]> Date: Sun Mar 4 10:57:16 2018 -0700 perlapi: utf8_to_uvuni_buf() Add clarification commit 0945d17558ba1cd9ec9357106db73d9b4c0a9009 Author: Karl Williamson <[email protected]> Date: Sun Mar 4 10:47:08 2018 -0700 t/run/locale.t: Add, revise tests This enhances the test added in bee74f4b9818f0ca72926dd6b4dfdbc6b75c59ef so that it is doing a valid setlocale, and adds a similar test for doing an invalid one. commit 83858d2d408dc98bdf12d8fa5ac20bf69c6bc02f Author: Karl Williamson <[email protected]> Date: Sun Mar 4 10:45:05 2018 -0700 t/loc_tools.pl: Add fcn to return valid locale cats This new function will return the locale categories known to this platform. commit baaa1581ffc78898fdc1873d0c5dd97f51e60e4e Author: Karl Williamson <[email protected]> Date: Sun Mar 4 10:43:03 2018 -0700 t/run/locale.t: Update skip count This should have been updated by bee74f4b9818f0ca72926dd6b4dfdbc6b75c59ef. ----------------------------------------------------------------------- Summary of changes: t/loc_tools.pl | 25 ++++++++++++++++++++----- t/run/locale.t | 45 +++++++++++++++++++++++++++++++++++---------- utf8.c | 4 +++- 3 files changed, 58 insertions(+), 16 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 diff --git a/t/run/locale.t b/t/run/locale.t index cec5b31c68..f1bb6f2ee5 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -118,7 +118,7 @@ SKIP: { } SKIP: { - skip("no locale available where LC_NUMERIC makes a difference", &last - 7 ) + skip("no locale available where LC_NUMERIC makes a difference", &last - 9 ) if !$different; # -7 is 5 tests before this block; 2 after note("using the '$different' locale for LC_NUMERIC tests"); { @@ -427,18 +427,43 @@ EOF } - { - fresh_perl(<<"EOF", - use locale; - use POSIX; - POSIX::setlocale(LC_ALL, "LC_NUMERIC=de_DE.utf8;LC_CTYPE=de_DE.utf8;LC_COLLATE=de_DE.utf8;LC_TIME=de_DE.utf8;LC_MESSAGES=de_DE.utf8;LC_MONETARY=de_DE.utf8;LC_ADDRESS=de_DE.utf8;LC_IDENTIFICATION=de_DE.utf8;LC_MEASUREMENT=de_DE.utf8;LC_PAPER=de_DE.utf8;LC_TELEPHONE=de_DE.utf8"); -EOF - {}); - ok ($? == 0, "In complicated LC_ALL, final individ category doesn't need a \';'"); +SKIP: { + my @valid_categories = valid_locale_categories(); + + my $valid_string = ""; + my $invalid_string = ""; + + foreach my $category (@valid_categories) { + if ($category ne "LC_ALL") { + $invalid_string .= ";" if $invalid_string ne ""; + $invalid_string .= "$category=foo_BAR"; + + $valid_string .= ";" if $valid_string ne ""; + $valid_string .= "$category=$non_C_locale"; + } } + fresh_perl(<<"EOF", + use locale; + use POSIX; + POSIX::setlocale(LC_ALL, "$invalid_string"); +EOF + {}); + is ($?, 0, "In setting complicated invalid LC_ALL, final individ category doesn't need a \';'"); + + skip("no non-C locale available", 2 ) unless $non_C_locale; + fresh_perl(<<"EOF", + use locale; + use POSIX; + POSIX::setlocale(LC_ALL, "$valid_string"); +EOF + {}); + is ($?, 0, "In setting complicated valid LC_ALL, final individ category doesn't need a \';'"); + +} + # IMPORTANT: When adding tests before the following line, be sure to update # its skip count: # skip("no locale available where LC_NUMERIC makes a difference", ...) -sub last { 38 } +sub last { 39 } diff --git a/utf8.c b/utf8.c index a30182a43f..eede51e13b 100644 --- a/utf8.c +++ b/utf8.c @@ -2329,7 +2329,9 @@ Perl_utf8_to_uvchr_buf(pTHX_ const U8 *s, const U8 *send, STRLEN *retlen) Only in very rare circumstances should code need to be dealing in Unicode (as opposed to native) code points. In those few cases, use -C<L<NATIVE_TO_UNI(utf8_to_uvchr_buf(...))|/utf8_to_uvchr_buf>> instead. +C<L<NATIVE_TO_UNI(utf8_to_uvchr_buf(...))|/utf8_to_uvchr_buf>> instead. If you +are not absolutely sure this is one of those cases, then assume it isn't and +use plain C<utf8_to_uvchr_buf> instead. Returns the Unicode (not-native) code point of the first character in the string C<s> which -- Perl5 Master Repository
