Update Locale::Codes to 3.12
[p5sagit/p5-mst-13.2.git] / cpan / Locale-Codes / lib / Locale / Script.pm
CommitLineData
6b6e008c 1package Locale::Script;
f768f60b 2# Copyright (C) 2001 Canon Research Centre Europe (CRE).
3# Copyright (C) 2002-2009 Neil Bowers
4# Copyright (c) 2010-2010 Sullivan Beck
5# This program is free software; you can redistribute it and/or modify it
6# under the same terms as Perl itself.
7
6b6e008c 8use strict;
f768f60b 9use warnings;
6b6e008c 10require 5.002;
11
6b6e008c 12require Exporter;
13use Carp;
f768f60b 14use Locale::Codes;
6b6e008c 15use Locale::Constants;
f768f60b 16use Locale::Codes::Script;
6b6e008c 17
f768f60b 18#=======================================================================
19# Public Global Variables
20#=======================================================================
6b6e008c 21
6b6e008c 22use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
f768f60b 23
24$VERSION='3.12';
6b6e008c 25@ISA = qw(Exporter);
f768f60b 26@EXPORT = qw(code2script
27 script2code
28 all_script_codes
29 all_script_names
30 script_code2code
31 LOCALE_SCRIPT_ALPHA
32 LOCALE_SCRIPT_NUMERIC
33 );
34
35sub _code {
36 my($code,$codeset) = @_;
37 $code = "" if (! $code);
38
39 $codeset = LOCALE_SCRIPT_DEFAULT if (! defined($codeset) || $codeset eq "");
40
41 if ($codeset =~ /^\d+$/) {
42 if ($codeset == LOCALE_SCRIPT_ALPHA) {
43 $codeset = "alpha";
44 } elsif ($codeset == LOCALE_SCRIPT_NUMERIC) {
45 $codeset = "num";
46 } else {
47 return (1);
48 }
49 }
50
51 if ($codeset eq "alpha") {
52 $code = ucfirst(lc($code));
53 } elsif ($codeset eq "num") {
54 if (defined($code) && $code ne "") {
55 return (1) unless ($code =~ /^\d+$/);
56 $code = sprintf("%.3d", $code);
57 }
58 } else {
59 return (1);
60 }
61
62 return (0,$code,$codeset);
63}
64
65#=======================================================================
66#
67# code2script ( CODE [,CODESET] )
68#
69#=======================================================================
6b6e008c 70
f768f60b 71sub code2script {
72 my($err,$code,$codeset) = _code(@_);
73 return undef if ($err ||
74 ! defined $code);
6b6e008c 75
f768f60b 76 return Locale::Codes::_code2name("script",$code,$codeset);
77}
6b6e008c 78
79#=======================================================================
6b14ceb7 80#
f768f60b 81# script2code ( SCRIPT [,CODESET] )
6b14ceb7 82#
6b6e008c 83#=======================================================================
f768f60b 84
85sub script2code {
86 my($script,$codeset) = @_;
87 my($err,$tmp);
88 ($err,$tmp,$codeset) = _code("",$codeset);
89 return undef if ($err ||
90 ! defined $script);
91
92 return Locale::Codes::_name2code("script",$script,$codeset);
6b6e008c 93}
94
f768f60b 95#=======================================================================
96#
97# script_code2code ( CODE,CODESET_IN,CODESET_OUT )
98#
99#=======================================================================
100
101sub script_code2code {
102 (@_ == 3) or croak "script_code2code() takes 3 arguments!";
103 my($code,$inset,$outset) = @_;
104 my($err,$tmp);
105 ($err,$code,$inset) = _code($code,$inset);
106 return undef if ($err);
107 ($err,$tmp,$outset) = _code("",$outset);
108 return undef if ($err);
109
110 return Locale::Codes::_code2code("script",$code,$inset,$outset);
111}
6b14ceb7 112
113#=======================================================================
114#
f768f60b 115# all_script_codes ( [CODESET] )
6b14ceb7 116#
117#=======================================================================
f768f60b 118
119sub all_script_codes {
120 my($codeset) = @_;
121 my($err,$tmp);
122 ($err,$tmp,$codeset) = _code("",$codeset);
123 return undef if ($err);
124
125 return Locale::Codes::_all_codes("script",$codeset);
6b6e008c 126}
127
6b14ceb7 128
129#=======================================================================
130#
f768f60b 131# all_script_names ( [CODESET] )
6b14ceb7 132#
133#=======================================================================
f768f60b 134
135sub all_script_names {
136 my($codeset) = @_;
137 my($err,$tmp);
138 ($err,$tmp,$codeset) = _code("",$codeset);
139 return undef if ($err);
140
141 return Locale::Codes::_all_names("script",$codeset);
6b6e008c 142}
143
f768f60b 144#=======================================================================
145#
146# rename_script ( CODE,NAME [,CODESET] )
147#
148#=======================================================================
149
150sub rename_script {
151 my($code,$new_name,@args) = @_;
152 my $nowarn = 0;
153 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
154 my $codeset = shift(@args);
155 my $err;
156 ($err,$code,$codeset) = _code($code,$codeset);
157
158 return Locale::Codes::_rename("script",$code,$new_name,$codeset,$nowarn);
159}
6b6e008c 160
161#=======================================================================
6b14ceb7 162#
f768f60b 163# add_script ( CODE,NAME [,CODESET] )
6b14ceb7 164#
165#=======================================================================
6b6e008c 166
f768f60b 167sub add_script {
168 my($code,$name,@args) = @_;
169 my $nowarn = 0;
170 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
171 my $codeset = shift(@args);
172 my $err;
173 ($err,$code,$codeset) = _code($code,$codeset);
174
175 return Locale::Codes::_add_code("script",$code,$name,$codeset,$nowarn);
6b6e008c 176}
177
f768f60b 178#=======================================================================
179#
180# delete_script ( CODE [,CODESET] )
181#
182#=======================================================================
183
184sub delete_script {
185 my($code,@args) = @_;
186 my $nowarn = 0;
187 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
188 my $codeset = shift(@args);
189 my $err;
190 ($err,$code,$codeset) = _code($code,$codeset);
191
192 return Locale::Codes::_delete_code("script",$code,$codeset,$nowarn);
193}
6b14ceb7 194
195#=======================================================================
196#
f768f60b 197# add_script_alias ( NAME,NEW_NAME )
6b14ceb7 198#
199#=======================================================================
6b6e008c 200
f768f60b 201sub add_script_alias {
202 my($name,$new_name,$nowarn) = @_;
203 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
204
205 return Locale::Codes::_add_alias("script",$name,$new_name,$nowarn);
6b6e008c 206}
207
f768f60b 208#=======================================================================
209#
210# delete_script_alias ( NAME )
211#
212#=======================================================================
213
214sub delete_script_alias {
215 my($name,$nowarn) = @_;
216 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
217
218 return Locale::Codes::_delete_alias("script",$name,$nowarn);
219}
6b6e008c 220
6b6e008c 221#=======================================================================
6b14ceb7 222#
f768f60b 223# rename_script_code ( CODE,NEW_CODE [,CODESET] )
6b14ceb7 224#
6b6e008c 225#=======================================================================
6b6e008c 226
f768f60b 227sub rename_script_code {
228 my($code,$new_code,@args) = @_;
229 my $nowarn = 0;
230 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
231 my $codeset = shift(@args);
232 my $err;
233 ($err,$code,$codeset) = _code($code,$codeset);
234 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
356373a2 235
f768f60b 236 return Locale::Codes::_rename_code("script",$code,$new_code,$codeset,$nowarn);
237}
6b6e008c 238
f768f60b 239#=======================================================================
240#
241# add_script_code_alias ( CODE,NEW_CODE [,CODESET] )
242#
243#=======================================================================
6b6e008c 244
f768f60b 245sub add_script_code_alias {
246 my($code,$new_code,@args) = @_;
247 my $nowarn = 0;
248 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
249 my $codeset = shift(@args);
250 my $err;
251 ($err,$code,$codeset) = _code($code,$codeset);
252 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
6b6e008c 253
f768f60b 254 return Locale::Codes::_add_code_alias("script",$code,$new_code,$codeset,$nowarn);
255}
6b6e008c 256
f768f60b 257#=======================================================================
258#
259# delete_script_code_alias ( CODE [,CODESET] )
260#
261#=======================================================================
262
263sub delete_script_code_alias {
264 my($code,@args) = @_;
265 my $nowarn = 0;
266 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
267 my $codeset = shift(@args);
268 my $err;
269 ($err,$code,$codeset) = _code($code,$codeset);
3a6b268d 270
f768f60b 271 return Locale::Codes::_delete_code_alias("script",$code,$codeset,$nowarn);
6b6e008c 272}
273
2741;
f768f60b 275# Local Variables:
276# mode: cperl
277# indent-tabs-mode: nil
278# cperl-indent-level: 3
279# cperl-continued-statement-offset: 2
280# cperl-continued-brace-offset: 0
281# cperl-brace-offset: 0
282# cperl-brace-imaginary-offset: 0
283# cperl-label-offset: -2
284# End: