| 1 | package Lingua::Charsets; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 2 | $Lingua::Charsets::VERSION = 0.04; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | has language_charsets => ( | |||||||||||||||||||||||||||
| 11 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | lazy => 1, | ||||||||||||||||||||||||||||
| 14 | builder => '_build_language_charsets', | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | has language_charsets_raw_reference => ( | |||||||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | lazy => 1, | ||||||||||||||||||||||||||||
| 21 | default => q[ | ||||||||||||||||||||||||||||
| 22 | af (Afrikaans) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 23 | sq (Albanian) iso-8859-1 cp1252 iso-8859-16 | ||||||||||||||||||||||||||||
| 24 | ar (Arabic) iso-8859-6 cp864 cp1256 MacArabic | ||||||||||||||||||||||||||||
| 25 | eu (Basque) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 26 | bg (Bulgarian) iso-8859-5 | ||||||||||||||||||||||||||||
| 27 | be (Byelorussian) iso-8859-5 | ||||||||||||||||||||||||||||
| 28 | ca (Catalan) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 29 | zh (Chinese) gb2312 big5-eten gbk euc-cn | ||||||||||||||||||||||||||||
| 30 | hr (Croatian) iso-8859-2 cp1250 MacCroatian iso-8859-16 | ||||||||||||||||||||||||||||
| 31 | cs (Czech) iso-8859-2 | ||||||||||||||||||||||||||||
| 32 | da (Danish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 33 | nl (Dutch) iso-8859-1 cp1252, iso-8859-15 | ||||||||||||||||||||||||||||
| 34 | en (English) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 35 | eo (Esperanto) iso-8859-3* | ||||||||||||||||||||||||||||
| 36 | et (Estonian) iso-8859-15 cp1257 | ||||||||||||||||||||||||||||
| 37 | fo (Faroese) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 38 | fi (Finnish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 39 | fr (French) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 40 | gl (Galician) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 41 | de (German) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 42 | ka (Georgian) geostd8 | ||||||||||||||||||||||||||||
| 43 | el (Greek) iso-8859-7 cp869 cp1253 MacGreek | ||||||||||||||||||||||||||||
| 44 | iw (Hebrew) iso-8859-8 cp1255 MacHebrew | ||||||||||||||||||||||||||||
| 45 | hu (Hungarian) iso-8859-2 cp1250 iso-8859-16 | ||||||||||||||||||||||||||||
| 46 | is (Icelandic) iso-8859-1 cp1252 MacIceland iso-8859-10 | ||||||||||||||||||||||||||||
| 47 | id (Indonesian) iso-8859-1 | ||||||||||||||||||||||||||||
| 48 | ga (Irish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 49 | it (Italian) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 50 | ja (Japanese) shiftjis iso-2022-jp euc-jp 7bit-jis iso-2022-jp-1 MacJapanese cp932 jis0201-raw jis0208-raw jis0212-raw | ||||||||||||||||||||||||||||
| 51 | ko (Korean) euc-kr ksc5601-raw cp949 MacKorean johab iso-2022-kr | ||||||||||||||||||||||||||||
| 52 | lv (Latvian) iso-8859-13 cp1257 | ||||||||||||||||||||||||||||
| 53 | lt (Lithuanian) iso-8859-13 cp1257 | ||||||||||||||||||||||||||||
| 54 | mk (Macedonian) iso-8859-5 cp1251 | ||||||||||||||||||||||||||||
| 55 | mt (Maltese) iso-8859-3* | ||||||||||||||||||||||||||||
| 56 | no (Norwegian) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 57 | pl (Polish) iso-8859-2 cp852 cp1250 iso-8859-13 iso-8859-16 | ||||||||||||||||||||||||||||
| 58 | pt (Portuguese) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 59 | ro (Romanian) iso-8859-2 MacRomania | ||||||||||||||||||||||||||||
| 60 | ru (Russian) koi8-r cp1251 cp866 iso-8859-5 x-mac-cyrillic | ||||||||||||||||||||||||||||
| 61 | gd (Scottish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 62 | sr (Serbian cyrillic) cp1251 iso-8859-5*** | ||||||||||||||||||||||||||||
| 63 | sr (Serbian latin) iso-8859-2 cp1250 | ||||||||||||||||||||||||||||
| 64 | sk (Slovak) iso-8859-2 | ||||||||||||||||||||||||||||
| 65 | sl (Slovenian) iso-8859-2 cp1250 | ||||||||||||||||||||||||||||
| 66 | es (Spanish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 67 | sv (Swedish) iso-8859-1 cp1252 | ||||||||||||||||||||||||||||
| 68 | th (Thai) cp874 tis-620 MacThai iso-8859-11 | ||||||||||||||||||||||||||||
| 69 | tr (Turkish) iso-8859-9 cp857 cp1254 MacTurkish | ||||||||||||||||||||||||||||
| 70 | uk (Ukrainian) iso-8859-5 | ||||||||||||||||||||||||||||
| 71 | vi (Vietnamese) cp1258 | ||||||||||||||||||||||||||||
| 72 | ] | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | ▶ | sub charsets_for { | ||||||||||||||||||||||||||
|
Subroutine
charsets_for: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 2 | my ($self,$lang) = @_; | |||||||||||||||||||||||||||
| 79 | my $charsets | ||||||||||||||||||||||||||||
| 80 | = $lang | ||||||||||||||||||||||||||||
| 81 | 2 | ▶ | ? $self->language_charsets->{ $lang }{ charsets } || [] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->language_charsets->{$lang}{"charsets"} or []
MC/DC0%0/1
$self->language_charsets->{$lang}{"charsets"} or []
$self->language_charsets->{$lang}{"charsets"}
Truth table50%1/2
A
A= $self->language_charsets->{$lang}{"charsets"}
| |||||||||||||||||||||||||||||
| 82 | : []; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub _build_language_charsets { | ||||||||||||||||||||||||||
|
Subroutine
_build_language_charsets: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 86 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 87 | 1 | my $dict = {}; | |||||||||||||||||||||||||||
| 88 | 1 | my $data = $self->language_charsets_raw_reference; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | my @lines = split /\n/, $data||''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$data || ''
MC/DC0%0/1
$data || ''
$data
Truth table50%1/2
A
A= $data
| |||||||||||||||||||||||||||||
| 90 | 1 | for my $line ( @lines ) { | |||||||||||||||||||||||||||
| 91 | 51 | ▶ | next unless $line = join ' ', split ' ', $line||''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$line || ''
MC/DC100%1/1
$line || ''
$line
Truth table100%2/2
A
A= $line
| |||||||||||||||||||||||||||||
| 92 | 50 | $line =~ s|\([^\(\)]+\)| |g; | |||||||||||||||||||||||||||
| 93 | 50 | $line =~ s|\*||g; | |||||||||||||||||||||||||||
| 94 | 50 | my @parts = split ' ', $line; | |||||||||||||||||||||||||||
| 95 | 50 | my $lang = shift @parts; | |||||||||||||||||||||||||||
| 96 | 50 | ▶ | if ( $lang =~ m|\A[a-z]{2}\Z| && @parts ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lang =~ /\A[a-z]{2}\Z/ and @parts
MC/DC0%0/2
$lang =~ /\A[a-z]{2}\Z/ and @parts
$lang =~ /\A[a-z]{2}\Z/
@parts
Truth table33%1/3
A and B
A= $lang =~ /\A[a-z]{2}\Z/B= @parts
| |||||||||||||||||||||||||||||
| 97 | 50 | push @{ $dict->{ $lang }{charsets} }, @parts; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 1 | return $dict; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 104 | 2 | 1; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # ABSTRACT: Language-based charset reference | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 NAME | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Lingua::Charsets - Provides a list of charsets by language. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | use Lingua::Charsets; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | my $lc = Lingua::Charsets->new; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | my $zh_charsets = $lc->charsets_for( 'zh' ); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This module provides a listing of charsets by language. It can be used | ||||||||||||||||||||||||||||
| 123 | in conjunction with a charset guessing algorithm such as Encode::Guess. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | The data used comes from a variety of locations; however, the initial | ||||||||||||||||||||||||||||
| 126 | source was The W3C charset listing available at: | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | L<http://www.w3.org/International/O-charset-lang.html> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 METHODS | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head2 language_charsets | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Returns a HashRef consisting of ISO-639-1 language codes as hashref keys. | ||||||||||||||||||||||||||||
| 135 | The hashref values are hashrefs with the key 'charsets' that consists | ||||||||||||||||||||||||||||
| 136 | of an arrayref of charsets. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 charsets_for( $iso_639_1_code ) | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Returns an ArrayRef[Str] of charsets for the language's ISO-639-1 code. An | ||||||||||||||||||||||||||||
| 141 | empty ArrayRef is returned if the language isn't found. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | L<Encode::Guess>, L<Encode::JP>, L<Encode::KR>, L<Lingua::RU::Charset> | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 REFERENCES | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | W3.org "I18N languages, countries and character sets" page at: | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | L<http://www.w3.org/International/O-charset-lang.html> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Additional information can be found at: | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | L<http://aspell.net/charsets/> | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | L<http://en.wikipedia.org/wiki/Character_encoding> | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | L<http://www.mnogosearch.org/doc/msearch-international.html> | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Aliases are listed in the mnoGoSearch webpage; however, they are not | ||||||||||||||||||||||||||||
| 162 | currently included as aliases would not be useful for decoding. | ||||||||||||||||||||||||||||
| 163 | They may be added as a separate reference in the future if they are | ||||||||||||||||||||||||||||
| 164 | deemed useful. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | John Wang E<lt>johncwang@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Copyright 2013 by John Wang E<lt>johncwang@gmail.comE<gt>. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | This software is released under the MIT license cited below. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head2 The "MIT" License | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||||||||||||||||||||
| 179 | of this software and associated documentation files (the "Software"), to deal | ||||||||||||||||||||||||||||
| 180 | in the Software without restriction, including without limitation the rights | ||||||||||||||||||||||||||||
| 181 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||
| 182 | copies of the Software, and to permit persons to whom the Software is | ||||||||||||||||||||||||||||
| 183 | furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | The above copyright notice and this permission notice shall be included in | ||||||||||||||||||||||||||||
| 186 | all copies or substantial portions of the Software. | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||||||||||||||||||||||||||||
| 189 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||
| 190 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||||||||||||||||||||||||||||
| 191 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||
| 192 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||||||||||||||||||||||||||
| 193 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||||||||||||||||||||||||||
| 194 | DEALINGS IN THE SOFTWARE. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||