country.pm

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PM 代码 · 共 551 行

PM
551
字号
## Locale::Country - ISO codes for country identification (ISO 3166)## $Id: Country.pm,v 2.7 2004/06/10 21:19:34 neilb Exp $#package Locale::Country;use strict;require 5.002;require Exporter;use Carp;use Locale::Constants;#-----------------------------------------------------------------------#	Public Global Variables#-----------------------------------------------------------------------use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);$VERSION   = sprintf("%d.%02d", q$Revision: 2.7 $ =~ /(\d+)\.(\d+)/);@ISA       = qw(Exporter);@EXPORT    = qw(code2country country2code                all_country_codes all_country_names		country_code2code		LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 LOCALE_CODE_NUMERIC);#-----------------------------------------------------------------------#	Private Global Variables#-----------------------------------------------------------------------my $CODES     = [];my $COUNTRIES = [];#=======================================================================## code2country ( CODE [, CODESET ] )##=======================================================================sub code2country{    my $code = shift;    my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;    return undef unless defined $code;    #-------------------------------------------------------------------    # Make sure the code is in the right form before we use it    # to look up the corresponding country.    # We have to sprintf because the codes are given as 3-digits,    # with leading 0's. Eg 052 for Barbados.    #-------------------------------------------------------------------    if ($codeset == LOCALE_CODE_NUMERIC)    {	return undef if ($code =~ /\D/);	$code = sprintf("%.3d", $code);    }    else    {	$code = lc($code);    }    if (exists $CODES->[$codeset]->{$code})    {        return $CODES->[$codeset]->{$code};    }    else    {        #---------------------------------------------------------------        # no such country code!        #---------------------------------------------------------------        return undef;    }}#=======================================================================## country2code ( NAME [, CODESET ] )##=======================================================================sub country2code{    my $country = shift;    my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;    return undef unless defined $country;    $country = lc($country);    if (exists $COUNTRIES->[$codeset]->{$country})    {        return $COUNTRIES->[$codeset]->{$country};    }    else    {        #---------------------------------------------------------------        # no such country!        #---------------------------------------------------------------        return undef;    }}#=======================================================================## country_code2code ( NAME [, CODESET ] )##=======================================================================sub country_code2code{    (@_ == 3) or croak "country_code2code() takes 3 arguments!";    my $code = shift;    my $inset = shift;    my $outset = shift;    my $outcode;    my $country;    return undef if $inset == $outset;    $country = code2country($code, $inset);    return undef if not defined $country;    $outcode = country2code($country, $outset);    return $outcode;}#=======================================================================## all_country_codes ( [ CODESET ] )##=======================================================================sub all_country_codes{    my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;    return keys %{ $CODES->[$codeset] };}#=======================================================================## all_country_names ( [ CODESET ] )##=======================================================================sub all_country_names{    my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;    return values %{ $CODES->[$codeset] };}#=======================================================================## alias_code ( ALIAS => CODE [ , CODESET ] )## Add an alias for an existing code. If the CODESET isn't specified,# then we use the default (currently the alpha-2 codeset).##   Locale::Country::alias_code('uk' => 'gb');##=======================================================================sub alias_code{    my $alias = shift;    my $real  = shift;    my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;    my $country;    if (not exists $CODES->[$codeset]->{$real})    {        carp "attempt to alias \"$alias\" to unknown country code \"$real\"\n";        return undef;    }    $country = $CODES->[$codeset]->{$real};    $CODES->[$codeset]->{$alias} = $country;    $COUNTRIES->[$codeset]->{"\L$country"} = $alias;    return $alias;}# old name of function for backwards compatibility*_alias_code = *alias_code;#=======================================================================## rename_country## change the official name for a country, eg:#	gb => 'Great Britain'# rather than the standard 'United Kingdom'. The original is retained# as an alias, but the new name will be returned if you lookup the# name from code.##=======================================================================sub rename_country{    my $code     = shift;    my $new_name = shift;    my $codeset = @_ > 0 ? shift : _code2codeset($code);    my $country;    my $c;    if (not defined $codeset)    {        carp "rename_country(): unknown country code \"$code\"\n";        return 0;    }    $country = $CODES->[$codeset]->{$code};    foreach my $cset (LOCALE_CODE_ALPHA_2,			LOCALE_CODE_ALPHA_3,			LOCALE_CODE_NUMERIC)    {	if ($cset == $codeset)	{	    $c = $code;	}	else	{	    $c = country_code2code($code, $codeset, $cset);	}	$CODES->[$cset]->{$c} = $new_name;	$COUNTRIES->[$cset]->{"\L$new_name"} = $c;    }    return 1;}#=======================================================================## _code2codeset## given a country code in an unknown codeset, return the codeset# it is from, or undef.##=======================================================================sub _code2codeset{    my $code = shift;    foreach my $codeset (LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3,			LOCALE_CODE_NUMERIC)    {	return $codeset if (exists $CODES->[$codeset]->{$code})    }    return undef;}#=======================================================================## initialisation code - stuff the DATA into the ALPHA2 hash##======================================================================={    my   ($alpha2, $alpha3, $numeric);    my   ($country, @countries);    local $_;    while (<DATA>)    {        next unless /\S/;        chop;        ($alpha2, $alpha3, $numeric, @countries) = split(/:/, $_);        $CODES->[LOCALE_CODE_ALPHA_2]->{$alpha2} = $countries[0];	foreach $country (@countries)	{	    $COUNTRIES->[LOCALE_CODE_ALPHA_2]->{"\L$country"} = $alpha2;	}	if ($alpha3)	{            $CODES->[LOCALE_CODE_ALPHA_3]->{$alpha3} = $countries[0];	    foreach $country (@countries)	    {		$COUNTRIES->[LOCALE_CODE_ALPHA_3]->{"\L$country"} = $alpha3;	    }	}	if ($numeric)	{            $CODES->[LOCALE_CODE_NUMERIC]->{$numeric} = $countries[0];	    foreach $country (@countries)	    {		$COUNTRIES->[LOCALE_CODE_NUMERIC]->{"\L$country"} = $numeric;	    }	}    }    close(DATA);}1;__DATA__ad:and:020:Andorraae:are:784:United Arab Emiratesaf:afg:004:Afghanistanag:atg:028:Antigua and Barbudaai:aia:660:Anguillaal:alb:008:Albaniaam:arm:051:Armeniaan:ant:530:Netherlands Antillesao:ago:024:Angolaaq:ata:010:Antarcticaar:arg:032:Argentinaas:asm:016:American Samoaat:aut:040:Austriaau:aus:036:Australiaaw:abw:533:Arubaax:ala:248:Aland Islandsaz:aze:031:Azerbaijanba:bih:070:Bosnia and Herzegovinabb:brb:052:Barbadosbd:bgd:050:Bangladeshbe:bel:056:Belgiumbf:bfa:854:Burkina Fasobg:bgr:100:Bulgariabh:bhr:048:Bahrainbi:bdi:108:Burundibj:ben:204:Beninbm:bmu:060:Bermudabn:brn:096:Brunei Darussalambo:bol:068:Boliviabr:bra:076:Brazilbs:bhs:044:Bahamasbt:btn:064:Bhutanbv:bvt:074:Bouvet Islandbw:bwa:072:Botswanaby:blr:112:Belarusbz:blz:084:Belizeca:can:124:Canadacc:cck:166:Cocos (Keeling) Islandscd:cod:180:Congo, The Democratic Republic of the:Zaire:Congo, Democratic Republic of thecf:caf:140:Central African Republiccg:cog:178:Congo:Congo, Republic of thech:che:756:Switzerlandci:civ:384:Cote D'Ivoireck:cok:184:Cook Islandscl:chl:152:Chilecm:cmr:120:Camerooncn:chn:156:Chinaco:col:170:Colombiacr:cri:188:Costa Ricacs:scg:891:Serbia and Montenegro:Yugoslaviacu:cub:192:Cubacv:cpv:132:Cape Verdecx:cxr:162:Christmas Islandcy:cyp:196:Cypruscz:cze:203:Czech Republicde:deu:276:Germanydj:dji:262:Djiboutidk:dnk:208:Denmarkdm:dma:212:Dominicado:dom:214:Dominican Republicdz:dza:012:Algeriaec:ecu:218:Ecuadoree:est:233:Estoniaeg:egy:818:Egypteh:esh:732:Western Saharaer:eri:232:Eritreaes:esp:724:Spainet:eth:231:Ethiopiafi:fin:246:Finlandfj:fji:242:Fijifk:flk:238:Falkland Islands (Malvinas):Falkland Islands (Islas Malvinas)fm:fsm:583:Micronesia, Federated States offo:fro:234:Faroe Islandsfr:fra:250:Francefx:fxx:249:France, Metropolitanga:gab:266:Gabongb:gbr:826:United Kingdom:Great Britaingd:grd:308:Grenadage:geo:268:Georgiagf:guf:254:French Guianagh:gha:288:Ghanagi:gib:292:Gibraltargl:grl:304:Greenlandgm:gmb:270:Gambiagn:gin:324:Guineagp:glp:312:Guadeloupegq:gnq:226:Equatorial Guineagr:grc:300:Greecegs:sgs:239:South Georgia and the South Sandwich Islandsgt:gtm:320:Guatemalagu:gum:316:Guamgw:gnb:624:Guinea-Bissaugy:guy:328:Guyanahk:hkg:344:Hong Konghm:hmd:334:Heard Island and McDonald Islandshn:hnd:340:Hondurashr:hrv:191:Croatiaht:hti:332:Haitihu:hun:348:Hungaryid:idn:360:Indonesiaie:irl:372:Irelandil:isr:376:Israelin:ind:356:Indiaio:iot:086:British Indian Ocean Territoryiq:irq:368:Iraqir:irn:364:Iran, Islamic Republic of:Iranis:isl:352:Icelandit:ita:380:Italyjm:jam:388:Jamaicajo:jor:400:Jordanjp:jpn:392:Japanke:ken:404:Kenyakg:kgz:417:Kyrgyzstankh:khm:116:Cambodiaki:kir:296:Kiribatikm:com:174:Comoroskn:kna:659:Saint Kitts and Neviskp:prk:408:Korea, Democratic People's Republic of:Korea, North:North Koreakr:kor:410:Korea, Republic of:Korea, South:South Koreakw:kwt:414:Kuwaitky:cym:136:Cayman Islandskz:kaz:398:Kazakhstan:Kazakstanla:lao:418:Lao People's Democratic Republiclb:lbn:422:Lebanonlc:lca:662:Saint Luciali:lie:438:Liechtensteinlk:lka:144:Sri Lankalr:lbr:430:Liberials:lso:426:Lesotholt:ltu:440:Lithuanialu:lux:442:Luxembourglv:lva:428:Latvialy:lby:434:Libyan Arab Jamahiriya:Libyama:mar:504:Moroccomc:mco:492:Monacomd:mda:498:Moldova, Republic of:Moldovamg:mdg:450:Madagascarmh:mhl:584:Marshall Islandsmk:mkd:807:Macedonia, the Former Yugoslav Republic of:Macedonia, Former Yugoslav Republic of:Macedoniaml:mli:466:Malimm:mmr:104:Myanmar:Burmamn:mng:496:Mongoliamo:mac:446:Macao:Macaump:mnp:580:Northern Mariana Islandsmq:mtq:474:Martiniquemr:mrt:478:Mauritaniams:msr:500:Montserratmt:mlt:470:Maltamu:mus:480:Mauritiusmv:mdv:462:Maldivesmw:mwi:454:Malawimx:mex:484:Mexicomy:mys:458:Malaysiamz:moz:508:Mozambiquena:nam:516:Namibianc:ncl:540:New Caledoniane:ner:562:Nigernf:nfk:574:Norfolk Islandng:nga:566:Nigeriani:nic:558:Nicaraguanl:nld:528:Netherlandsno:nor:578:Norwaynp:npl:524:Nepalnr:nru:520:Naurunu:niu:570:Niuenz:nzl:554:New Zealandom:omn:512:Omanpa:pan:591:Panamape:per:604:Perupf:pyf:258:French Polynesiapg:png:598:Papua New Guineaph:phl:608:Philippinespk:pak:586:Pakistanpl:pol:616:Polandpm:spm:666:Saint Pierre and Miquelonpn:pcn:612:Pitcairn:Pitcairn Islandpr:pri:630:Puerto Ricops:pse:275:Palestinian Territory, Occupiedpt:prt:620:Portugalpw:plw:585:Palaupy:pry:600:Paraguayqa:qat:634:Qatarre:reu:638:Reunionro:rou:642:Romaniaru:rus:643:Russian Federation:Russiarw:rwa:646:Rwandasa:sau:682:Saudi Arabiasb:slb:090:Solomon Islandssc:syc:690:Seychellessd:sdn:736:Sudanse:swe:752:Swedensg:sgp:702:Singaporesh:shn:654:Saint Helenasi:svn:705:Sloveniasj:sjm:744:Svalbard and Jan Mayen:Jan Mayen:Svalbardsk:svk:703:Slovakiasl:sle:694:Sierra Leonesm:smr:674:San Marinosn:sen:686:Senegalso:som:706:Somaliasr:sur:740:Surinamest:stp:678:Sao Tome and Principesv:slv:222:El Salvadorsy:syr:760:Syrian Arab Republic:Syriasz:swz:748:Swazilandtc:tca:796:Turks and Caicos Islandstd:tcd:148:Chadtf:atf:260:French Southern Territories:French Southern and Antarctic Landstg:tgo:768:Togoth:tha:764:Thailandtj:tjk:762:Tajikistantk:tkl:772:Tokelautm:tkm:795:Turkmenistantn:tun:788:Tunisiato:ton:776:Tongatl:tls:626:Timor-Leste:East Timortr:tur:792:Turkeytt:tto:780:Trinidad and Tobagotv:tuv:798:Tuvalutw:twn:158:Taiwan, Province of China:Taiwantz:tza:834:Tanzania, United Republic of:Tanzaniaua:ukr:804:Ukraineug:uga:800:Ugandaum:umi:581:United States Minor Outlying Islandsus:usa:840:United States:USA:United States of Americauy:ury:858:Uruguayuz:uzb:860:Uzbekistanva:vat:336:Holy See (Vatican City State):Holy See (Vatican City)vc:vct:670:Saint Vincent and the Grenadinesve:ven:862:Venezuelavg:vgb:092:Virgin Islands, British:British Virgin Islandsvi:vir:850:Virgin Islands, U.S.vn:vnm:704:Vietnamvu:vut:548:Vanuatuwf:wlf:876:Wallis and Futunaws:wsm:882:Samoaye:yem:887:Yemenyt:myt:175:Mayotteza:zaf:710:South Africazm:zmb:894:Zambiazw:zwe:716:Zimbabwe

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?