00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include <map>
00014
00015 #include "zypp/base/Logger.h"
00016 #include "zypp/base/String.h"
00017 #include "zypp/base/Gettext.h"
00018
00019 #include "zypp/CountryCode.h"
00020
00021 using std::endl;
00022
00024 namespace zypp
00025 {
00026
00028 namespace
00029 {
00030
00032 struct CodeMaps
00033 {
00034 typedef std::map<std::string,std::string> CodeMap;
00035 typedef CodeMap::const_iterator Index;
00036
00038 static Index getIndex( const std::string & code_r )
00039 {
00040 static CodeMaps _maps;
00041 return _maps.lookup( code_r );
00042 }
00043
00044 private:
00048 CodeMaps();
00049
00051 inline Index lookup( const std::string & code_r );
00052
00054 inline Index lookupCode( const std::string & code_r );
00055
00056 private:
00058 CodeMap iso3166;
00060 CodeMap others;
00061 };
00062
00063 inline CodeMaps::Index CodeMaps::lookupCode( const std::string & code_r )
00064 {
00065 switch ( code_r.size() )
00066 {
00067 case 2:
00068 {
00069 Index it = iso3166.find( code_r );
00070 if ( it != iso3166.end() )
00071 return it;
00072 }
00073 break;
00074 }
00075
00076
00077 return others.find( code_r );
00078 }
00079
00080 inline CodeMaps::Index CodeMaps::lookup( const std::string & code_r )
00081 {
00082 Index it = lookupCode( code_r );
00083 if ( it != others.end() )
00084 return it;
00085
00086
00087 CodeMap::value_type nval( code_r, std::string() );
00088
00089 if ( code_r.size() != 2 )
00090 WAR << "Malformed CountryCode '" << code_r << "' (expect 2-letter)" << endl;
00091
00092 std::string lcode( str::toUpper( code_r ) );
00093 if ( lcode != code_r )
00094 {
00095 WAR << "Malformed CountryCode '" << code_r << "' (not upper case)" << endl;
00096
00097
00098 it = lookupCode( lcode );
00099 if ( it != others.end() )
00100 nval.second = it->second;
00101 }
00102
00103 MIL << "Remember CountryCode '" << code_r << "': '" << nval.second << "'" << endl;
00104 return others.insert( nval ).first;
00105 }
00106
00108 }
00110
00112
00113
00114
00119 struct CountryCode::Impl
00120 {
00121 Impl()
00122 : _index( CodeMaps::getIndex( std::string() ) )
00123 {}
00124
00125 Impl( const std::string & code_r )
00126 : _index( CodeMaps::getIndex( code_r ) )
00127 {}
00128
00129 std::string code() const
00130 { return _index->first; }
00131
00132 std::string name() const {
00133 if ( _index->second.empty() )
00134 {
00135 std::string ret( _("Unknown country: ") );
00136 ret += "'";
00137 ret += _index->first;
00138 ret += "'";
00139 return ret;
00140 }
00141 return _( _index->second.c_str() );
00142 }
00143
00144 private:
00146 CodeMaps::Index _index;
00147
00148 public:
00150 static shared_ptr<Impl> nullimpl()
00151 {
00152 static shared_ptr<Impl> _nullimpl( new Impl );
00153 return _nullimpl;
00154 }
00155 };
00157
00159
00160
00161
00163
00164 const CountryCode CountryCode::noCode;
00165
00167
00168
00169
00170
00171 CountryCode::CountryCode()
00172 : _pimpl( Impl::nullimpl() )
00173 {}
00174
00176
00177
00178
00179
00180 CountryCode::CountryCode( const std::string & code_r )
00181 : _pimpl( new Impl( code_r ) )
00182 {}
00183
00185
00186
00187
00188
00189 CountryCode::~CountryCode()
00190 {}
00191
00193
00194
00195
00196
00197 std::string CountryCode::code() const
00198 { return _pimpl->code(); }
00199
00201
00202
00203
00204
00205 std::string CountryCode::name() const
00206 { return _pimpl->name(); }
00207
00209 namespace
00210 {
00211
00212 CodeMaps::CodeMaps()
00213 {
00214
00215 others[""] = N_( "noCode" );
00216
00217 iso3166["AD"] = N_( "Andorra" );
00218 iso3166["AE"] = N_( "United Arab Emirates" );
00219 iso3166["AF"] = N_( "Afghanistan" );
00220 iso3166["AG"] = N_( "Antigua and Barbuda" );
00221 iso3166["AI"] = N_( "Anguilla" );
00222 iso3166["AL"] = N_( "Albania" );
00223 iso3166["AM"] = N_( "Armenia" );
00224 iso3166["AN"] = N_( "Netherlands Antilles" );
00225 iso3166["AO"] = N_( "Angola" );
00226 iso3166["AQ"] = N_( "Antarctica" );
00227 iso3166["AR"] = N_( "Argentina" );
00228 iso3166["AS"] = N_( "American Samoa" );
00229 iso3166["AT"] = N_( "Austria" );
00230 iso3166["AU"] = N_( "Australia" );
00231 iso3166["AW"] = N_( "Aruba" );
00232 iso3166["AX"] = N_( "Aland Islands" );
00233 iso3166["AZ"] = N_( "Azerbaijan" );
00234 iso3166["BA"] = N_( "Bosnia and Herzegovina" );
00235 iso3166["BB"] = N_( "Barbados" );
00236 iso3166["BD"] = N_( "Bangladesh" );
00237 iso3166["BE"] = N_( "Belgium" );
00238 iso3166["BF"] = N_( "Burkina Faso" );
00239 iso3166["BG"] = N_( "Bulgaria" );
00240 iso3166["BH"] = N_( "Bahrain" );
00241 iso3166["BI"] = N_( "Burundi" );
00242 iso3166["BJ"] = N_( "Benin" );
00243 iso3166["BM"] = N_( "Bermuda" );
00244 iso3166["BN"] = N_( "Brunei Darussalam" );
00245 iso3166["BO"] = N_( "Bolivia" );
00246 iso3166["BR"] = N_( "Brazil" );
00247 iso3166["BS"] = N_( "Bahamas" );
00248 iso3166["BT"] = N_( "Bhutan" );
00249 iso3166["BV"] = N_( "Bouvet Island" );
00250 iso3166["BW"] = N_( "Botswana" );
00251 iso3166["BY"] = N_( "Belarus" );
00252 iso3166["BZ"] = N_( "Belize" );
00253 iso3166["CA"] = N_( "Canada" );
00254 iso3166["CC"] = N_( "Cocos (Keeling) Islands" );
00255 iso3166["CD"] = N_( "Congo" );
00256 iso3166["CF"] = N_( "Centruual African Republic" );
00257 iso3166["CG"] = N_( "Congo" );
00258 iso3166["CH"] = N_( "Switzerland" );
00259 iso3166["CI"] = N_( "Cote D'Ivoire" );
00260 iso3166["CK"] = N_( "Cook Islands" );
00261 iso3166["CL"] = N_( "Chile" );
00262 iso3166["CM"] = N_( "Cameroon" );
00263 iso3166["CN"] = N_( "China" );
00264 iso3166["CO"] = N_( "Colombia" );
00265 iso3166["CR"] = N_( "Costa Rica" );
00266 iso3166["CS"] = N_( "Serbia and Montenegro" );
00267 iso3166["CU"] = N_( "Cuba" );
00268 iso3166["CV"] = N_( "Cape Verde" );
00269 iso3166["CX"] = N_( "Christmas Island" );
00270 iso3166["CY"] = N_( "Cyprus" );
00271 iso3166["CZ"] = N_( "Czech Republic" );
00272 iso3166["DE"] = N_( "Germany" );
00273 iso3166["DJ"] = N_( "Djibouti" );
00274 iso3166["DK"] = N_( "Denmark" );
00275 iso3166["DM"] = N_( "Dominica" );
00276 iso3166["DO"] = N_( "Dominican Republic" );
00277 iso3166["DZ"] = N_( "Algeria" );
00278 iso3166["EC"] = N_( "Ecuador" );
00279 iso3166["EE"] = N_( "Estonia" );
00280 iso3166["EG"] = N_( "Egypt" );
00281 iso3166["EH"] = N_( "Western Sahara" );
00282 iso3166["ER"] = N_( "Eritrea" );
00283 iso3166["ES"] = N_( "Spain" );
00284 iso3166["ET"] = N_( "Ethiopia" );
00285 iso3166["FI"] = N_( "Finland" );
00286 iso3166["FJ"] = N_( "Fiji" );
00287 iso3166["FK"] = N_( "Falkland Islands (Malvinas)" );
00288 iso3166["FM"] = N_( "Federated States of Micronesia" );
00289 iso3166["FO"] = N_( "Faroe Islands" );
00290 iso3166["FR"] = N_( "France" );
00291 iso3166["FX"] = N_( "Metropolitan France" );
00292 iso3166["GA"] = N_( "Gabon" );
00293 iso3166["GB"] = N_( "United Kingdom" );
00294 iso3166["GD"] = N_( "Grenada" );
00295 iso3166["GE"] = N_( "Georgia" );
00296 iso3166["GF"] = N_( "French Guiana" );
00297 iso3166["GH"] = N_( "Ghana" );
00298 iso3166["GI"] = N_( "Gibraltar" );
00299 iso3166["GL"] = N_( "Greenland" );
00300 iso3166["GM"] = N_( "Gambia" );
00301 iso3166["GN"] = N_( "Guinea" );
00302 iso3166["GP"] = N_( "Guadeloupe" );
00303 iso3166["GQ"] = N_( "Equatorial Guinea" );
00304 iso3166["GR"] = N_( "Greece" );
00305 iso3166["GS"] = N_( "South Georgia and the South Sandwich Islands" );
00306 iso3166["GT"] = N_( "Guatemala" );
00307 iso3166["GU"] = N_( "Guam" );
00308 iso3166["GW"] = N_( "Guinea-Bissau" );
00309 iso3166["GY"] = N_( "Guyana" );
00310 iso3166["HK"] = N_( "Hong Kong" );
00311 iso3166["HM"] = N_( "Heard Island and McDonald Islands" );
00312 iso3166["HN"] = N_( "Honduras" );
00313 iso3166["HR"] = N_( "Croatia" );
00314 iso3166["HT"] = N_( "Haiti" );
00315 iso3166["HU"] = N_( "Hungary" );
00316 iso3166["ID"] = N_( "Indonesia" );
00317 iso3166["IE"] = N_( "Ireland" );
00318 iso3166["IL"] = N_( "Israel" );
00319 iso3166["IN"] = N_( "India" );
00320 iso3166["IO"] = N_( "British Indian Ocean Territory" );
00321 iso3166["IQ"] = N_( "Iraq" );
00322 iso3166["IR"] = N_( "Iran" );
00323 iso3166["IS"] = N_( "Iceland" );
00324 iso3166["IT"] = N_( "Italy" );
00325 iso3166["JM"] = N_( "Jamaica" );
00326 iso3166["JO"] = N_( "Jordan" );
00327 iso3166["JP"] = N_( "Japan" );
00328 iso3166["KE"] = N_( "Kenya" );
00329 iso3166["KG"] = N_( "Kyrgyzstan" );
00330 iso3166["KH"] = N_( "Cambodia" );
00331 iso3166["KI"] = N_( "Kiribati" );
00332 iso3166["KM"] = N_( "Comoros" );
00333 iso3166["KN"] = N_( "Saint Kitts and Nevis" );
00334 iso3166["KP"] = N_( "North Korea" );
00335 iso3166["KR"] = N_( "South Korea" );
00336 iso3166["KW"] = N_( "Kuwait" );
00337 iso3166["KY"] = N_( "Cayman Islands" );
00338 iso3166["KZ"] = N_( "Kazakhstan" );
00339 iso3166["LA"] = N_( "Lao People's Democratic Republic" );
00340 iso3166["LB"] = N_( "Lebanon" );
00341 iso3166["LC"] = N_( "Saint Lucia" );
00342 iso3166["LI"] = N_( "Liechtenstein" );
00343 iso3166["LK"] = N_( "Sri Lanka" );
00344 iso3166["LR"] = N_( "Liberia" );
00345 iso3166["LS"] = N_( "Lesotho" );
00346 iso3166["LT"] = N_( "Lithuania" );
00347 iso3166["LU"] = N_( "Luxembourg" );
00348 iso3166["LV"] = N_( "Latvia" );
00349 iso3166["LY"] = N_( "Libya" );
00350 iso3166["MA"] = N_( "Morocco" );
00351 iso3166["MC"] = N_( "Monaco" );
00352 iso3166["MD"] = N_( "Moldova" );
00353 iso3166["MG"] = N_( "Madagascar" );
00354 iso3166["MH"] = N_( "Marshall Islands" );
00355 iso3166["MK"] = N_( "Macedonia" );
00356 iso3166["ML"] = N_( "Mali" );
00357 iso3166["MM"] = N_( "Myanmar" );
00358 iso3166["MN"] = N_( "Mongolia" );
00359 iso3166["MO"] = N_( "Macao" );
00360 iso3166["MP"] = N_( "Northern Mariana Islands" );
00361 iso3166["MQ"] = N_( "Martinique" );
00362 iso3166["MR"] = N_( "Mauritania" );
00363 iso3166["MS"] = N_( "Montserrat" );
00364 iso3166["MT"] = N_( "Malta" );
00365 iso3166["MU"] = N_( "Mauritius" );
00366 iso3166["MV"] = N_( "Maldives" );
00367 iso3166["MW"] = N_( "Malawi" );
00368 iso3166["MX"] = N_( "Mexico" );
00369 iso3166["MY"] = N_( "Malaysia" );
00370 iso3166["MZ"] = N_( "Mozambique" );
00371 iso3166["NA"] = N_( "Namibia" );
00372 iso3166["NC"] = N_( "New Caledonia" );
00373 iso3166["NE"] = N_( "Niger" );
00374 iso3166["NF"] = N_( "Norfolk Island" );
00375 iso3166["NG"] = N_( "Nigeria" );
00376 iso3166["NI"] = N_( "Nicaragua" );
00377 iso3166["NL"] = N_( "Netherlands" );
00378 iso3166["NO"] = N_( "Norway" );
00379 iso3166["NP"] = N_( "Nepal" );
00380 iso3166["NR"] = N_( "Nauru" );
00381 iso3166["NU"] = N_( "Niue" );
00382 iso3166["NZ"] = N_( "New Zealand" );
00383 iso3166["OM"] = N_( "Oman" );
00384 iso3166["PA"] = N_( "Panama" );
00385 iso3166["PE"] = N_( "Peru" );
00386 iso3166["PF"] = N_( "French Polynesia" );
00387 iso3166["PG"] = N_( "Papua New Guinea" );
00388 iso3166["PH"] = N_( "Philippines" );
00389 iso3166["PK"] = N_( "Pakistan" );
00390 iso3166["PL"] = N_( "Poland" );
00391 iso3166["PM"] = N_( "Saint Pierre and Miquelon" );
00392 iso3166["PN"] = N_( "Pitcairn" );
00393 iso3166["PR"] = N_( "Puerto Rico" );
00394 iso3166["PS"] = N_( "Palestinian Territory" );
00395 iso3166["PT"] = N_( "Portugal" );
00396 iso3166["PW"] = N_( "Palau" );
00397 iso3166["PY"] = N_( "Paraguay" );
00398 iso3166["QA"] = N_( "Qatar" );
00399 iso3166["RE"] = N_( "Reunion" );
00400 iso3166["RO"] = N_( "Romania" );
00401 iso3166["RU"] = N_( "Russian Federation" );
00402 iso3166["RW"] = N_( "Rwanda" );
00403 iso3166["SA"] = N_( "Saudi Arabia" );
00404 iso3166["SB"] = N_( "Solomon Islands" );
00405 iso3166["SC"] = N_( "Seychelles" );
00406 iso3166["SD"] = N_( "Sudan" );
00407 iso3166["SE"] = N_( "Sweden" );
00408 iso3166["SG"] = N_( "Singapore" );
00409 iso3166["SH"] = N_( "Saint Helena" );
00410 iso3166["SI"] = N_( "Slovenia" );
00411 iso3166["SJ"] = N_( "Svalbard and Jan Mayen" );
00412 iso3166["SK"] = N_( "Slovakia" );
00413 iso3166["SL"] = N_( "Sierra Leone" );
00414 iso3166["SM"] = N_( "San Marino" );
00415 iso3166["SN"] = N_( "Senegal" );
00416 iso3166["SO"] = N_( "Somalia" );
00417 iso3166["SR"] = N_( "Suriname" );
00418 iso3166["ST"] = N_( "Sao Tome and Principe" );
00419 iso3166["SV"] = N_( "El Salvador" );
00420 iso3166["SY"] = N_( "Syria" );
00421 iso3166["SZ"] = N_( "Swaziland" );
00422 iso3166["TC"] = N_( "Turks and Caicos Islands" );
00423 iso3166["TD"] = N_( "Chad" );
00424 iso3166["TF"] = N_( "French Southern Territories" );
00425 iso3166["TG"] = N_( "Togo" );
00426 iso3166["TH"] = N_( "Thailand" );
00427 iso3166["TJ"] = N_( "Tajikistan" );
00428 iso3166["TK"] = N_( "Tokelau" );
00429 iso3166["TM"] = N_( "Turkmenistan" );
00430 iso3166["TN"] = N_( "Tunisia" );
00431 iso3166["TO"] = N_( "Tonga" );
00432 iso3166["TL"] = N_( "East Timor" );
00433 iso3166["TR"] = N_( "Turkey" );
00434 iso3166["TT"] = N_( "Trinidad and Tobago" );
00435 iso3166["TV"] = N_( "Tuvalu" );
00436 iso3166["TW"] = N_( "Taiwan" );
00437 iso3166["TZ"] = N_( "Tanzania" );
00438 iso3166["UA"] = N_( "Ukraine" );
00439 iso3166["UG"] = N_( "Uganda" );
00440 iso3166["UM"] = N_( "United States Minor Outlying Islands" );
00441 iso3166["US"] = N_( "United States" );
00442 iso3166["UY"] = N_( "Uruguay" );
00443 iso3166["UZ"] = N_( "Uzbekistan" );
00444 iso3166["VA"] = N_( "Holy See (Vatican City State)" );
00445 iso3166["VC"] = N_( "Saint Vincent and the Grenadines" );
00446 iso3166["VE"] = N_( "Venezuela" );
00447 iso3166["VG"] = N_( "British Virgin Islands" );
00448 iso3166["VI"] = N_( "Virgin Islands, U.S." );
00449 iso3166["VN"] = N_( "Vietnam" );
00450 iso3166["VU"] = N_( "Vanuatu" );
00451 iso3166["WF"] = N_( "Wallis and Futuna" );
00452 iso3166["WS"] = N_( "Samoa" );
00453 iso3166["YE"] = N_( "Yemen" );
00454 iso3166["YT"] = N_( "Mayotte" );
00455 iso3166["ZA"] = N_( "South Africa" );
00456 iso3166["ZM"] = N_( "Zambia" );
00457 iso3166["ZW"] = N_( "Zimbabwe" );
00458 }
00459
00461 }
00463
00465 }