From 7209668ca687851aa77eb13b98398e9f7fcb8786 Mon Sep 17 00:00:00 2001 From: Leo Dutra Date: Sat, 27 Nov 2021 19:34:15 -0300 Subject: [PATCH] stable --- src/countries.rs | 497 ++++++++++++++++++++++++----------------------- src/lib.rs | 108 +++++----- 2 files changed, 306 insertions(+), 299 deletions(-) diff --git a/src/countries.rs b/src/countries.rs index 523f80e..f9d77ec 100644 --- a/src/countries.rs +++ b/src/countries.rs @@ -4,254 +4,257 @@ use std::collections::HashMap; lazy_static! { // TODO UPDATE LIST pub (crate) static ref COUNTRIES: [Country; 246] = [ - Country { code: "AD", names: vec!["Andorra", "Andorran"] }, - Country { code: "AE", names: vec!["United Arab Emirates", "UAE", "Emirati"] }, - Country { code: "AF", names: vec!["Afghanistan", "Afghan"] }, - Country { code: "AG", names: vec!["Antigua and Barbuda", "Antiguan, Barbudan"] }, - Country { code: "AI", names: vec!["Anguilla", "Anguillian"] }, - Country { code: "AL", names: vec!["Albania", "Albanian"] }, - Country { code: "AM", names: vec!["Armenia", "Armenian"] }, - Country { code: "AN", names: vec!["Netherlands Antilles"] }, - Country { code: "AO", names: vec!["Angola", "Angolan"] }, - Country { code: "AQ", names: vec!["Antarctica", "Antarctican"] }, - Country { code: "AR", names: vec!["Argentina", "Argentine"] }, - Country { code: "AS", names: vec!["American Samoa", "American Samoan"] }, - Country { code: "AT", names: vec!["Austria", "Austrian"] }, - Country { code: "AU", names: vec!["Australia", "Australian"] }, - Country { code: "AW", names: vec!["Aruba", "Aruban"] }, - Country { code: "AX", names: vec!["Åland Islands", "Ålandish"] }, - Country { code: "AZ", names: vec!["Azerbaijan", "Azerbaijani"] }, - Country { code: "BA", names: vec!["Bosnia and Herzegovina", "Bosnian, Herzegovinian"] }, - Country { code: "BB", names: vec!["Barbados", "Barbadian"] }, - Country { code: "BD", names: vec!["Bangladesh", "Bangladeshi"] }, - Country { code: "BE", names: vec!["Belgium", "Belgian"] }, - Country { code: "BF", names: vec!["Burkina Faso", "Burkinabe"] }, - Country { code: "BG", names: vec!["Bulgaria", "Bulgarian"] }, - Country { code: "BH", names: vec!["Bahrain", "Bahraini"] }, - Country { code: "BI", names: vec!["Burundi", "Burundian"] }, - Country { code: "BJ", names: vec!["Benin", "Beninese"] }, - Country { code: "BM", names: vec!["Bermuda", "Bermudian"] }, - Country { code: "BN", names: vec!["Brunei Darussalam", "Bruneian"] }, - Country { code: "BO", names: vec!["Bolivia", "Bolivian"] }, - Country { code: "BR", names: vec!["Brazil", "Brazilian"] }, - Country { code: "BS", names: vec!["Bahamas", "Bahamian"] }, - Country { code: "BT", names: vec!["Bhutan", "Bhutanese"] }, - Country { code: "BV", names: vec!["Bouvet Island"] }, - Country { code: "BW", names: vec!["Botswana", "Motswana"] }, - Country { code: "BY", names: vec!["Belarus", "Belarusian"] }, - Country { code: "BZ", names: vec!["Belize", "Belizean"] }, - Country { code: "CA", names: vec!["Canada", "Canadian"] }, - Country { code: "CC", names: vec!["Cocos (Keeling) Islands", "Cocos Islander"] }, - Country { code: "CD", names: vec!["Congo, The Democratic Republic of the"] }, - Country { code: "CF", names: vec!["Central African Republic", "Central African"] }, - Country { code: "CG", names: vec!["Congo"] }, - Country { code: "CH", names: vec!["Switzerland", "Swiss"] }, - Country { code: "CI", names: vec!["Cote D'Ivoire", "Ivorian"] }, - Country { code: "CK", names: vec!["Cook Islands", "Cook Islander"] }, - Country { code: "CL", names: vec!["Chile", "Chilean"] }, - Country { code: "CM", names: vec!["Cameroon", "Cameroonian"] }, - Country { code: "CN", names: vec!["China", "Chinese"] }, - Country { code: "CO", names: vec!["Colombia", "Colombian"] }, - Country { code: "CR", names: vec!["Costa Rica", "Costa Rican"] }, - Country { code: "CU", names: vec!["Cuba", "Cuban"] }, - Country { code: "CV", names: vec!["Cape Verde", "Cape Verdian"] }, - Country { code: "CX", names: vec!["Christmas Island", "Christmas Islander"] }, - Country { code: "CY", names: vec!["Cyprus", "Cypriot"] }, - Country { code: "CZ", names: vec!["Czechia", "Czech Republic", "Czech"] }, - Country { code: "DE", names: vec!["Germany", "German"] }, - Country { code: "DJ", names: vec!["Djibouti"] }, - Country { code: "DK", names: vec!["Denmark", "Danish"] }, - Country { code: "DM", names: vec!["Dominica"] }, - Country { code: "DO", names: vec!["Dominican Republic"] }, - Country { code: "DZ", names: vec!["Algeria", "Algerian"] }, - Country { code: "EC", names: vec!["Ecuador", "Ecuadorean"] }, - Country { code: "EE", names: vec!["Estonia", "Estonian"] }, - Country { code: "EG", names: vec!["Egypt", "Egyptian"] }, - Country { code: "EH", names: vec!["Western Sahara", "Sahrawi"] }, - Country { code: "ER", names: vec!["Eritrea", "Eritrean"] }, - Country { code: "ES", names: vec!["Spain", "Spanish"] }, - Country { code: "ET", names: vec!["Ethiopia", "Ethiopian"] }, - Country { code: "EU", names: vec!["European Union"] }, - Country { code: "FI", names: vec!["Finland", "Finnish"] }, - Country { code: "FJ", names: vec!["Fiji", "Fijian"] }, - Country { code: "FK", names: vec!["Falkland Islands (Malvinas)", "Falkland Islander"] }, - Country { code: "FM", names: vec!["Micronesia, Federated States of", "Micronesian"] }, - Country { code: "FO", names: vec!["Faroe Islands", "Faroese"] }, - Country { code: "FR", names: vec!["France", "French"] }, - Country { code: "GA", names: vec!["Gabon", "Gabonese"] }, - Country { code: "GB", names: vec!["United Kingdom", "UK", "British"] }, - Country { code: "GD", names: vec!["Grenada", "Grenadian"] }, - Country { code: "GE", names: vec!["Georgia", "Georgian"] }, - Country { code: "GF", names: vec!["French Guiana", "Guianan"] }, - Country { code: "GG", names: vec!["Guernsey"] }, - Country { code: "GH", names: vec!["Ghana", "Ghanaian"] }, - Country { code: "GI", names: vec!["Gibraltar"] }, - Country { code: "GL", names: vec!["Greenland", "Greenlandic"] }, - Country { code: "GM", names: vec!["Gambia", "Gambian"] }, - Country { code: "GN", names: vec!["Guinea", "Guinean"] }, - Country { code: "GP", names: vec!["Guadeloupe", "Guadeloupian"] }, - Country { code: "GQ", names: vec!["Equatorial Guinea", "Equatorial Guinean"] }, - Country { code: "GR", names: vec!["Greece", "Greek"] }, - Country { code: "GS", names: vec!["South Georgia and the South Sandwich Islands", "South Georgian South Sandwich Islander"] }, - Country { code: "GT", names: vec!["Guatemala", "Guatemalan"] }, - Country { code: "GU", names: vec!["Guam", "Guamanian"] }, - Country { code: "GW", names: vec!["Guinea-Bissau", "Guinea-Bissauan"] }, - Country { code: "GY", names: vec!["Guyana", "Guyanese"] }, - Country { code: "HK", names: vec!["Hong Kong", "Hong Konger"] }, - Country { code: "HM", names: vec!["Heard Island and Mcdonald Islands", "Heard and McDonald Islander"] }, - Country { code: "HN", names: vec!["Honduras", "Honduran"] }, - Country { code: "HR", names: vec!["Croatia", "Croatian"] }, - Country { code: "HT", names: vec!["Haiti", "Haitian"] }, - Country { code: "HU", names: vec!["Hungary", "Hungarian"] }, - Country { code: "ID", names: vec!["Indonesia", "Indonesian"] }, - Country { code: "IE", names: vec!["Ireland", "Irish"] }, - Country { code: "IL", names: vec!["Israel", "Israeli"] }, - Country { code: "IM", names: vec!["Isle of Man", "Manx"] }, - Country { code: "IN", names: vec!["India", "Indian"] }, - Country { code: "IO", names: vec!["British Indian Ocean Territory"] }, - Country { code: "IQ", names: vec!["Iraq", "Iraqi"] }, - Country { code: "IR", names: vec!["Iran, Islamic Republic Of", "Iranian"] }, - Country { code: "IS", names: vec!["Iceland", "Icelander"] }, - Country { code: "IT", names: vec!["Italy", "Italian"] }, - Country { code: "JE", names: vec!["Jersey"] }, - Country { code: "JM", names: vec!["Jamaica", "Jamaican"] }, - Country { code: "JO", names: vec!["Jordan", "Jordanian"] }, - Country { code: "JP", names: vec!["Japan", "Japanese"] }, - Country { code: "KE", names: vec!["Kenya", "Kenyan"] }, - Country { code: "KG", names: vec!["Kyrgyzstan", "Kirghiz"] }, - Country { code: "KH", names: vec!["Cambodia", "Cambodian"] }, - Country { code: "KI", names: vec!["Kiribati", "I-Kiribati"] }, - Country { code: "KM", names: vec!["Comoros", "Comoran"] }, - Country { code: "KN", names: vec!["Saint Kitts and Nevis", "Kittitian or Nevisian"] }, - Country { code: "KP", names: vec!["Korea, Democratic People's Republic of", "North Korea", "North Korean", "DPRK"] }, - Country { code: "KR", names: vec!["Korea, Republic of", "South Korea", "South Korean"] }, - Country { code: "KW", names: vec!["Kuwait", "Kuwaiti"] }, - Country { code: "KY", names: vec!["Cayman Islands", "Caymanian"] }, - Country { code: "KZ", names: vec!["Kazakhstan", "Kazakhstani"] }, - Country { code: "LA", names: vec!["Lao People's Democratic Republic", "Laotian"] }, - Country { code: "LB", names: vec!["Lebanon", "Lebanese"] }, - Country { code: "LC", names: vec!["Saint Lucia", "Saint Lucian"] }, - Country { code: "LI", names: vec!["Liechtenstein", "Liechtensteiner"] }, - Country { code: "LK", names: vec!["Sri Lanka", "Sri Lankan"] }, - Country { code: "LR", names: vec!["Liberia", "Liberian"] }, - Country { code: "LS", names: vec!["Lesotho", "Mosotho"] }, - Country { code: "LT", names: vec!["Lithuania", "Lithuanian"] }, - Country { code: "LU", names: vec!["Luxembourg", "Luxembourger"] }, - Country { code: "LV", names: vec!["Latvia", "Latvian"] }, - Country { code: "LY", names: vec!["Libyan Arab Jamahiriya", "Libyan"] }, - Country { code: "MA", names: vec!["Morocco", "Moroccan"] }, - Country { code: "MC", names: vec!["Monaco", "Monegasque"] }, - Country { code: "MD", names: vec!["Moldova, Republic of", "Moldovan"] }, - Country { code: "ME", names: vec!["Montenegro", "Montenegrin"] }, - Country { code: "MG", names: vec!["Madagascar", "Malagasy"] }, - Country { code: "MH", names: vec!["Marshall Islands", "Marshallese"] }, - Country { code: "MK", names: vec!["Republic of North Macedonia", "North Macedonia", "Macedonia, The Former Yugoslav Republic of", "Macedonian"] }, - Country { code: "ML", names: vec!["Mali", "Malian"] }, - Country { code: "MM", names: vec!["Myanmar", "Burma", "Burmese"] }, - Country { code: "MN", names: vec!["Mongolia", "Mongolian"] }, - Country { code: "MO", names: vec!["Macao", "Macau", "Macanese"] }, - Country { code: "MP", names: vec!["Northern Mariana Islands"] }, - Country { code: "MQ", names: vec!["Martinique"] }, - Country { code: "MR", names: vec!["Mauritania", "Mauritanian"] }, - Country { code: "MS", names: vec!["Montserrat", "Montserratian"] }, - Country { code: "MT", names: vec!["Malta", "Maltese"] }, - Country { code: "MU", names: vec!["Mauritius", "Mauritian"] }, - Country { code: "MV", names: vec!["Maldives", "Maldivan"] }, - Country { code: "MW", names: vec!["Malawi", "Malawian"] }, - Country { code: "MX", names: vec!["Mexico", "Mexican"] }, - Country { code: "MY", names: vec!["Malaysia", "Malaysian"] }, - Country { code: "MZ", names: vec!["Mozambique", "Mozambican"] }, - Country { code: "NA", names: vec!["Namibia", "Namibian"] }, - Country { code: "NC", names: vec!["New Caledonia", "New Caledonian"] }, - Country { code: "NE", names: vec!["Niger", "Nigerien"] }, - Country { code: "NF", names: vec!["Norfolk Island", "Norfolk Islander"] }, - Country { code: "NG", names: vec!["Nigeria", "Nigerian"] }, - Country { code: "NI", names: vec!["Nicaragua", "Nicaraguan"] }, - Country { code: "NL", names: vec!["Netherlands", "Dutch"] }, - Country { code: "NO", names: vec!["Norway", "Norwegian"] }, - Country { code: "NP", names: vec!["Nepal", "Nepalese"] }, - Country { code: "NR", names: vec!["Nauru", "Nauruan"] }, - Country { code: "NU", names: vec!["Niue", "Niuean"] }, - Country { code: "NZ", names: vec!["New Zealand", "New Zealander"] }, - Country { code: "OM", names: vec!["Oman", "Omani"] }, - Country { code: "PA", names: vec!["Panama", "Panamanian"] }, - Country { code: "PE", names: vec!["Peru", "Peruvian"] }, - Country { code: "PF", names: vec!["French Polynesia", "French Polynesian"] }, - Country { code: "PG", names: vec!["Papua New Guinea", "Papua New Guinean"] }, - Country { code: "PH", names: vec!["Philippines", "Filipino"] }, - Country { code: "PK", names: vec!["Pakistan", "Pakistani"] }, - Country { code: "PL", names: vec!["Poland", "Polish"] }, - Country { code: "PM", names: vec!["Saint Pierre and Miquelon"] }, - Country { code: "PN", names: vec!["Pitcairn", "Pitcairn Islander"] }, - Country { code: "PR", names: vec!["Puerto Rico", "Puerto Rican"] }, - Country { code: "PS", names: vec!["Palestinian Territory, Occupied", "Palestine", "Palestinian"] }, - Country { code: "PT", names: vec!["Portugal", "Portuguese"] }, - Country { code: "PW", names: vec!["Palau", "Palauan"] }, - Country { code: "PY", names: vec!["Paraguay", "Paraguayan"] }, - Country { code: "QA", names: vec!["Qatar", "Qatari"] }, - Country { code: "RE", names: vec!["Reunion"] }, - Country { code: "RO", names: vec!["Romania", "Romanian"] }, - Country { code: "RS", names: vec!["Serbia", "Serbian"] }, - Country { code: "RU", names: vec!["Russian Federation", "Russian"] }, - Country { code: "RW", names: vec!["Rwanda", "Rwandan"] }, - Country { code: "SA", names: vec!["Saudi Arabia", "Saudi Arabian"] }, - Country { code: "SB", names: vec!["Solomon Islands", "Solomon Islander"] }, - Country { code: "SC", names: vec!["Seychelles", "Seychellois"] }, - Country { code: "SD", names: vec!["Sudan", "Sudanese"] }, - Country { code: "SE", names: vec!["Sweden", "Swedish"] }, - Country { code: "SG", names: vec!["Singapore", "Singaporean"] }, - Country { code: "SH", names: vec!["Saint Helena", "Saint Helenian"] }, - Country { code: "SI", names: vec!["Slovenia", "Slovene"] }, - Country { code: "SJ", names: vec!["Svalbard and Jan Mayen"] }, - Country { code: "SK", names: vec!["Slovakia", "Slovak"] }, - Country { code: "SL", names: vec!["Sierra Leone", "Sierra Leonean"] }, - Country { code: "SM", names: vec!["San Marino", "Sammarinese"] }, - Country { code: "SN", names: vec!["Senegal", "Senegalese"] }, - Country { code: "SO", names: vec!["Somalia", "Somali"] }, - Country { code: "SR", names: vec!["Suriname", "Surinamer"] }, - Country { code: "ST", names: vec!["Sao Tome and Principe", "Sao Tomean"] }, - Country { code: "SV", names: vec!["El Salvador", "Salvadoran"] }, - Country { code: "SY", names: vec!["Syrian Arab Republic", "Syrian"] }, - Country { code: "SZ", names: vec!["Swaziland", "Swazi"] }, - Country { code: "TC", names: vec!["Turks and Caicos Islands", "Turks and Caicos Islander"] }, - Country { code: "TD", names: vec!["Chad", "Chadian"] }, - Country { code: "TF", names: vec!["French Southern Territories"] }, - Country { code: "TG", names: vec!["Togo", "Togolese"] }, - Country { code: "TH", names: vec!["Thailand", "Thai"] }, - Country { code: "TJ", names: vec!["Tajikistan", "Tadzhik"] }, - Country { code: "TK", names: vec!["Tokelau", "Tokelauan"] }, - Country { code: "TL", names: vec!["Timor-Leste", "East Timorese"] }, - Country { code: "TM", names: vec!["Turkmenistan", "Turkmen"] }, - Country { code: "TN", names: vec!["Tunisia", "Tunisian"] }, - Country { code: "TO", names: vec!["Tonga", "Tongan"] }, - Country { code: "TR", names: vec!["Turkey", "Turkish"] }, - Country { code: "TT", names: vec!["Trinidad and Tobago", "Trinidadian"] }, - Country { code: "TV", names: vec!["Tuvalu", "Tuvaluan"] }, - Country { code: "TW", names: vec!["Taiwan", "Taiwanese"] }, - Country { code: "TZ", names: vec!["Tanzania, United Republic of", "Tanzanian"] }, - Country { code: "UA", names: vec!["Ukraine", "Ukrainian"] }, - Country { code: "UG", names: vec!["Uganda", "Ugandan"] }, - Country { code: "UM", names: vec!["United States Minor Outlying Islands"] }, - Country { code: "US", names: vec!["United States", "USA", "American"] }, - Country { code: "UY", names: vec!["Uruguay", "Uruguayan"] }, - Country { code: "UZ", names: vec!["Uzbekistan", "Uzbekistani"] }, - Country { code: "VA", names: vec!["Holy See (Vatican City State)", "Vatican"] }, - Country { code: "VC", names: vec!["Saint Vincent and the Grenadines", "Saint Vincentian"] }, - Country { code: "VE", names: vec!["Venezuela", "Venezuelan"] }, - Country { code: "VG", names: vec!["Virgin Islands, British"] }, - Country { code: "VI", names: vec!["Virgin Islands, U.S."] }, - Country { code: "VN", names: vec!["Vietnam", "Viet Nam", "Vietnamese"] }, - Country { code: "VU", names: vec!["Vanuatu", "Ni-Vanuatu"] }, - Country { code: "WF", names: vec!["Wallis and Futuna", "Wallis and Futuna Islander"] }, - Country { code: "WS", names: vec!["Samoa", "Samoan"] }, - Country { code: "XK", names: vec!["Kosovo", "Kosovar"] }, - Country { code: "YE", names: vec!["Yemen", "Yemeni"] }, - Country { code: "YT", names: vec!["Mayotte", "Mahoran"] }, - Country { code: "ZA", names: vec!["South Africa", "South African"] }, - Country { code: "ZM", names: vec!["Zambia", "Zambian"] }, - Country { code: "ZW", names: vec!["Zimbabwe", "Zimbabwean"] }, + Country::new("AD", vec!["Andorra", "Andorran"] ), + Country::new("AE", vec!["United Arab Emirates", "UAE", "Emirati"] ), + Country::new("AF", vec!["Afghanistan", "Afghan"] ), + Country::new("AG", vec!["Antigua and Barbuda", "Antiguan, Barbudan"] ), + Country::new("AI", vec!["Anguilla", "Anguillian"] ), + Country::new("AL", vec!["Albania", "Albanian"] ), + Country::new("AM", vec!["Armenia", "Armenian"] ), + Country::new("AN", vec!["Netherlands Antilles"] ), + Country::new("AO", vec!["Angola", "Angolan"] ), + Country::new("AQ", vec!["Antarctica", "Antarctican"] ), + Country::new("AR", vec!["Argentina", "Argentine"] ), + Country::new("AS", vec!["American Samoa", "American Samoan"] ), + Country::new("AT", vec!["Austria", "Austrian"] ), + Country::new("AU", vec!["Australia", "Australian"] ), + Country::new("AW", vec!["Aruba", "Aruban"] ), + Country::new("AX", vec!["Åland Islands", "Ålandish"] ), + Country::new("AZ", vec!["Azerbaijan", "Azerbaijani"] ), + Country::new("BA", vec!["Bosnia and Herzegovina", "Bosnian, Herzegovinian"] ), + Country::new("BB", vec!["Barbados", "Barbadian"] ), + Country::new("BD", vec!["Bangladesh", "Bangladeshi"] ), + Country::new("BE", vec!["Belgium", "Belgian"] ), + Country::new("BF", vec!["Burkina Faso", "Burkinabe"] ), + Country::new("BG", vec!["Bulgaria", "Bulgarian"] ), + Country::new("BH", vec!["Bahrain", "Bahraini"] ), + Country::new("BI", vec!["Burundi", "Burundian"] ), + Country::new("BJ", vec!["Benin", "Beninese"] ), + Country::new("BM", vec!["Bermuda", "Bermudian"] ), + Country::new("BN", vec!["Brunei Darussalam", "Bruneian"] ), + Country::new("BO", vec!["Bolivia", "Bolivian"] ), + Country::new("BR", vec!["Brazil", "Brazilian"] ), + Country::new("BS", vec!["Bahamas", "Bahamian"] ), + Country::new("BT", vec!["Bhutan", "Bhutanese"] ), + Country::new("BV", vec!["Bouvet Island"] ), + Country::new("BW", vec!["Botswana", "Motswana"] ), + Country::new("BY", vec!["Belarus", "Belarusian"] ), + Country::new("BZ", vec!["Belize", "Belizean"] ), + Country::new("CA", vec!["Canada", "Canadian"] ), + Country::new("CC", vec!["Cocos (Keeling) Islands", "Cocos Islander"] ), + Country::new("CD", vec!["Congo, The Democratic Republic of the"] ), + Country::new("CF", vec!["Central African Republic", "Central African"] ), + Country::new("CG", vec!["Congo"] ), + Country::new("CH", vec!["Switzerland", "Swiss"] ), + Country::new("CI", vec!["Cote D'Ivoire", "Ivorian"] ), + Country::new("CK", vec!["Cook Islands", "Cook Islander"] ), + Country::new("CL", vec!["Chile", "Chilean"] ), + Country::new("CM", vec!["Cameroon", "Cameroonian"] ), + Country::new("CN", vec!["China", "Chinese"] ), + Country::new("CO", vec!["Colombia", "Colombian"] ), + Country::new("CR", vec!["Costa Rica", "Costa Rican"] ), + Country::new("CU", vec!["Cuba", "Cuban"] ), + Country::new("CV", vec!["Cape Verde", "Cape Verdian"] ), + Country::new("CX", vec!["Christmas Island", "Christmas Islander"] ), + Country::new("CY", vec!["Cyprus", "Cypriot"] ), + Country::new("CZ", vec!["Czechia", "Czech Republic", "Czech"] ), + Country::new("DE", vec!["Germany", "German"] ), + Country::new("DJ", vec!["Djibouti"] ), + Country::new("DK", vec!["Denmark", "Danish"] ), + Country::new("DM", vec!["Dominica"] ), + Country::new("DO", vec!["Dominican Republic"] ), + Country::new("DZ", vec!["Algeria", "Algerian"] ), + Country::new("EC", vec!["Ecuador", "Ecuadorean"] ), + Country::new("EE", vec!["Estonia", "Estonian"] ), + Country::new("EG", vec!["Egypt", "Egyptian"] ), + Country::new("EH", vec!["Western Sahara", "Sahrawi"] ), + Country::new("ER", vec!["Eritrea", "Eritrean"] ), + Country::new("ES", vec!["Spain", "Spanish"] ), + Country::new("ET", vec!["Ethiopia", "Ethiopian"] ), + Country::new("EU", vec!["European Union"] ), + Country::new("FI", vec!["Finland", "Finnish"] ), + Country::new("FJ", vec!["Fiji", "Fijian"] ), + Country::new("FK", vec!["Falkland Islands (Malvinas)", "Falkland Islander"] ), + Country::new("FM", vec!["Micronesia, Federated States of", "Micronesian"] ), + Country::new("FO", vec!["Faroe Islands", "Faroese"] ), + Country::new("FR", vec!["France", "French"] ), + Country::new("GA", vec!["Gabon", "Gabonese"] ), + Country::new("GB", vec!["United Kingdom", "UK", "British"] ), + Country::new("GD", vec!["Grenada", "Grenadian"] ), + Country::new("GE", vec!["Georgia", "Georgian"] ), + Country::new("GF", vec!["French Guiana", "Guianan"] ), + Country::new("GG", vec!["Guernsey"] ), + Country::new("GH", vec!["Ghana", "Ghanaian"] ), + Country::new("GI", vec!["Gibraltar"] ), + Country::new("GL", vec!["Greenland", "Greenlandic"] ), + Country::new("GM", vec!["Gambia", "Gambian"] ), + Country::new("GN", vec!["Guinea", "Guinean"] ), + Country::new("GP", vec!["Guadeloupe", "Guadeloupian"] ), + Country::new("GQ", vec!["Equatorial Guinea", "Equatorial Guinean"] ), + Country::new("GR", vec!["Greece", "Greek"] ), + Country::new("GS", vec!["South Georgia and the South Sandwich Islands", "South Georgian South Sandwich Islander"] ), + Country::new("GT", vec!["Guatemala", "Guatemalan"] ), + Country::new("GU", vec!["Guam", "Guamanian"] ), + Country::new("GW", vec!["Guinea-Bissau", "Guinea-Bissauan"] ), + Country::new("GY", vec!["Guyana", "Guyanese"] ), + Country::new("HK", vec!["Hong Kong", "Hong Konger"] ), + Country::new("HM", vec!["Heard Island and Mcdonald Islands", "Heard and McDonald Islander"] ), + Country::new("HN", vec!["Honduras", "Honduran"] ), + Country::new("HR", vec!["Croatia", "Croatian"] ), + Country::new("HT", vec!["Haiti", "Haitian"] ), + Country::new("HU", vec!["Hungary", "Hungarian"] ), + Country::new("ID", vec!["Indonesia", "Indonesian"] ), + Country::new("IE", vec!["Ireland", "Irish"] ), + Country::new("IL", vec!["Israel", "Israeli"] ), + Country::new("IM", vec!["Isle of Man", "Manx"] ), + Country::new("IN", vec!["India", "Indian"] ), + Country::new("IO", vec!["British Indian Ocean Territory"] ), + Country::new("IQ", vec!["Iraq", "Iraqi"] ), + Country::new("IR", vec!["Iran, Islamic Republic Of", "Iranian"] ), + Country::new("IS", vec!["Iceland", "Icelander"] ), + Country::new("IT", vec!["Italy", "Italian"] ), + Country::new("JE", vec!["Jersey"] ), + Country::new("JM", vec!["Jamaica", "Jamaican"] ), + Country::new("JO", vec!["Jordan", "Jordanian"] ), + Country::new("JP", vec!["Japan", "Japanese"] ), + Country::new("KE", vec!["Kenya", "Kenyan"] ), + Country::new("KG", vec!["Kyrgyzstan", "Kirghiz"] ), + Country::new("KH", vec!["Cambodia", "Cambodian"] ), + Country::new("KI", vec!["Kiribati", "I-Kiribati"] ), + Country::new("KM", vec!["Comoros", "Comoran"] ), + Country::new("KN", vec!["Saint Kitts and Nevis", "Kittitian or Nevisian"] ), + Country::new("KP", vec!["Korea, Democratic People's Republic of", "North Korea", "North Korean", "DPRK"] ), + Country::new("KR", vec!["Korea, Republic of", "South Korea", "South Korean"] ), + Country::new("KW", vec!["Kuwait", "Kuwaiti"] ), + Country::new("KY", vec!["Cayman Islands", "Caymanian"] ), + Country::new("KZ", vec!["Kazakhstan", "Kazakhstani"] ), + Country::new("LA", vec!["Lao People's Democratic Republic", "Laotian"] ), + Country::new("LB", vec!["Lebanon", "Lebanese"] ), + Country::new("LC", vec!["Saint Lucia", "Saint Lucian"] ), + Country::new("LI", vec!["Liechtenstein", "Liechtensteiner"] ), + Country::new("LK", vec!["Sri Lanka", "Sri Lankan"] ), + Country::new("LR", vec!["Liberia", "Liberian"] ), + Country::new("LS", vec!["Lesotho", "Mosotho"] ), + Country::new("LT", vec!["Lithuania", "Lithuanian"] ), + Country::new("LU", vec!["Luxembourg", "Luxembourger"] ), + Country::new("LV", vec!["Latvia", "Latvian"] ), + Country::new("LY", vec!["Libyan Arab Jamahiriya", "Libyan"] ), + Country::new("MA", vec!["Morocco", "Moroccan"] ), + Country::new("MC", vec!["Monaco", "Monegasque"] ), + Country::new("MD", vec!["Moldova, Republic of", "Moldovan"] ), + Country::new("ME", vec!["Montenegro", "Montenegrin"] ), + Country::new("MG", vec!["Madagascar", "Malagasy"] ), + Country::new("MH", vec!["Marshall Islands", "Marshallese"] ), + Country::new("MK", vec!["Republic of North Macedonia", "North Macedonia", "Macedonia, The Former Yugoslav Republic of", "Macedonian"] ), + Country::new("ML", vec!["Mali", "Malian"] ), + Country::new("MM", vec!["Myanmar", "Burma", "Burmese"] ), + Country::new("MN", vec!["Mongolia", "Mongolian"] ), + Country::new("MO", vec!["Macao", "Macau", "Macanese"] ), + Country::new("MP", vec!["Northern Mariana Islands"] ), + Country::new("MQ", vec!["Martinique"] ), + Country::new("MR", vec!["Mauritania", "Mauritanian"] ), + Country::new("MS", vec!["Montserrat", "Montserratian"] ), + Country::new("MT", vec!["Malta", "Maltese"] ), + Country::new("MU", vec!["Mauritius", "Mauritian"] ), + Country::new("MV", vec!["Maldives", "Maldivan"] ), + Country::new("MW", vec!["Malawi", "Malawian"] ), + Country::new("MX", vec!["Mexico", "Mexican"] ), + Country::new("MY", vec!["Malaysia", "Malaysian"] ), + Country::new("MZ", vec!["Mozambique", "Mozambican"] ), + Country::new("NA", vec!["Namibia", "Namibian"] ), + Country::new("NC", vec!["New Caledonia", "New Caledonian"] ), + Country::new("NE", vec!["Niger", "Nigerien"] ), + Country::new("NF", vec!["Norfolk Island", "Norfolk Islander"] ), + Country::new("NG", vec!["Nigeria", "Nigerian"] ), + Country::new("NI", vec!["Nicaragua", "Nicaraguan"] ), + Country::new("NL", vec!["Netherlands", "Dutch"] ), + Country::new("NO", vec!["Norway", "Norwegian"] ), + Country::new("NP", vec!["Nepal", "Nepalese"] ), + Country::new("NR", vec!["Nauru", "Nauruan"] ), + Country::new("NU", vec!["Niue", "Niuean"] ), + Country::new("NZ", vec!["New Zealand", "New Zealander"] ), + Country::new("OM", vec!["Oman", "Omani"] ), + Country::new("PA", vec!["Panama", "Panamanian"] ), + Country::new("PE", vec!["Peru", "Peruvian"] ), + Country::new("PF", vec!["French Polynesia", "French Polynesian"] ), + Country::new("PG", vec!["Papua New Guinea", "Papua New Guinean"] ), + Country::new("PH", vec!["Philippines", "Filipino"] ), + Country::new("PK", vec!["Pakistan", "Pakistani"] ), + Country::new("PL", vec!["Poland", "Polish"] ), + Country::new("PM", vec!["Saint Pierre and Miquelon"] ), + Country::new("PN", vec!["Pitcairn", "Pitcairn Islander"] ), + Country::new("PR", vec!["Puerto Rico", "Puerto Rican"] ), + Country::new("PS", vec!["Palestinian Territory, Occupied", "Palestine", "Palestinian"] ), + Country::new("PT", vec!["Portugal", "Portuguese"] ), + Country::new("PW", vec!["Palau", "Palauan"] ), + Country::new("PY", vec!["Paraguay", "Paraguayan"] ), + Country::new("QA", vec!["Qatar", "Qatari"] ), + Country::new("RE", vec!["Reunion"] ), + Country::new("RO", vec!["Romania", "Romanian"] ), + Country::new("RS", vec!["Serbia", "Serbian"] ), + Country::new("RU", vec!["Russian Federation", "Russian"] ), + Country::new("RW", vec!["Rwanda", "Rwandan"] ), + Country::new("SA", vec!["Saudi Arabia", "Saudi Arabian"] ), + Country::new("SB", vec!["Solomon Islands", "Solomon Islander"] ), + Country::new("SC", vec!["Seychelles", "Seychellois"] ), + Country::new("SD", vec!["Sudan", "Sudanese"] ), + Country::new("SE", vec!["Sweden", "Swedish"] ), + Country::new("SG", vec!["Singapore", "Singaporean"] ), + Country::new("SH", vec!["Saint Helena", "Saint Helenian"] ), + Country::new("SI", vec!["Slovenia", "Slovene"] ), + Country::new("SJ", vec!["Svalbard and Jan Mayen"] ), + Country::new("SK", vec!["Slovakia", "Slovak"] ), + Country::new("SL", vec!["Sierra Leone", "Sierra Leonean"] ), + Country::new("SM", vec!["San Marino", "Sammarinese"] ), + Country::new("SN", vec!["Senegal", "Senegalese"] ), + Country::new("SO", vec!["Somalia", "Somali"] ), + Country::new("SR", vec!["Suriname", "Surinamer"] ), + Country::new("ST", vec!["Sao Tome and Principe", "Sao Tomean"] ), + Country::new("SV", vec!["El Salvador", "Salvadoran"] ), + Country::new("SY", vec!["Syrian Arab Republic", "Syrian"] ), + Country::new("SZ", vec!["Swaziland", "Swazi"] ), + Country::new("TC", vec!["Turks and Caicos Islands", "Turks and Caicos Islander"] ), + Country::new("TD", vec!["Chad", "Chadian"] ), + Country::new("TF", vec!["French Southern Territories"] ), + Country::new("TG", vec!["Togo", "Togolese"] ), + Country::new("TH", vec!["Thailand", "Thai"] ), + Country::new("TJ", vec!["Tajikistan", "Tadzhik"] ), + Country::new("TK", vec!["Tokelau", "Tokelauan"] ), + Country::new("TL", vec!["Timor-Leste", "East Timorese"] ), + Country::new("TM", vec!["Turkmenistan", "Turkmen"] ), + Country::new("TN", vec!["Tunisia", "Tunisian"] ), + Country::new("TO", vec!["Tonga", "Tongan"] ), + Country::new("TR", vec!["Turkey", "Turkish"] ), + Country::new("TT", vec!["Trinidad and Tobago", "Trinidadian"] ), + Country::new("TV", vec!["Tuvalu", "Tuvaluan"] ), + Country::new("TW", vec!["Taiwan", "Taiwanese"] ), + Country::new("TZ", vec!["Tanzania, United Republic of", "Tanzanian"] ), + Country::new("UA", vec!["Ukraine", "Ukrainian"] ), + Country::new("UG", vec!["Uganda", "Ugandan"] ), + Country::new("UM", vec!["United States Minor Outlying Islands"] ), + Country::new("US", vec!["United States", "USA", "American"] ), + Country::new("UY", vec!["Uruguay", "Uruguayan"] ), + Country::new("UZ", vec!["Uzbekistan", "Uzbekistani"] ), + Country::new("VA", vec!["Holy See (Vatican City State)", "Vatican"] ), + Country::new("VC", vec!["Saint Vincent and the Grenadines", "Saint Vincentian"] ), + Country::new("VE", vec!["Venezuela", "Venezuelan"] ), + Country::new("VG", vec!["Virgin Islands, British"] ), + Country::new("VI", vec!["Virgin Islands, U.S."] ), + Country::new("VN", vec!["Vietnam", "Viet Nam", "Vietnamese"] ), + Country::new("VU", vec!["Vanuatu", "Ni-Vanuatu"] ), + Country::new("WF", vec!["Wallis and Futuna", "Wallis and Futuna Islander"] ), + Country::new("WS", vec!["Samoa", "Samoan"] ), + Country::new("XK", vec!["Kosovo", "Kosovar"] ), + Country::new("YE", vec!["Yemen", "Yemeni"] ), + Country::new("YT", vec!["Mayotte", "Mahoran"] ), + Country::new("ZA", vec!["South Africa", "South African"] ), + Country::new("ZM", vec!["Zambia", "Zambian"] ), + Country::new("ZW", vec!["Zimbabwe", "Zimbabwean"] ), ]; - pub (crate) static ref COUNTRIES_MAP: HashMap<&'static str, &'static Country> = + pub (crate) static ref COUNTRIES_CODE_MAP: HashMap<&'static str, &'static Country> = COUNTRIES.iter().map(|country| (country.code, country)).collect(); + + pub (crate) static ref COUNTRIES_FLAG_MAP: HashMap<&'static str, &'static Country> = + COUNTRIES.iter().map(|country| (country.flag.as_str(), country)).collect(); } diff --git a/src/lib.rs b/src/lib.rs index 8b7dabb..67971d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,25 +5,61 @@ extern crate lazy_static; mod countries; +use countries::{COUNTRIES, COUNTRIES_CODE_MAP, COUNTRIES_FLAG_MAP}; -use countries::{COUNTRIES, COUNTRIES_MAP}; -use regex::Regex; +const FLAG_MAGIC_NUMBER: u32 = 127462 - 65; -const FLAG_MAGIC_NUMBER: u32 = 127397; +fn trim_upper(text: &str) -> String { + text.trim().to_uppercase() +} -lazy_static! { - static ref FLAG_RE: Regex = Regex::new(r"^[\u{0001F1E6}-\u{0001F1FF}]{2}$").unwrap(); - static ref CODE_RE: Regex = Regex::new(r"^(?i)[a-z]{2}$").unwrap(); +pub(crate) fn internal_code_to_flag(code: &'static str) -> String { + let mut flag = String::new(); + for c in trim_upper(code).chars() { + if let Some(c) = std::char::from_u32(c as u32 + FLAG_MAGIC_NUMBER) { + flag.push(c); + } else { + panic!("Could not convert code \"{}\" to flag", code); + } + } + flag +} + +fn check_by_code(code: &str) -> bool { + COUNTRIES_CODE_MAP.contains_key(trim_upper(code).as_str()) +} + +fn get_by_code(code: &str) -> Option<&'static Country> { + COUNTRIES_CODE_MAP + .get(trim_upper(code).as_str()) + .map(|x| *x) +} + +fn check_by_flag(flag: &str) -> bool { + COUNTRIES_CODE_MAP.contains_key(flag.trim()) +} + +fn get_by_flag(flag: &str) -> Option<&'static Country> { + COUNTRIES_FLAG_MAP.get(flag.trim()).map(|x| *x) } #[derive(Clone)] pub(crate) struct Country { code: &'static str, + flag: String, names: Vec<&'static str>, } impl Country { - pub fn name(&self) -> &'static str { + pub(crate) fn new(code: &'static str, names: Vec<&'static str>) -> Self { + Country { + code, + names, + flag: internal_code_to_flag(code), + } + } + + pub(crate) fn name(&self) -> &'static str { self.names[0] } } @@ -33,78 +69,46 @@ pub fn code(input: &str) -> Option<&'static str> { } pub fn flag(mut input: &str) -> Option { - if !CODE_RE.is_match(input) || input == "UK" { - if let Some(code) = name_to_code(input) { - input = code; - } + if let Some(code) = name_to_code(input) { + input = code; } code_to_flag(input) } pub fn name(mut input: &str) -> Option<&'static str> { - if FLAG_RE.is_match(input) { - if let Some(code) = flag_to_code(input) { - input = code; - } + if let Some(code) = flag_to_code(input) { + input = code; } code_to_name(input) } pub fn is_code(code: Option<&str>) -> bool { - code.map_or(false, |code| { - COUNTRIES_MAP.contains_key(code.trim().to_uppercase().as_str()) - }) + code.map_or(false, check_by_code) } pub fn code_to_name(code: &str) -> Option<&'static str> { - COUNTRIES_MAP - .get(code.trim().to_uppercase().as_str()) - .map(|country| country.name()) + get_by_code(code).map(|country| country.name()) } pub fn code_to_flag(code: &str) -> Option { - if is_code(Some(code)) { - let mut flag = String::new(); - for c in code.chars() { - if let Some(c) = std::char::from_u32(c as u32 + FLAG_MAGIC_NUMBER) { - flag.push(c); - } else { - return None; - } - } - Some(flag) - } else { - None - } + get_by_code(code).map(|country| country.flag.clone()) } pub fn is_country_flag(flag: &str) -> bool { - FLAG_RE.is_match(flag) + check_by_flag(flag) } pub fn flag_to_code(flag: &str) -> Option<&'static str> { - let flag = flag.trim(); - if !is_country_flag(flag) { - return None; - } - let mut code = String::new(); - for c in flag.chars() { - if let Some(c) = std::char::from_u32(c as u32 - FLAG_MAGIC_NUMBER) { - code.push(c); - } else { - return None; - } - } - COUNTRIES_MAP.get(code.as_str()).map(|country| country.code) + get_by_flag(flag).map(|country| country.code) } pub fn name_to_code(name: &str) -> Option<&'static str> { - let name = name.trim().to_lowercase(); + let name = trim_upper(name); // exact match lookup for country in COUNTRIES.iter() { for n in &country.names { - if n.to_lowercase() == name { + if n.to_uppercase() == name { return Some(country.code); } } @@ -121,7 +125,7 @@ pub fn name_to_code(name: &str) -> Option<&'static str> { }); // Return only when exactly one match was found - // prevents cases like "United" + // prevents cases like "United" if matches.len() == 1 { Some(matches[0]) } else { @@ -130,7 +134,7 @@ pub fn name_to_code(name: &str) -> Option<&'static str> { } fn fuzzy_compare(input: &str, name: &str) -> bool { - let name = name.to_lowercase(); + let name = name.to_uppercase(); // Cases like: // "Vatican" <-> "Holy See (Vatican City State)"