Skip to content

Commit 04de022

Browse files
committed
POSIX::localeconv: Return empty/special values
This function returns a hash allowing Perl access to the localeconv() data structure, with the keys being the structure's field names, and the values being their corresponding value in the current locale. Prior to this commit, it did not populate the hash with: 1) any string-valued keys whose value is the empty string 2) any numeric-valued keys whose value is the special value CHAR_MAX This is wrong. localeconv() should return a complete list of fields on the platform, regardless of their values. Someone may well wish to iterate over all the keys in the hash. CHAR_MAX just indicates special handling is required for that numeric field. And all string fields legally can be empty, except for the decimal point. For example, the symbol indicating a number is positive is empty in many locales. I couldn't find a reason in the history why these have been omitted.
1 parent f42fb42 commit 04de022

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

ext/POSIX/t/posix.t

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,9 @@ SKIP: {
373373
currency_symbol mon_decimal_point mon_thousands_sep
374374
mon_grouping positive_sign negative_sign)) {
375375
SKIP: {
376-
skip("localeconv has no result for $_", 1)
377-
unless exists $conv->{$_};
378-
unlike(delete $conv->{$_}, qr/\A\z/,
379-
"localeconv returned a non-empty string for $_");
376+
my $value = delete $conv->{$_};
377+
skip("localeconv '$_' may be empty", 1) if $_ ne 'decimal_point';
378+
isnt($value, "", "localeconv returned a non-empty string for $_");
380379
}
381380
}
382381

@@ -399,8 +398,6 @@ SKIP: {
399398

400399
foreach (@lconv) {
401400
SKIP: {
402-
skip("localeconv has no result for $_", 1)
403-
unless exists $conv->{$_};
404401
like(delete $conv->{$_}, qr/\A-?\d+\z/,
405402
"localeconv returned an integer for $_");
406403
}

locale.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ S_populate_localeconv(pTHX_ const struct lconv *lcbuf,
34963496

34973497
while (strings->name) {
34983498
const char *value = *((const char **)(ptr + strings->offset));
3499-
if (value && *value) {
3499+
if (value) {
35003500
bool is_utf8 = /* Only make UTF-8 if required to */
35013501
(UTF8NESS_YES == (get_locale_string_utf8ness_i(locale,
35023502
cat_index,
@@ -3516,8 +3516,7 @@ S_populate_localeconv(pTHX_ const struct lconv *lcbuf,
35163516
while (integers->name) {
35173517
const char value = *((const char *)(ptr + integers->offset));
35183518

3519-
if (value != CHAR_MAX)
3520-
(void) hv_store(retval, integers->name,
3519+
(void) hv_store(retval, integers->name,
35213520
strlen(integers->name), newSViv(value), 0);
35223521
integers++;
35233522
}

0 commit comments

Comments
 (0)