From: Jarkko Hietaniemi Date: Thu, 30 Jul 1998 00:39:30 +0000 (+0300) Subject: Re: [PATCH] 5.004_05-MAINT_TRIAL_5: three locale fixes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=502a173a8c3e53b1538fe058ed5270cb83ccfb93;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] 5.004_05-MAINT_TRIAL_5: three locale fixes Message-Id: <199807292139.AAA01795@alpha.hut.fi> p4raw-id: //depot/maint-5.005/perl@1686 --- diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 3c52a28..6958c00 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -2956,7 +2956,6 @@ localeconv() #ifdef HAS_LOCALECONV struct lconv *lcbuf; RETVAL = newHV(); - SET_NUMERIC_LOCAL(); if (lcbuf = localeconv()) { /* the strings */ if (lcbuf->decimal_point && *lcbuf->decimal_point) diff --git a/pod/perllocale.pod b/pod/perllocale.pod index a3e3998..4401be2 100644 --- a/pod/perllocale.pod +++ b/pod/perllocale.pod @@ -169,15 +169,23 @@ combination of language, country or territory, and codeset. Read on for hints on the naming of locales: not all systems name locales as in the example. -If no second argument is provided, the function returns a string naming -the current locale for the category. You can use this value as the -second argument in a subsequent call to setlocale(). If a second -argument is given and it corresponds to a valid locale, the locale for -the category is set to that value, and the function returns the -now-current locale value. You can then use this in yet another call to -setlocale(). (In some implementations, the return value may sometimes -differ from the value you gave as the second argument--think of it as -an alias for the value you gave.) +If no second argument is provided and the category is something else +than LC_ALL, the function returns a string naming the current locale +for the category. You can use this value as the second argument in a +subsequent call to setlocale(). + +If no second argument is provided and the category is LC_ALL, the +result is implementation-dependent. It may be a string of +concatenated locales names (separator also implementation-dependent) +or a single locale name. Please consult your L for +details. + +If a second argument is given and it corresponds to a valid locale, +the locale for the category is set to that value, and the function +returns the now-current locale value. You can then use this in yet +another call to setlocale(). (In some implementations, the return +value may sometimes differ from the value you gave as the second +argument--think of it as an alias for the value you gave.) As the example shows, if the second argument is an empty string, the category's locale is returned to the default specified by the @@ -210,10 +218,12 @@ I section). If that fails, try the following command lines: and see whether they list something resembling these en_US.ISO8859-1 de_DE.ISO8859-1 ru_RU.ISO8859-5 + en_US.iso88591 de_DE.iso88591 ru_RU.iso88595 en_US de_DE ru_RU en de ru english german russian english.iso88591 german.iso88591 russian.iso88595 + english.roman8 russian.koi8r Sadly, even though the calling interface for setlocale() has been standardized, names of locales and the directories where the @@ -368,11 +378,12 @@ with a single parameter--see L.) localeconv() takes no arguments, and returns B a hash. The keys of this hash are variable names for formatting, such as -C and C. The values are the corresponding, -er, values. See L for a longer example listing -the categories an implementation might be expected to provide; some -provide more and others fewer, however. You don't need an explicit C, because localeconv() always observes the current locale. +C and C. The values are the +corresponding, er, values. See L for a longer +example listing the categories an implementation might be expected to +provide; some provide more and others fewer. You don't need an +explicit C, because localeconv() always observes the +current locale. Here's a simple-minded example program that rewrites its command-line parameters as integers correctly formatted in the current locale: @@ -387,13 +398,29 @@ parameters as integers correctly formatted in the current locale: # Apply defaults if values are missing $thousands_sep = ',' unless $thousands_sep; - $grouping = 3 unless $grouping; + + # grouping and mon_grouping are packed lists + # of small integers (characters) telling the + # grouping (thousand_seps and mon_thousand_seps + # being the group dividers) of numbers and + # monetary quantities. The integers' meanings: + # 255 means no more grouping, 0 means repeat + # the previous grouping, 1-254 means use that + # as the current grouping. Grouping goes from + # right to left (low to high digits). In the + # below we cheat slightly by never using anything + # else than the first grouping (whatever that is). + if ($grouping) { + @grouping = unpack("C*", $grouping); + } else { + @grouping = (3); + } # Format command line params for current locale for (@ARGV) { $_ = int; # Chop non-integer part 1 while - s/(\d)(\d{$grouping}($|$thousands_sep))/$1$thousands_sep$2/; + s/(\d)(\d{$grouping[0]}($|$thousands_sep))/$1$thousands_sep$2/; print "$_"; } print "\n";