| 1 | package Encode::Alias; | ||||||||||||||||||||||||||||||||||||
| 2 | 69 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 69 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 69 | our $VERSION = '2.26'; | |||||||||||||||||||||||||||||||||||
| 5 | 69 | ▶ | use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG}; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 69 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | # Public, encouraged API is exported by default | ||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 69 | our @EXPORT = | |||||||||||||||||||||||||||||||||||
| 12 | qw ( | ||||||||||||||||||||||||||||||||||||
| 13 | define_alias | ||||||||||||||||||||||||||||||||||||
| 14 | find_alias | ||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 69 | our @Alias; # ordered matching list | |||||||||||||||||||||||||||||||||||
| 18 | 69 | our %Alias; # cached known aliases | |||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | 3935 | ▶ | sub find_alias { | ||||||||||||||||||||||||||||||||||
|
Subroutine
find_alias: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 21 | 3935 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 22 | 3935 | my $find = shift; | |||||||||||||||||||||||||||||||||||
| 23 | 3935 | ▶ | unless ( exists $Alias{$find} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 24 | 1327 | $Alias{$find} = undef; # Recursion guard | |||||||||||||||||||||||||||||||||||
| 25 | 1327 | ▶ | for ( my $i = 0 ; $i < @Alias ; $i += 2 ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 26 | 43509 | my $alias = $Alias[$i]; | |||||||||||||||||||||||||||||||||||
| 27 | 43509 | my $val = $Alias[ $i + 1 ]; | |||||||||||||||||||||||||||||||||||
| 28 | 43509 | my $new; | |||||||||||||||||||||||||||||||||||
| 29 | 43509 | ▶ | if ( ref($alias) eq 'Regexp' && $find =~ $alias ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
ref $alias eq "Regexp" and $find =~ /$alias/i
MC/DC100%2/2
ref $alias eq "Regexp" and $find =~ /$alias/i
ref $alias eq "Regexp"
$find =~ /$alias/i
Truth table100%3/3
A and B
A= ref $alias eq "Regexp"B= $find =~ /$alias/i
| |||||||||||||||||||||||||||||||||||||
| 30 | 1005 | DEBUG and warn "eval $val"; | |||||||||||||||||||||||||||||||||||
| 31 | 1005 | $new = eval $val; | |||||||||||||||||||||||||||||||||||
| 32 | 1005 | DEBUG and $@ and warn "$val, $@"; | |||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||
| 34 | elsif ( ref($alias) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||
| 35 | 11 | DEBUG and warn "$alias", "->", "($find)"; | |||||||||||||||||||||||||||||||||||
| 36 | 11 | $new = $alias->($find); | |||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||
| 38 | elsif ( lc($find) eq lc($alias) ) { | ||||||||||||||||||||||||||||||||||||
| 39 | 30 | $new = $val; | |||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||
| 41 | 43509 | ▶ | if ( defined($new) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 42 | 1046 | ▶ | next if $new eq $find; # avoid (direct) recursion on bugs | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 43 | 921 | DEBUG and warn "$alias, $new"; | |||||||||||||||||||||||||||||||||||
| 44 | 921 | ▶ | my $enc = | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 45 | ( ref($new) ) ? $new : Encode::find_encoding($new); | ||||||||||||||||||||||||||||||||||||
| 46 | 921 | ▶ | if ($enc) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 47 | 913 | $Alias{$find} = $enc; | |||||||||||||||||||||||||||||||||||
| 48 | 913 | last; | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | # case insensitive search when canonical is not in all lowercase | ||||||||||||||||||||||||||||||||||||
| 54 | # RT ticket #7835 | ||||||||||||||||||||||||||||||||||||
| 55 | 1327 | ▶ | unless ( $Alias{$find} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 56 | 414 | my $lcfind = lc($find); | |||||||||||||||||||||||||||||||||||
| 57 | 414 | for my $name ( keys %Encode::Encoding, keys %Encode::ExtModule ) | |||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||
| 59 | 90366 | ▶ | $lcfind eq lc($name) or next; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 60 | 60 | $Alias{$find} = Encode::find_encoding($name); | |||||||||||||||||||||||||||||||||||
| 61 | 60 | DEBUG and warn "$find => $name"; | |||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||
| 65 | 3935 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||
| 66 | my $name; | ||||||||||||||||||||||||||||||||||||
| 67 | if ( my $e = $Alias{$find} ) { | ||||||||||||||||||||||||||||||||||||
| 68 | $name = $e->name; | ||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||
| 71 | $name = ""; | ||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||
| 73 | warn "find_alias($class, $find)->name = $name"; | ||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||
| 75 | 3935 | return $Alias{$find}; | |||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 3667 | ▶ | sub define_alias { | ||||||||||||||||||||||||||||||||||
|
Subroutine
define_alias: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 79 | 3667 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 80 | 4301 | my $alias = shift; | |||||||||||||||||||||||||||||||||||
| 81 | 4301 | my $name = shift; | |||||||||||||||||||||||||||||||||||
| 82 | 4301 | ▶ | unshift( @Alias, $alias => $name ) # newer one has precedence | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 83 | if defined $alias; | ||||||||||||||||||||||||||||||||||||
| 84 | 4301 | ▶ | if ( ref($alias) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | # clear %Alias cache to allow overrides | ||||||||||||||||||||||||||||||||||||
| 87 | 3506 | my @a = keys %Alias; | |||||||||||||||||||||||||||||||||||
| 88 | 3506 | for my $k (@a) { | |||||||||||||||||||||||||||||||||||
| 89 | 2246 | ▶ | if ( ref($alias) eq 'Regexp' && $k =~ $alias ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $alias eq "Regexp" and $k =~ /$alias/
MC/DC100%2/2
ref $alias eq "Regexp" and $k =~ /$alias/
ref $alias eq "Regexp"
$k =~ /$alias/
Truth table100%3/3
A and B
A= ref $alias eq "Regexp"B= $k =~ /$alias/
| |||||||||||||||||||||||||||||||||||||
| 90 | 32 | DEBUG and warn "delete \$Alias\{$k\}"; | |||||||||||||||||||||||||||||||||||
| 91 | 32 | delete $Alias{$k}; | |||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||
| 93 | ▶ | elsif ( ref($alias) eq 'CODE' && $alias->($k) ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $alias eq "CODE" and &$alias($k)
MC/DC50%1/2
ref $alias eq "CODE" and &$alias($k)
ref $alias eq "CODE"
&$alias($k)
Truth table66%2/3
A and B
A= ref $alias eq "CODE"B= &$alias($k)
| |||||||||||||||||||||||||||||||||||||
| 94 | 359 | DEBUG and warn "delete \$Alias\{$k\}"; | |||||||||||||||||||||||||||||||||||
| 95 | 359 | delete $Alias{$k}; | |||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||
| 99 | elsif (defined $alias) { | ||||||||||||||||||||||||||||||||||||
| 100 | 795 | DEBUG and warn "delete \$Alias\{$alias\}"; | |||||||||||||||||||||||||||||||||||
| 101 | 795 | delete $Alias{$alias}; | |||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||
| 103 | elsif (DEBUG) { | ||||||||||||||||||||||||||||||||||||
| 104 | require Carp; | ||||||||||||||||||||||||||||||||||||
| 105 | Carp::croak("undef \$alias"); | ||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | # HACK: Encode must be used after define_alias is declarated as Encode calls define_alias | ||||||||||||||||||||||||||||||||||||
| 111 | 69 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | # Allow latin-1 style names as well | ||||||||||||||||||||||||||||||||||||
| 114 | # 0 1 2 3 4 5 6 7 8 9 10 | ||||||||||||||||||||||||||||||||||||
| 115 | 69 | our @Latin2iso = ( 0, 1, 2, 3, 4, 9, 10, 13, 14, 15, 16 ); | |||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||
| 117 | # Allow winlatin1 style names as well | ||||||||||||||||||||||||||||||||||||
| 118 | 69 | our %Winlatin2cp = ( | |||||||||||||||||||||||||||||||||||
| 119 | 'latin1' => 1252, | ||||||||||||||||||||||||||||||||||||
| 120 | 'latin2' => 1250, | ||||||||||||||||||||||||||||||||||||
| 121 | 'cyrillic' => 1251, | ||||||||||||||||||||||||||||||||||||
| 122 | 'greek' => 1253, | ||||||||||||||||||||||||||||||||||||
| 123 | 'turkish' => 1254, | ||||||||||||||||||||||||||||||||||||
| 124 | 'hebrew' => 1255, | ||||||||||||||||||||||||||||||||||||
| 125 | 'arabic' => 1256, | ||||||||||||||||||||||||||||||||||||
| 126 | 'baltic' => 1257, | ||||||||||||||||||||||||||||||||||||
| 127 | 'vietnamese' => 1258, | ||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | 69 | init_aliases(); | |||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | 71 | ▶ | sub undef_aliases { | ||||||||||||||||||||||||||||||||||
|
Subroutine
undef_aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 133 | 71 | @Alias = (); | |||||||||||||||||||||||||||||||||||
| 134 | 71 | %Alias = (); | |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||
| 137 | 70 | ▶ | sub init_aliases { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init_aliases: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 138 | 70 | undef_aliases(); | |||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||
| 140 | # Try all-lower-case version should all else fails | ||||||||||||||||||||||||||||||||||||
| 141 | 70 | define_alias( qr/^(.*)$/ => '"\L$1"' ); | |||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | # UTF/UCS stuff | ||||||||||||||||||||||||||||||||||||
| 144 | 70 | define_alias( qr/^(unicode-1-1-)?UTF-?7$/i => '"UTF-7"' ); | |||||||||||||||||||||||||||||||||||
| 145 | 70 | define_alias( qr/^UCS-?2-?LE$/i => '"UCS-2LE"' ); | |||||||||||||||||||||||||||||||||||
| 146 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 147 | qr/^UCS-?2-?(BE)?$/i => '"UCS-2BE"', | ||||||||||||||||||||||||||||||||||||
| 148 | qr/^UCS-?4-?(BE|LE|)?$/i => 'uc("UTF-32$1")', | ||||||||||||||||||||||||||||||||||||
| 149 | qr/^iso-10646-1$/i => '"UCS-2BE"' | ||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||
| 151 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 152 | qr/^UTF-?(16|32)-?BE$/i => '"UTF-$1BE"', | ||||||||||||||||||||||||||||||||||||
| 153 | qr/^UTF-?(16|32)-?LE$/i => '"UTF-$1LE"', | ||||||||||||||||||||||||||||||||||||
| 154 | qr/^UTF-?(16|32)$/i => '"UTF-$1"', | ||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | # ASCII | ||||||||||||||||||||||||||||||||||||
| 158 | 70 | define_alias( qr/^(?:US-?)ascii$/i => '"ascii"' ); | |||||||||||||||||||||||||||||||||||
| 159 | 70 | define_alias( 'C' => 'ascii' ); | |||||||||||||||||||||||||||||||||||
| 160 | 70 | define_alias( qr/\b(?:ISO[-_]?)?646(?:[-_]?US)?$/i => '"ascii"' ); | |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | # Allow variants of iso-8859-1 etc. | ||||||||||||||||||||||||||||||||||||
| 163 | 70 | define_alias( qr/\biso[-_]?(\d+)[-_](\d+)$/i => '"iso-$1-$2"' ); | |||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | # ISO-8859-8-I => ISO-8859-8 | ||||||||||||||||||||||||||||||||||||
| 166 | # https://en.wikipedia.org/wiki/ISO-8859-8-I | ||||||||||||||||||||||||||||||||||||
| 167 | 70 | define_alias( qr/\biso[-_]8859[-_]8[-_]I$/i => '"iso-8859-8"' ); | |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | # At least HP-UX has these. | ||||||||||||||||||||||||||||||||||||
| 170 | 70 | define_alias( qr/\biso8859(\d+)$/i => '"iso-8859-$1"' ); | |||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||
| 172 | # More HP stuff. | ||||||||||||||||||||||||||||||||||||
| 173 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 174 | qr/\b(?:hp-)?(arabic|greek|hebrew|kana|roman|thai|turkish)8$/i => | ||||||||||||||||||||||||||||||||||||
| 175 | '"${1}8"' ); | ||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | # The Official name of ASCII. | ||||||||||||||||||||||||||||||||||||
| 178 | 70 | define_alias( qr/\bANSI[-_]?X3\.4[-_]?1968$/i => '"ascii"' ); | |||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | # This is a font issue, not an encoding issue. | ||||||||||||||||||||||||||||||||||||
| 181 | # (The currency symbol of the Latin 1 upper half | ||||||||||||||||||||||||||||||||||||
| 182 | # has been redefined as the euro symbol.) | ||||||||||||||||||||||||||||||||||||
| 183 | 70 | define_alias( qr/^(.+)\@euro$/i => '"$1"' ); | |||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | 70 | define_alias( qr/\b(?:iso[-_]?)?latin[-_]?(\d+)$/i => | |||||||||||||||||||||||||||||||||||
| 186 | 'defined $Encode::Alias::Latin2iso[$1] ? "iso-8859-$Encode::Alias::Latin2iso[$1]" : undef' | ||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||
| 189 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 190 | qr/\bwin(latin[12]|cyrillic|baltic|greek|turkish| | ||||||||||||||||||||||||||||||||||||
| 191 | hebrew|arabic|baltic|vietnamese)$/ix => | ||||||||||||||||||||||||||||||||||||
| 192 | '"cp" . $Encode::Alias::Winlatin2cp{lc($1)}' | ||||||||||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | # Common names for non-latin preferred MIME names | ||||||||||||||||||||||||||||||||||||
| 196 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 197 | 'ascii' => 'US-ascii', | ||||||||||||||||||||||||||||||||||||
| 198 | 'cyrillic' => 'iso-8859-5', | ||||||||||||||||||||||||||||||||||||
| 199 | 'arabic' => 'iso-8859-6', | ||||||||||||||||||||||||||||||||||||
| 200 | 'greek' => 'iso-8859-7', | ||||||||||||||||||||||||||||||||||||
| 201 | 'hebrew' => 'iso-8859-8', | ||||||||||||||||||||||||||||||||||||
| 202 | 'thai' => 'iso-8859-11', | ||||||||||||||||||||||||||||||||||||
| 203 | ); | ||||||||||||||||||||||||||||||||||||
| 204 | # RT #20781 | ||||||||||||||||||||||||||||||||||||
| 205 | 70 | define_alias(qr/\btis-?620\b/i => '"iso-8859-11"'); | |||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | # At least AIX has IBM-NNN (surprisingly...) instead of cpNNN. | ||||||||||||||||||||||||||||||||||||
| 208 | # And Microsoft has their own naming (again, surprisingly). | ||||||||||||||||||||||||||||||||||||
| 209 | # And windows-* is registered in IANA! | ||||||||||||||||||||||||||||||||||||
| 210 | 70 | define_alias( | |||||||||||||||||||||||||||||||||||
| 211 | qr/\b(?:cp|ibm|ms|windows)[-_ ]?(\d{2,4})$/i => '"cp$1"' ); | ||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||
| 213 | # Sometimes seen with a leading zero. | ||||||||||||||||||||||||||||||||||||
| 214 | # define_alias( qr/\bcp037\b/i => '"cp37"'); | ||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | # Mac Mappings | ||||||||||||||||||||||||||||||||||||
| 217 | # predefined in *.ucm; unneeded | ||||||||||||||||||||||||||||||||||||
| 218 | # define_alias( qr/\bmacIcelandic$/i => '"macIceland"'); | ||||||||||||||||||||||||||||||||||||
| 219 | 70 | define_alias( qr/^(?:x[_-])?mac[_-](.*)$/i => '"mac$1"' ); | |||||||||||||||||||||||||||||||||||
| 220 | # http://rt.cpan.org/Ticket/Display.html?id=36326 | ||||||||||||||||||||||||||||||||||||
| 221 | 70 | define_alias( qr/^macintosh$/i => '"MacRoman"' ); | |||||||||||||||||||||||||||||||||||
| 222 | # https://rt.cpan.org/Ticket/Display.html?id=78125 | ||||||||||||||||||||||||||||||||||||
| 223 | 70 | define_alias( qr/^macce$/i => '"MacCentralEurRoman"' ); | |||||||||||||||||||||||||||||||||||
| 224 | # Ououououou. gone. They are different! | ||||||||||||||||||||||||||||||||||||
| 225 | # define_alias( qr/\bmacRomanian$/i => '"macRumanian"'); | ||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||
| 227 | # Standardize on the dashed versions. | ||||||||||||||||||||||||||||||||||||
| 228 | 70 | define_alias( qr/\bkoi8[\s\-_]*([ru])$/i => '"koi8-$1"' ); | |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||
| 230 | 70 | ▶ | unless ($Encode::ON_EBCDIC) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||
| 232 | # for Encode::CN | ||||||||||||||||||||||||||||||||||||
| 233 | 70 | define_alias( qr/\beuc.*cn$/i => '"euc-cn"' ); | |||||||||||||||||||||||||||||||||||
| 234 | 70 | define_alias( qr/\bcn.*euc$/i => '"euc-cn"' ); | |||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||
| 236 | # define_alias( qr/\bGB[- ]?(\d+)$/i => '"euc-cn"' ) | ||||||||||||||||||||||||||||||||||||
| 237 | # CP936 doesn't have vendor-addon for GBK, so they're identical. | ||||||||||||||||||||||||||||||||||||
| 238 | 70 | define_alias( qr/^gbk$/i => '"cp936"' ); | |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||
| 240 | # This fixes gb2312 vs. euc-cn confusion, practically | ||||||||||||||||||||||||||||||||||||
| 241 | 70 | define_alias( qr/\bGB[-_ ]?2312(?!-?raw)/i => '"euc-cn"' ); | |||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||
| 243 | # for Encode::JP | ||||||||||||||||||||||||||||||||||||
| 244 | 70 | define_alias( qr/\bjis$/i => '"7bit-jis"' ); | |||||||||||||||||||||||||||||||||||
| 245 | 70 | define_alias( qr/\beuc.*jp$/i => '"euc-jp"' ); | |||||||||||||||||||||||||||||||||||
| 246 | 70 | define_alias( qr/\bjp.*euc$/i => '"euc-jp"' ); | |||||||||||||||||||||||||||||||||||
| 247 | 70 | define_alias( qr/\bujis$/i => '"euc-jp"' ); | |||||||||||||||||||||||||||||||||||
| 248 | 70 | define_alias( qr/\bshift.*jis$/i => '"shiftjis"' ); | |||||||||||||||||||||||||||||||||||
| 249 | 70 | define_alias( qr/\bsjis$/i => '"shiftjis"' ); | |||||||||||||||||||||||||||||||||||
| 250 | 70 | define_alias( qr/\bwindows-31j$/i => '"cp932"' ); | |||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||
| 252 | # for Encode::KR | ||||||||||||||||||||||||||||||||||||
| 253 | 70 | define_alias( qr/\beuc.*kr$/i => '"euc-kr"' ); | |||||||||||||||||||||||||||||||||||
| 254 | 70 | define_alias( qr/\bkr.*euc$/i => '"euc-kr"' ); | |||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | # This fixes ksc5601 vs. euc-kr confusion, practically | ||||||||||||||||||||||||||||||||||||
| 257 | 70 | define_alias( qr/(?:x-)?uhc$/i => '"cp949"' ); | |||||||||||||||||||||||||||||||||||
| 258 | 70 | define_alias( qr/(?:x-)?windows-949$/i => '"cp949"' ); | |||||||||||||||||||||||||||||||||||
| 259 | 70 | define_alias( qr/\bks_c_5601-1987$/i => '"cp949"' ); | |||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | # for Encode::TW | ||||||||||||||||||||||||||||||||||||
| 262 | 70 | define_alias( qr/\bbig-?5$/i => '"big5-eten"' ); | |||||||||||||||||||||||||||||||||||
| 263 | 70 | define_alias( qr/\bbig5-?et(?:en)?$/i => '"big5-eten"' ); | |||||||||||||||||||||||||||||||||||
| 264 | 70 | define_alias( qr/\btca[-_]?big5$/i => '"big5-eten"' ); | |||||||||||||||||||||||||||||||||||
| 265 | 70 | define_alias( qr/\bbig5-?hk(?:scs)?$/i => '"big5-hkscs"' ); | |||||||||||||||||||||||||||||||||||
| 266 | 70 | define_alias( qr/\bhk(?:scs)?[-_]?big5$/i => '"big5-hkscs"' ); | |||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | # https://github.com/dankogai/p5-encode/issues/37 | ||||||||||||||||||||||||||||||||||||
| 270 | 70 | define_alias(qr/cp65000/i => '"UTF-7"'); | |||||||||||||||||||||||||||||||||||
| 271 | 70 | define_alias(qr/cp65001/i => '"utf-8-strict"'); | |||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||
| 273 | # utf8 is blessed :) | ||||||||||||||||||||||||||||||||||||
| 274 | 70 | define_alias( qr/\bUTF-8$/i => '"utf-8-strict"' ); | |||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||
| 276 | # At last, Map white space and _ to '-' | ||||||||||||||||||||||||||||||||||||
| 277 | 70 | define_alias( qr/^([^\s_]+)[\s_]+([^\s_]*)$/i => '"$1-$2"' ); | |||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||
| 280 | 69 | 1; | |||||||||||||||||||||||||||||||||||
| 281 | __END__ | ||||||||||||||||||||||||||||||||||||