iso3166-country-codes 0.1 → 0.20090527.1
raw patch · 8 files changed
+820/−230 lines, 8 filesdep −HTTPdep −utf8-stringsetup-changed
Dependencies removed: HTTP, utf8-string
Files
- Data/ISO3166_CountryCodes.hs +811/−0
- Data/ISO3166_CountryCodes.hsc +0/−0
- Data/ISO3166_CountryCodes.preamble.hs +0/−61
- Data/ISO3166_CountryCodes/GenerateDataDeclaration.hs +0/−67
- Data/ISO3166_CountryCodes/Getter.hs +0/−62
- Makefile +0/−32
- Setup.hs +1/−1
- iso3166-country-codes.cabal +8/−7
+ Data/ISO3166_CountryCodes.hs view
@@ -0,0 +1,811 @@+{- This is a machine generated module.+ Do not edit.+ See cabal file for repository url.+-}+{- | Two letter Country Codes++ Defines the type CountryCode with constructors for each+ of the two-letter codes defined in+ <http://www.iso.org/iso/iso3166_en_code_lists.txt> and+ instances for 'Eq', 'Read', 'Show', 'Enum', 'Bounded'+ and 'Ord'.++ Also defines @'countryNameFromCode'@, which gives the+ official short country name all in uppercase and+ @'readableCountryName'@, which produces somewhat more user-friendly output++ Intended to be imported qualified as some country codes+ are the same as some standard Haskell constructors.++-}+module Data.ISO3166_CountryCodes+ (CountryCode(..),+ countryNameFromCode,+ readableCountryName+ ) where+import qualified Prelude as P+import Prelude ((.),not,(==),otherwise,(&&),(==),(/=))+import Control.Monad+import Data.Char+import Data.List++{- | A human readable version of the official name of a country+ from its country code++ Uses some ad-hockery to rearrange the order of the words.++-}+readableCountryName :: CountryCode -> String++readableCountryName+ = concat . intersperse " " . rearrange . fmap up1 . words .+ countryNameFromCode+ where up1 [] = []+ up1 (c:rest) | not (isAlpha c) = c:up1 rest+ up1 "OF" = "of"+ up1 "THE" = "the"+ up1 "AND" = "and"+ up1 "U.S." = "US" -- gawd+ up1 ('M':'C':l) = "Mc"++up1 l -- Don't do MacEdonia!+ -- but there are no Mac_ countries yet+ up1 ('D':'\'':l) = "d'"++up1 l+ up1 (c:cs) = toUpper c: downup cs+ downup [] = [] -- needed for hyphenated names+ downup (c:cs) | c=='-' = c:up1 cs+ | otherwise = toLower c:downup cs+ rearrange [] = []+ rearrange [c] = [c]+ rearrange ll@(n:l)+ | last l `elem` ["of", "the"] && last n == ','+ = onhead up1 l++[[c|c<-n,c/=',']]+ | otherwise = ll+ onhead f [] = []+ onhead f (h:r) = f h:r+{- Copyright © 2010 Jón Fairbairn+-}+data CountryCode = + AF -- ^ AFGHANISTAN+ |+ AX -- ^ ÅLAND ISLANDS+ |+ AL -- ^ ALBANIA+ |+ DZ -- ^ ALGERIA+ |+ AS -- ^ AMERICAN SAMOA+ |+ AD -- ^ ANDORRA+ |+ AO -- ^ ANGOLA+ |+ AI -- ^ ANGUILLA+ |+ AQ -- ^ ANTARCTICA+ |+ AG -- ^ ANTIGUA AND BARBUDA+ |+ AR -- ^ ARGENTINA+ |+ AM -- ^ ARMENIA+ |+ AW -- ^ ARUBA+ |+ AU -- ^ AUSTRALIA+ |+ AT -- ^ AUSTRIA+ |+ AZ -- ^ AZERBAIJAN+ |+ BS -- ^ BAHAMAS+ |+ BH -- ^ BAHRAIN+ |+ BD -- ^ BANGLADESH+ |+ BB -- ^ BARBADOS+ |+ BY -- ^ BELARUS+ |+ BE -- ^ BELGIUM+ |+ BZ -- ^ BELIZE+ |+ BJ -- ^ BENIN+ |+ BM -- ^ BERMUDA+ |+ BT -- ^ BHUTAN+ |+ BO -- ^ BOLIVIA, PLURINATIONAL STATE OF+ |+ BA -- ^ BOSNIA AND HERZEGOVINA+ |+ BW -- ^ BOTSWANA+ |+ BV -- ^ BOUVET ISLAND+ |+ BR -- ^ BRAZIL+ |+ IO -- ^ BRITISH INDIAN OCEAN TERRITORY+ |+ BN -- ^ BRUNEI DARUSSALAM+ |+ BG -- ^ BULGARIA+ |+ BF -- ^ BURKINA FASO+ |+ BI -- ^ BURUNDI+ |+ KH -- ^ CAMBODIA+ |+ CM -- ^ CAMEROON+ |+ CA -- ^ CANADA+ |+ CV -- ^ CAPE VERDE+ |+ KY -- ^ CAYMAN ISLANDS+ |+ CF -- ^ CENTRAL AFRICAN REPUBLIC+ |+ TD -- ^ CHAD+ |+ CL -- ^ CHILE+ |+ CN -- ^ CHINA+ |+ CX -- ^ CHRISTMAS ISLAND+ |+ CC -- ^ COCOS (KEELING) ISLANDS+ |+ CO -- ^ COLOMBIA+ |+ KM -- ^ COMOROS+ |+ CG -- ^ CONGO+ |+ CD -- ^ CONGO, THE DEMOCRATIC REPUBLIC OF THE+ |+ CK -- ^ COOK ISLANDS+ |+ CR -- ^ COSTA RICA+ |+ CI -- ^ CÔTE D'IVOIRE+ |+ HR -- ^ CROATIA+ |+ CU -- ^ CUBA+ |+ CY -- ^ CYPRUS+ |+ CZ -- ^ CZECH REPUBLIC+ |+ DK -- ^ DENMARK+ |+ DJ -- ^ DJIBOUTI+ |+ DM -- ^ DOMINICA+ |+ DO -- ^ DOMINICAN REPUBLIC+ |+ EC -- ^ ECUADOR+ |+ EG -- ^ EGYPT+ |+ SV -- ^ EL SALVADOR+ |+ GQ -- ^ EQUATORIAL GUINEA+ |+ ER -- ^ ERITREA+ |+ EE -- ^ ESTONIA+ |+ ET -- ^ ETHIOPIA+ |+ FK -- ^ FALKLAND ISLANDS (MALVINAS)+ |+ FO -- ^ FAROE ISLANDS+ |+ FJ -- ^ FIJI+ |+ FI -- ^ FINLAND+ |+ FR -- ^ FRANCE+ |+ GF -- ^ FRENCH GUIANA+ |+ PF -- ^ FRENCH POLYNESIA+ |+ TF -- ^ FRENCH SOUTHERN TERRITORIES+ |+ GA -- ^ GABON+ |+ GM -- ^ GAMBIA+ |+ GE -- ^ GEORGIA+ |+ DE -- ^ GERMANY+ |+ GH -- ^ GHANA+ |+ GI -- ^ GIBRALTAR+ |+ GR -- ^ GREECE+ |+ GL -- ^ GREENLAND+ |+ GD -- ^ GRENADA+ |+ GP -- ^ GUADELOUPE+ |+ GU -- ^ GUAM+ |+ GT -- ^ GUATEMALA+ |+ GG -- ^ GUERNSEY+ |+ GN -- ^ GUINEA+ |+ GW -- ^ GUINEA-BISSAU+ |+ GY -- ^ GUYANA+ |+ HT -- ^ HAITI+ |+ HM -- ^ HEARD ISLAND AND MCDONALD ISLANDS+ |+ VA -- ^ HOLY SEE (VATICAN CITY STATE)+ |+ HN -- ^ HONDURAS+ |+ HK -- ^ HONG KONG+ |+ HU -- ^ HUNGARY+ |+ IS -- ^ ICELAND+ |+ IN -- ^ INDIA+ |+ ID -- ^ INDONESIA+ |+ IR -- ^ IRAN, ISLAMIC REPUBLIC OF+ |+ IQ -- ^ IRAQ+ |+ IE -- ^ IRELAND+ |+ IM -- ^ ISLE OF MAN+ |+ IL -- ^ ISRAEL+ |+ IT -- ^ ITALY+ |+ JM -- ^ JAMAICA+ |+ JP -- ^ JAPAN+ |+ JE -- ^ JERSEY+ |+ JO -- ^ JORDAN+ |+ KZ -- ^ KAZAKHSTAN+ |+ KE -- ^ KENYA+ |+ KI -- ^ KIRIBATI+ |+ KP -- ^ KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF+ |+ KR -- ^ KOREA, REPUBLIC OF+ |+ KW -- ^ KUWAIT+ |+ KG -- ^ KYRGYZSTAN+ |+ LA -- ^ LAO PEOPLE'S DEMOCRATIC REPUBLIC+ |+ LV -- ^ LATVIA+ |+ LB -- ^ LEBANON+ |+ LS -- ^ LESOTHO+ |+ LR -- ^ LIBERIA+ |+ LY -- ^ LIBYAN ARAB JAMAHIRIYA+ |+ LI -- ^ LIECHTENSTEIN+ |+ LT -- ^ LITHUANIA+ |+ LU -- ^ LUXEMBOURG+ |+ MO -- ^ MACAO+ |+ MK -- ^ MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF+ |+ MG -- ^ MADAGASCAR+ |+ MW -- ^ MALAWI+ |+ MY -- ^ MALAYSIA+ |+ MV -- ^ MALDIVES+ |+ ML -- ^ MALI+ |+ MT -- ^ MALTA+ |+ MH -- ^ MARSHALL ISLANDS+ |+ MQ -- ^ MARTINIQUE+ |+ MR -- ^ MAURITANIA+ |+ MU -- ^ MAURITIUS+ |+ YT -- ^ MAYOTTE+ |+ MX -- ^ MEXICO+ |+ FM -- ^ MICRONESIA, FEDERATED STATES OF+ |+ MD -- ^ MOLDOVA, REPUBLIC OF+ |+ MC -- ^ MONACO+ |+ MN -- ^ MONGOLIA+ |+ ME -- ^ MONTENEGRO+ |+ MS -- ^ MONTSERRAT+ |+ MA -- ^ MOROCCO+ |+ MZ -- ^ MOZAMBIQUE+ |+ MM -- ^ MYANMAR+ |+ NA -- ^ NAMIBIA+ |+ NR -- ^ NAURU+ |+ NP -- ^ NEPAL+ |+ NL -- ^ NETHERLANDS+ |+ AN -- ^ NETHERLANDS ANTILLES+ |+ NC -- ^ NEW CALEDONIA+ |+ NZ -- ^ NEW ZEALAND+ |+ NI -- ^ NICARAGUA+ |+ NE -- ^ NIGER+ |+ NG -- ^ NIGERIA+ |+ NU -- ^ NIUE+ |+ NF -- ^ NORFOLK ISLAND+ |+ MP -- ^ NORTHERN MARIANA ISLANDS+ |+ NO -- ^ NORWAY+ |+ OM -- ^ OMAN+ |+ PK -- ^ PAKISTAN+ |+ PW -- ^ PALAU+ |+ PS -- ^ PALESTINIAN TERRITORY, OCCUPIED+ |+ PA -- ^ PANAMA+ |+ PG -- ^ PAPUA NEW GUINEA+ |+ PY -- ^ PARAGUAY+ |+ PE -- ^ PERU+ |+ PH -- ^ PHILIPPINES+ |+ PN -- ^ PITCAIRN+ |+ PL -- ^ POLAND+ |+ PT -- ^ PORTUGAL+ |+ PR -- ^ PUERTO RICO+ |+ QA -- ^ QATAR+ |+ RE -- ^ REUNION+ |+ RO -- ^ ROMANIA+ |+ RU -- ^ RUSSIAN FEDERATION+ |+ RW -- ^ RWANDA+ |+ BL -- ^ SAINT BARTHÉLEMY+ |+ SH -- ^ SAINT HELENA+ |+ KN -- ^ SAINT KITTS AND NEVIS+ |+ LC -- ^ SAINT LUCIA+ |+ MF -- ^ SAINT MARTIN+ |+ PM -- ^ SAINT PIERRE AND MIQUELON+ |+ VC -- ^ SAINT VINCENT AND THE GRENADINES+ |+ WS -- ^ SAMOA+ |+ SM -- ^ SAN MARINO+ |+ ST -- ^ SAO TOME AND PRINCIPE+ |+ SA -- ^ SAUDI ARABIA+ |+ SN -- ^ SENEGAL+ |+ RS -- ^ SERBIA+ |+ SC -- ^ SEYCHELLES+ |+ SL -- ^ SIERRA LEONE+ |+ SG -- ^ SINGAPORE+ |+ SK -- ^ SLOVAKIA+ |+ SI -- ^ SLOVENIA+ |+ SB -- ^ SOLOMON ISLANDS+ |+ SO -- ^ SOMALIA+ |+ ZA -- ^ SOUTH AFRICA+ |+ GS -- ^ SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS+ |+ ES -- ^ SPAIN+ |+ LK -- ^ SRI LANKA+ |+ SD -- ^ SUDAN+ |+ SR -- ^ SURINAME+ |+ SJ -- ^ SVALBARD AND JAN MAYEN+ |+ SZ -- ^ SWAZILAND+ |+ SE -- ^ SWEDEN+ |+ CH -- ^ SWITZERLAND+ |+ SY -- ^ SYRIAN ARAB REPUBLIC+ |+ TW -- ^ TAIWAN, PROVINCE OF CHINA+ |+ TJ -- ^ TAJIKISTAN+ |+ TZ -- ^ TANZANIA, UNITED REPUBLIC OF+ |+ TH -- ^ THAILAND+ |+ TL -- ^ TIMOR-LESTE+ |+ TG -- ^ TOGO+ |+ TK -- ^ TOKELAU+ |+ TO -- ^ TONGA+ |+ TT -- ^ TRINIDAD AND TOBAGO+ |+ TN -- ^ TUNISIA+ |+ TR -- ^ TURKEY+ |+ TM -- ^ TURKMENISTAN+ |+ TC -- ^ TURKS AND CAICOS ISLANDS+ |+ TV -- ^ TUVALU+ |+ UG -- ^ UGANDA+ |+ UA -- ^ UKRAINE+ |+ AE -- ^ UNITED ARAB EMIRATES+ |+ GB -- ^ UNITED KINGDOM+ |+ US -- ^ UNITED STATES+ |+ UM -- ^ UNITED STATES MINOR OUTLYING ISLANDS+ |+ UY -- ^ URUGUAY+ |+ UZ -- ^ UZBEKISTAN+ |+ VU -- ^ VANUATU+ |+ VE -- ^ VENEZUELA+ |+ VN -- ^ VIET NAM+ |+ VG -- ^ VIRGIN ISLANDS, BRITISH+ |+ VI -- ^ VIRGIN ISLANDS, U.S.+ |+ WF -- ^ WALLIS AND FUTUNA+ |+ EH -- ^ WESTERN SAHARA+ |+ YE -- ^ YEMEN+ |+ ZM -- ^ ZAMBIA+ |+ ZW -- ^ ZIMBABWE+ deriving (P.Eq,P.Read,P.Show,P.Enum,P.Bounded,P.Ord)++{-|+ convert a country code to the official (English) name of the country++ see @'readableCountryName'@ for something with a more pleasing word order and capitalisation+-}+countryNameFromCode:: CountryCode -> String+countryNameFromCode AF = "AFGHANISTAN"+countryNameFromCode AX = "ÅLAND ISLANDS"+countryNameFromCode AL = "ALBANIA"+countryNameFromCode DZ = "ALGERIA"+countryNameFromCode AS = "AMERICAN SAMOA"+countryNameFromCode AD = "ANDORRA"+countryNameFromCode AO = "ANGOLA"+countryNameFromCode AI = "ANGUILLA"+countryNameFromCode AQ = "ANTARCTICA"+countryNameFromCode AG = "ANTIGUA AND BARBUDA"+countryNameFromCode AR = "ARGENTINA"+countryNameFromCode AM = "ARMENIA"+countryNameFromCode AW = "ARUBA"+countryNameFromCode AU = "AUSTRALIA"+countryNameFromCode AT = "AUSTRIA"+countryNameFromCode AZ = "AZERBAIJAN"+countryNameFromCode BS = "BAHAMAS"+countryNameFromCode BH = "BAHRAIN"+countryNameFromCode BD = "BANGLADESH"+countryNameFromCode BB = "BARBADOS"+countryNameFromCode BY = "BELARUS"+countryNameFromCode BE = "BELGIUM"+countryNameFromCode BZ = "BELIZE"+countryNameFromCode BJ = "BENIN"+countryNameFromCode BM = "BERMUDA"+countryNameFromCode BT = "BHUTAN"+countryNameFromCode BO = "BOLIVIA, PLURINATIONAL STATE OF"+countryNameFromCode BA = "BOSNIA AND HERZEGOVINA"+countryNameFromCode BW = "BOTSWANA"+countryNameFromCode BV = "BOUVET ISLAND"+countryNameFromCode BR = "BRAZIL"+countryNameFromCode IO = "BRITISH INDIAN OCEAN TERRITORY"+countryNameFromCode BN = "BRUNEI DARUSSALAM"+countryNameFromCode BG = "BULGARIA"+countryNameFromCode BF = "BURKINA FASO"+countryNameFromCode BI = "BURUNDI"+countryNameFromCode KH = "CAMBODIA"+countryNameFromCode CM = "CAMEROON"+countryNameFromCode CA = "CANADA"+countryNameFromCode CV = "CAPE VERDE"+countryNameFromCode KY = "CAYMAN ISLANDS"+countryNameFromCode CF = "CENTRAL AFRICAN REPUBLIC"+countryNameFromCode TD = "CHAD"+countryNameFromCode CL = "CHILE"+countryNameFromCode CN = "CHINA"+countryNameFromCode CX = "CHRISTMAS ISLAND"+countryNameFromCode CC = "COCOS (KEELING) ISLANDS"+countryNameFromCode CO = "COLOMBIA"+countryNameFromCode KM = "COMOROS"+countryNameFromCode CG = "CONGO"+countryNameFromCode CD = "CONGO, THE DEMOCRATIC REPUBLIC OF THE"+countryNameFromCode CK = "COOK ISLANDS"+countryNameFromCode CR = "COSTA RICA"+countryNameFromCode CI = "CÔTE D'IVOIRE"+countryNameFromCode HR = "CROATIA"+countryNameFromCode CU = "CUBA"+countryNameFromCode CY = "CYPRUS"+countryNameFromCode CZ = "CZECH REPUBLIC"+countryNameFromCode DK = "DENMARK"+countryNameFromCode DJ = "DJIBOUTI"+countryNameFromCode DM = "DOMINICA"+countryNameFromCode DO = "DOMINICAN REPUBLIC"+countryNameFromCode EC = "ECUADOR"+countryNameFromCode EG = "EGYPT"+countryNameFromCode SV = "EL SALVADOR"+countryNameFromCode GQ = "EQUATORIAL GUINEA"+countryNameFromCode ER = "ERITREA"+countryNameFromCode EE = "ESTONIA"+countryNameFromCode ET = "ETHIOPIA"+countryNameFromCode FK = "FALKLAND ISLANDS (MALVINAS)"+countryNameFromCode FO = "FAROE ISLANDS"+countryNameFromCode FJ = "FIJI"+countryNameFromCode FI = "FINLAND"+countryNameFromCode FR = "FRANCE"+countryNameFromCode GF = "FRENCH GUIANA"+countryNameFromCode PF = "FRENCH POLYNESIA"+countryNameFromCode TF = "FRENCH SOUTHERN TERRITORIES"+countryNameFromCode GA = "GABON"+countryNameFromCode GM = "GAMBIA"+countryNameFromCode GE = "GEORGIA"+countryNameFromCode DE = "GERMANY"+countryNameFromCode GH = "GHANA"+countryNameFromCode GI = "GIBRALTAR"+countryNameFromCode GR = "GREECE"+countryNameFromCode GL = "GREENLAND"+countryNameFromCode GD = "GRENADA"+countryNameFromCode GP = "GUADELOUPE"+countryNameFromCode GU = "GUAM"+countryNameFromCode GT = "GUATEMALA"+countryNameFromCode GG = "GUERNSEY"+countryNameFromCode GN = "GUINEA"+countryNameFromCode GW = "GUINEA-BISSAU"+countryNameFromCode GY = "GUYANA"+countryNameFromCode HT = "HAITI"+countryNameFromCode HM = "HEARD ISLAND AND MCDONALD ISLANDS"+countryNameFromCode VA = "HOLY SEE (VATICAN CITY STATE)"+countryNameFromCode HN = "HONDURAS"+countryNameFromCode HK = "HONG KONG"+countryNameFromCode HU = "HUNGARY"+countryNameFromCode IS = "ICELAND"+countryNameFromCode IN = "INDIA"+countryNameFromCode ID = "INDONESIA"+countryNameFromCode IR = "IRAN, ISLAMIC REPUBLIC OF"+countryNameFromCode IQ = "IRAQ"+countryNameFromCode IE = "IRELAND"+countryNameFromCode IM = "ISLE OF MAN"+countryNameFromCode IL = "ISRAEL"+countryNameFromCode IT = "ITALY"+countryNameFromCode JM = "JAMAICA"+countryNameFromCode JP = "JAPAN"+countryNameFromCode JE = "JERSEY"+countryNameFromCode JO = "JORDAN"+countryNameFromCode KZ = "KAZAKHSTAN"+countryNameFromCode KE = "KENYA"+countryNameFromCode KI = "KIRIBATI"+countryNameFromCode KP = "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF"+countryNameFromCode KR = "KOREA, REPUBLIC OF"+countryNameFromCode KW = "KUWAIT"+countryNameFromCode KG = "KYRGYZSTAN"+countryNameFromCode LA = "LAO PEOPLE'S DEMOCRATIC REPUBLIC"+countryNameFromCode LV = "LATVIA"+countryNameFromCode LB = "LEBANON"+countryNameFromCode LS = "LESOTHO"+countryNameFromCode LR = "LIBERIA"+countryNameFromCode LY = "LIBYAN ARAB JAMAHIRIYA"+countryNameFromCode LI = "LIECHTENSTEIN"+countryNameFromCode LT = "LITHUANIA"+countryNameFromCode LU = "LUXEMBOURG"+countryNameFromCode MO = "MACAO"+countryNameFromCode MK = "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF"+countryNameFromCode MG = "MADAGASCAR"+countryNameFromCode MW = "MALAWI"+countryNameFromCode MY = "MALAYSIA"+countryNameFromCode MV = "MALDIVES"+countryNameFromCode ML = "MALI"+countryNameFromCode MT = "MALTA"+countryNameFromCode MH = "MARSHALL ISLANDS"+countryNameFromCode MQ = "MARTINIQUE"+countryNameFromCode MR = "MAURITANIA"+countryNameFromCode MU = "MAURITIUS"+countryNameFromCode YT = "MAYOTTE"+countryNameFromCode MX = "MEXICO"+countryNameFromCode FM = "MICRONESIA, FEDERATED STATES OF"+countryNameFromCode MD = "MOLDOVA, REPUBLIC OF"+countryNameFromCode MC = "MONACO"+countryNameFromCode MN = "MONGOLIA"+countryNameFromCode ME = "MONTENEGRO"+countryNameFromCode MS = "MONTSERRAT"+countryNameFromCode MA = "MOROCCO"+countryNameFromCode MZ = "MOZAMBIQUE"+countryNameFromCode MM = "MYANMAR"+countryNameFromCode NA = "NAMIBIA"+countryNameFromCode NR = "NAURU"+countryNameFromCode NP = "NEPAL"+countryNameFromCode NL = "NETHERLANDS"+countryNameFromCode AN = "NETHERLANDS ANTILLES"+countryNameFromCode NC = "NEW CALEDONIA"+countryNameFromCode NZ = "NEW ZEALAND"+countryNameFromCode NI = "NICARAGUA"+countryNameFromCode NE = "NIGER"+countryNameFromCode NG = "NIGERIA"+countryNameFromCode NU = "NIUE"+countryNameFromCode NF = "NORFOLK ISLAND"+countryNameFromCode MP = "NORTHERN MARIANA ISLANDS"+countryNameFromCode NO = "NORWAY"+countryNameFromCode OM = "OMAN"+countryNameFromCode PK = "PAKISTAN"+countryNameFromCode PW = "PALAU"+countryNameFromCode PS = "PALESTINIAN TERRITORY, OCCUPIED"+countryNameFromCode PA = "PANAMA"+countryNameFromCode PG = "PAPUA NEW GUINEA"+countryNameFromCode PY = "PARAGUAY"+countryNameFromCode PE = "PERU"+countryNameFromCode PH = "PHILIPPINES"+countryNameFromCode PN = "PITCAIRN"+countryNameFromCode PL = "POLAND"+countryNameFromCode PT = "PORTUGAL"+countryNameFromCode PR = "PUERTO RICO"+countryNameFromCode QA = "QATAR"+countryNameFromCode RE = "REUNION"+countryNameFromCode RO = "ROMANIA"+countryNameFromCode RU = "RUSSIAN FEDERATION"+countryNameFromCode RW = "RWANDA"+countryNameFromCode BL = "SAINT BARTHÉLEMY"+countryNameFromCode SH = "SAINT HELENA"+countryNameFromCode KN = "SAINT KITTS AND NEVIS"+countryNameFromCode LC = "SAINT LUCIA"+countryNameFromCode MF = "SAINT MARTIN"+countryNameFromCode PM = "SAINT PIERRE AND MIQUELON"+countryNameFromCode VC = "SAINT VINCENT AND THE GRENADINES"+countryNameFromCode WS = "SAMOA"+countryNameFromCode SM = "SAN MARINO"+countryNameFromCode ST = "SAO TOME AND PRINCIPE"+countryNameFromCode SA = "SAUDI ARABIA"+countryNameFromCode SN = "SENEGAL"+countryNameFromCode RS = "SERBIA"+countryNameFromCode SC = "SEYCHELLES"+countryNameFromCode SL = "SIERRA LEONE"+countryNameFromCode SG = "SINGAPORE"+countryNameFromCode SK = "SLOVAKIA"+countryNameFromCode SI = "SLOVENIA"+countryNameFromCode SB = "SOLOMON ISLANDS"+countryNameFromCode SO = "SOMALIA"+countryNameFromCode ZA = "SOUTH AFRICA"+countryNameFromCode GS = "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"+countryNameFromCode ES = "SPAIN"+countryNameFromCode LK = "SRI LANKA"+countryNameFromCode SD = "SUDAN"+countryNameFromCode SR = "SURINAME"+countryNameFromCode SJ = "SVALBARD AND JAN MAYEN"+countryNameFromCode SZ = "SWAZILAND"+countryNameFromCode SE = "SWEDEN"+countryNameFromCode CH = "SWITZERLAND"+countryNameFromCode SY = "SYRIAN ARAB REPUBLIC"+countryNameFromCode TW = "TAIWAN, PROVINCE OF CHINA"+countryNameFromCode TJ = "TAJIKISTAN"+countryNameFromCode TZ = "TANZANIA, UNITED REPUBLIC OF"+countryNameFromCode TH = "THAILAND"+countryNameFromCode TL = "TIMOR-LESTE"+countryNameFromCode TG = "TOGO"+countryNameFromCode TK = "TOKELAU"+countryNameFromCode TO = "TONGA"+countryNameFromCode TT = "TRINIDAD AND TOBAGO"+countryNameFromCode TN = "TUNISIA"+countryNameFromCode TR = "TURKEY"+countryNameFromCode TM = "TURKMENISTAN"+countryNameFromCode TC = "TURKS AND CAICOS ISLANDS"+countryNameFromCode TV = "TUVALU"+countryNameFromCode UG = "UGANDA"+countryNameFromCode UA = "UKRAINE"+countryNameFromCode AE = "UNITED ARAB EMIRATES"+countryNameFromCode GB = "UNITED KINGDOM"+countryNameFromCode US = "UNITED STATES"+countryNameFromCode UM = "UNITED STATES MINOR OUTLYING ISLANDS"+countryNameFromCode UY = "URUGUAY"+countryNameFromCode UZ = "UZBEKISTAN"+countryNameFromCode VU = "VANUATU"+countryNameFromCode VE = "VENEZUELA"+countryNameFromCode VN = "VIET NAM"+countryNameFromCode VG = "VIRGIN ISLANDS, BRITISH"+countryNameFromCode VI = "VIRGIN ISLANDS, U.S."+countryNameFromCode WF = "WALLIS AND FUTUNA"+countryNameFromCode EH = "WESTERN SAHARA"+countryNameFromCode YE = "YEMEN"+countryNameFromCode ZM = "ZAMBIA"+countryNameFromCode ZW = "ZIMBABWE"
− Data/ISO3166_CountryCodes.hsc
− Data/ISO3166_CountryCodes.preamble.hs
@@ -1,61 +0,0 @@-{- | Two letter Country Codes-- Defines the type CountryCode with constructors for each- of the two-letter codes defined in- <http://www.iso.org/iso/iso3166_en_code_lists.txt> and- instances for 'Eq', 'Read', 'Show', 'Enum', 'Bounded'- and 'Ord'.-- Also defines @'countryNameFromCode'@, which gives the- official short country name all in uppercase and- @'readableCountryName'@, which produces somewhat more user-friendly output-- Intended to be imported qualified as some country codes- are the same as some standard Haskell constructors.---}-module Data.ISO3166_CountryCodes- (CountryCode(..),- countryNameFromCode,- readableCountryName- ) where-import qualified Prelude as P-import Prelude ((.),not,(==),otherwise,(&&),(==),(/=))-import Control.Monad-import Data.Char-import Data.List--{- | A human readable version of the official name of a country- from its country code-- Uses some ad-hockery to rearrange the order of the words.---}-readableCountryName :: CountryCode -> String--readableCountryName- = concat . intersperse " " . rearrange . fmap up1 . words .- countryNameFromCode- where up1 [] = []- up1 (c:rest) | not (isAlpha c) = c:up1 rest- up1 "OF" = "of"- up1 "THE" = "the"- up1 "AND" = "and"- up1 "U.S." = "US" -- gawd- up1 ('M':'C':l) = "Mc"++up1 l -- Don't do MacEdonia!- -- but there are no Mac_ countries yet- up1 ('D':'\'':l) = "d'"++up1 l- up1 (c:cs) = toUpper c: downup cs- downup [] = [] -- needed for hyphenated names- downup (c:cs) | c=='-' = c:up1 cs- | otherwise = toLower c:downup cs- rearrange [] = []- rearrange [c] = [c]- rearrange ll@(n:l)- | last l `elem` ["of", "the"] && last n == ','- = onhead up1 l++[[c|c<-n,c/=',']]- | otherwise = ll- onhead f [] = []- onhead f (h:r) = f h:r-{- Copyright © 2010 Jón Fairbairn--}
− Data/ISO3166_CountryCodes/GenerateDataDeclaration.hs
@@ -1,67 +0,0 @@-{- | generate language code data type from the official list- downloaded from <http://www.iso.org/iso/iso3166_en_code_lists.txt>-- use the text version because it's easy to parse and the- xml version doesn't add anything, so I can avoid- depending on an xml library for the moment-- The code_lists file contains non-ASCII characters,- output (in the country names) and Haskell source is Unicode- the output here requires encoding to UTF-8, something that- Haskell IO ought to do itself.---}-module Main where-import Getter-import Data.Char-import Codec.Binary.UTF8.String-import Data.List--main- = do output_preamble- generate_country_codes--output_preamble- = readFile preamble >>= putStr--generate_country_codes- = do text <- fmap lines $- get_country_code_list- let codes = [(cc,name) |- l <- text,- let cc = filter (isAlpha) $- dropWhile (==';') $- dropWhile (/=';') $- l- name = takeWhile (/=';') l,- length cc == 2- ]- gen_data_decl codes- gen_alist_decl codes--gen_data_decl codes- = do putStrLn "data CountryCode = "- sequence_ $ fmap putStrLn $ intersperse " |" $ fmap country_alternative codes- putStrLn " deriving (P.Eq,P.Read,P.Show,P.Enum,P.Bounded,P.Ord)"--country_alternative (code, name)- = " "++code++" -- ^ " ++ encodeString name--gen_alist_decl codes- = do mapM_ putStrLn $- ["",- "{-|",- " convert a country code to the official (English) name of the country",- "",- " see @'readableCountryName'@ for something with a more pleasing word order and capitalisation",- "-}",- "countryNameFromCode:: CountryCode -> String"- ]- sequence_ $ fmap make_clause codes--make_clause (constr, countryName)- = putStrLn $ "countryNameFromCode " ++ constr ++ " = \"" ++ encodeString countryName ++ "\""--preamble = "Data/ISO3166_CountryCodes.preamble.hs"-{- Copyright © 2010 Jón Fairbairn--}
− Data/ISO3166_CountryCodes/Getter.hs
@@ -1,62 +0,0 @@-module Getter(get_country_code_list) where--{- This operates essentially as a single file http cache--}--import Network.HTTP-import System.Directory-import System.Time-import IO--country_code_URL = "http://www.iso.org/iso/iso3166_en_code_lists.txt"-local_copy = "Data/ISO3166_CountryCodes/iso3166_en_code_lists.txt"--last_modified_file = local_copy ++ ".last-modified"--{--most errors are handled by failing...---}--get_country_code_list- = do local_copy_date <- getSomeModificationTime- let r = getRequest country_code_URL- Right response <- simpleHTTP r{rqHeaders=Header HdrIfModifiedSince local_copy_date:getHeaders r}-- case rspCode response of- (3,0,4) -> do -- not modified since fetched- readFile local_copy- (2,0,0) -> do let content = rspBody response -- doesn't seem lazy enough- writeFile local_copy content- case [date| Header HdrLastModified date <- rspHeaders response] of- [d] -> do writeFile last_modified_file d- return content- _ -> error $ "unhandled HTTP response: " ++ show response--{---Using the file modification time might be better in some-ways, but we don't know whether the server holding the-source file implements if-modified-since correctly, so-storing the modification time returned by the server in its-own file is about as good as we can manage.--Besides, at time of writing Haskell's time manipulation is-in a mess.---}--getSomeModificationTime- = do already_here <- doesFileExist local_copy- last_modified_recorded <- doesFileExist last_modified_file- if already_here && last_modified_recorded -- we have a copy, but is it up to date?- then readFile last_modified_file- else return epoch -- this should be long enough ago to ensure a fetch--{- I originally used-epoch = "Thu, 1 Jan 1970 00:00:00 GMT"-but for some reason the server returns "not modified" if you do that---}-epoch = "Sat, 27 May 2000 08:12:00 GMT"-
− Makefile
@@ -1,32 +0,0 @@-all: Data/ISO3166_CountryCodes.o docs--Data/ISO3166_CountryCodes.hs: Data/ISO3166_CountryCodes/GenerateDataDeclaration Data/ISO3166_CountryCodes.preamble.hs- Data/ISO3166_CountryCodes/GenerateDataDeclaration > $@--Data/ISO3166_CountryCodes/GenerateDataDeclaration: Data/ISO3166_CountryCodes/GenerateDataDeclaration.hs- ghc --make -iData/ISO3166_CountryCodes $@--%.o: %.hs- ghc --make $<--.PHONY: docs--docs: Data/Documentation/haddock/ISO3166_CountryCodes.haddock--Data/Documentation/haddock/ISO3166_CountryCodes.haddock: Data/Documentation/haddock Data/ISO3166_CountryCodes.hs- haddock -o Data/Documentation/haddock -h\- --read-interface=http://www.haskell.org/ghc/docs/latest/html/libraries/base,/usr/share/doc/ghc/libraries/base/base.haddock \- --read-interface=http://www.haskell.org/ghc/docs/latest/html/libraries/haskell98,/usr/share/doc/ghc/libraries/haskell98/haskell98.haddock \- --read-interface=http://www.haskell.org/ghc/docs/latest/html/libraries/template-haskell/,/usr/share/doc/ghc/libraries/template-haskell/template-haskell.haddock \- --read-interface=http://www.haskell.org/ghc/docs/latest/html/libraries/time/,/usr/share/doc/ghc/libraries/time/time.haddock \- --read-interface=http://hackage.haskell.org/packages/archive/bytestring/0.9.1.4/doc/html/,/usr/share/doc/ghc/libraries/bytestring/bytestring.haddock \- --read-interface=http://hackage.haskell.org/packages/archive/containers/0.2.0.1/doc/html/,/usr/share/doc/ghc/libraries/containers/containers.haddock \- --dump-interface Data/Documentation/haddock/ISO3166_CountryCodes.haddock \- Data/ISO3166_CountryCodes.hs--Data/Documentation/haddock:- mkdir -p Data/Documentation/haddock--.PHONY: clean-clean:- rm -rf Data/*.hi Data/*.o Data/ISO3166_CountryCodes.hs Data/ISO3166_CountryCodes/*.hi Data/ISO3166_CountryCodes/*.o Data/ISO3166_CountryCodes/GenerateDataDeclaration Data/ISO3166_CountryCodes/iso3166_en_code_lists.txt Data/ISO3166_CountryCodes/iso3166_en_code_lists.txt.last-modified Data/Documentation/haddock
Setup.hs view
@@ -1,2 +1,2 @@-import Distribution.Make+import Distribution.Simple main = defaultMain
iso3166-country-codes.cabal view
@@ -1,7 +1,7 @@+Version: 0.20090527.1 Name: iso3166-country-codes-Version: 0.1 Cabal-Version: >= 1.6-Build-type: Make+Build-type: Simple License: LGPL License-File: COPYING.LESSER Author: Jón Fairbairn@@ -14,11 +14,12 @@ ISO 3166 country codes, and mappings from that type to the official name of the country. -Extra-source-files: Data/ISO3166_CountryCodes/GenerateDataDeclaration.hs, Data/ISO3166_CountryCodes/Getter.hs, Data/ISO3166_CountryCodes.preamble.hs, Makefile--extra-tmp-files: Data/ISO3166_CountryCodes.hs, Data/ISO3166_CountryCodes/GenerateDataDeclaration- Library- Build-Depends: base ==4.*, HTTP == 4000.*, utf8-string ==0.*+ Build-Depends: base ==4.* Exposed-modules: Data.ISO3166_CountryCodes +-- a full build depends on HTTP == 4000.*, utf8-string ==0.*++source-repository head+ type: darcs+ location: http://www.cl.cam.ac.uk/~jf15/ISO3166_CountryCodes/