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