This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Add comment
[perl5.git] / lib / locale.pm
CommitLineData
bbce6d69 1package locale;
2
a02ae656 3our $VERSION = '1.03';
569f7fc5 4use Config;
b75c8c73 5
66cbab2c
KW
6$Carp::Internal{ (__PACKAGE__) } = 1;
7
bbce6d69 8=head1 NAME
9
f36a3959 10locale - Perl pragma to use or avoid POSIX locales for built-in operations
bbce6d69 11
12=head1 SYNOPSIS
13
465d77f9 14 @x = sort @y; # Native-platform/Unicode code point sort order
bbce6d69 15 {
16 use locale;
465d77f9 17 @x = sort @y; # Locale-defined sort order
bbce6d69 18 }
465d77f9
KW
19 @x = sort @y; # Native-platform/Unicode code point sort order
20 # again
bbce6d69 21
22=head1 DESCRIPTION
23
24This pragma tells the compiler to enable (or disable) the use of POSIX
f36a3959
KW
25locales for built-in operations (for example, LC_CTYPE for regular
26expressions, LC_COLLATE for string comparison, and LC_NUMERIC for number
27formatting). Each "use locale" or "no locale"
bbce6d69 28affects statements to the end of the enclosing BLOCK.
29
b8bc843f
A
30See L<perllocale> for more detailed information on how Perl supports
31locales.
32
a02ae656
KW
33On systems that don't have locales, this pragma will cause your operations
34to behave as if in the "C" locale; attempts to change the locale will fail.
569f7fc5 35
bbce6d69 36=cut
37
66cbab2c
KW
38# A separate bit is used for each of the two forms of the pragma, as they are
39# mostly independent, and interact with each other and the unicode_strings
40# feature. This allows for fast determination of which one(s) of the three
41# are to be used at any given point, and no code has to be written to deal
42# with coming in and out of scopes--it falls automatically out from the hint
43# handling
44
2de3dbcc 45$locale::hint_bits = 0x4;
66cbab2c 46$locale::not_chars_hint_bits = 0x10;
d5448623 47
bbce6d69 48sub import {
66cbab2c 49 shift; # should be 'locale'; not checked
569f7fc5 50
66cbab2c
KW
51 my $found_not_chars = 0;
52 while (defined (my $arg = shift)) {
53 if ($arg eq ":not_characters") {
54 $^H |= $locale::not_chars_hint_bits;
55
56 # This form of the pragma overrides the other
57 $^H &= ~$locale::hint_bits;
58 $found_not_chars = 1;
59 }
60 else {
61 require Carp;
62 Carp::croak("Unknown parameter '$arg' to 'use locale'");
63 }
64 }
65
66 # Use the plain form if not doing the :not_characters one.
67 $^H |= $locale::hint_bits unless $found_not_chars;
bbce6d69 68}
69
70sub unimport {
66cbab2c 71 $^H &= ~($locale::hint_bits|$locale::not_chars_hint_bits);
bbce6d69 72}
73
741;