1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/CountryCode.cc
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/String.h"
17 #include "zypp/base/Gettext.h"
19 #include "zypp/CountryCode.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 /** Wrap static codemap data. */
32 struct CodeMaps // singleton
34 typedef std::map<std::string,std::string> CodeMap;
35 typedef CodeMap::const_iterator Index;
37 /** Return the CodeMap Index for \a code_r. */
38 static Index getIndex( const std::string & code_r )
40 static CodeMaps _maps; // the singleton instance
41 return _maps.lookup( code_r );
45 /** Ctor initializes the code maps.
46 * http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
50 /** Make shure the code is in the code maps and return it's index. */
51 inline Index lookup( const std::string & code_r );
53 /** Return index of \a code_r, if it's in the code maps. */
54 inline Index lookupCode( const std::string & code_r );
57 /** Two letter codes. */
59 /** All the stuff the application injects. */
63 inline CodeMaps::Index CodeMaps::lookupCode( const std::string & code_r )
65 switch ( code_r.size() )
69 Index it = iso3166.find( code_r );
70 if ( it != iso3166.end() )
75 // not found: check others
76 // !!! not found at all returns others.end()
77 return others.find( code_r );
80 inline CodeMaps::Index CodeMaps::lookup( const std::string & code_r )
82 Index it = lookupCode( code_r );
83 if ( it != others.end() )
86 // not found: Remember a new code
87 CodeMap::value_type nval( code_r, std::string() );
89 if ( code_r.size() != 2 )
90 WAR << "Malformed CountryCode '" << code_r << "' (expect 2-letter)" << endl;
92 std::string lcode( str::toUpper( code_r ) );
93 if ( lcode != code_r )
95 WAR << "Malformed CountryCode '" << code_r << "' (not upper case)" << endl;
96 // but maybe we're lucky with the upper case code
97 // and find a country name.
98 it = lookupCode( lcode );
99 if ( it != others.end() )
100 nval.second = it->second;
103 MIL << "Remember CountryCode '" << code_r << "': '" << nval.second << "'" << endl;
104 return others.insert( nval ).first;
107 /////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////
111 ///////////////////////////////////////////////////////////////////
113 // CLASS NAME : CountryCode::Impl
115 /** CountryCode implementation.
116 * \note CodeMaps contain the untranslated country names.
117 * Translation is done in \ref name.
119 struct CountryCode::Impl
122 : _index( CodeMaps::getIndex( std::string() ) )
125 Impl( const std::string & code_r )
126 : _index( CodeMaps::getIndex( code_r ) )
129 std::string code() const
130 { return _index->first; }
132 std::string name() const {
133 if ( _index->second.empty() )
135 std::string ret( _("Unknown country: ") );
137 ret += _index->first;
141 return _( _index->second.c_str() );
145 /** index into code map. */
146 CodeMaps::Index _index;
149 /** Offer default Impl. */
150 static shared_ptr<Impl> nullimpl()
152 static shared_ptr<Impl> _nullimpl( new Impl );
156 ///////////////////////////////////////////////////////////////////
158 ///////////////////////////////////////////////////////////////////
160 // CLASS NAME : CountryCode
162 ///////////////////////////////////////////////////////////////////
164 const CountryCode CountryCode::noCode;
166 ///////////////////////////////////////////////////////////////////
168 // METHOD NAME : CountryCode::CountryCode
169 // METHOD TYPE : Ctor
171 CountryCode::CountryCode()
172 : _pimpl( Impl::nullimpl() )
175 ///////////////////////////////////////////////////////////////////
177 // METHOD NAME : CountryCode::CountryCode
178 // METHOD TYPE : Ctor
180 CountryCode::CountryCode( const std::string & code_r )
181 : _pimpl( new Impl( code_r ) )
184 ///////////////////////////////////////////////////////////////////
186 // METHOD NAME : CountryCode::~CountryCode
187 // METHOD TYPE : Dtor
189 CountryCode::~CountryCode()
192 ///////////////////////////////////////////////////////////////////
194 // METHOD NAME : CountryCode::code
195 // METHOD TYPE : std::string
197 std::string CountryCode::code() const
198 { return _pimpl->code(); }
200 ///////////////////////////////////////////////////////////////////
202 // METHOD NAME : CountryCode::name
203 // METHOD TYPE : std::string
205 std::string CountryCode::name() const
206 { return _pimpl->name(); }
208 ///////////////////////////////////////////////////////////////////
210 { /////////////////////////////////////////////////////////////////
214 // Defined CountryCode constants
215 others[""] = N_( "No Code" );
223 const Init init[] = {
224 {"AD", N_( "Andorra" ) }, // :AND:020:
225 {"AE", N_( "United Arab Emirates" ) }, // :ARE:784:
226 {"AF", N_( "Afghanistan" ) }, // :AFG:004:
227 {"AG", N_( "Antigua and Barbuda" ) }, // :ATG:028:
228 {"AI", N_( "Anguilla" ) }, // :AIA:660:
229 {"AL", N_( "Albania" ) }, // :ALB:008:
230 {"AM", N_( "Armenia" ) }, // :ARM:051:
231 {"AN", N_( "Netherlands Antilles" ) }, // :ANT:530:
232 {"AO", N_( "Angola" ) }, // :AGO:024:
233 {"AQ", N_( "Antarctica" ) }, // :ATA:010:
234 {"AR", N_( "Argentina" ) }, // :ARG:032:
235 {"AS", N_( "American Samoa" ) }, // :ASM:016:
236 {"AT", N_( "Austria" ) }, // :AUT:040:
237 {"AU", N_( "Australia" ) }, // :AUS:036:
238 {"AW", N_( "Aruba" ) }, // :ABW:533:
239 {"AX", N_( "Aland Islands" ) }, // :ALA:248:
240 {"AZ", N_( "Azerbaijan" ) }, // :AZE:031:
241 {"BA", N_( "Bosnia and Herzegovina" ) }, // :BIH:070:
242 {"BB", N_( "Barbados" ) }, // :BRB:052:
243 {"BD", N_( "Bangladesh" ) }, // :BGD:050:
244 {"BE", N_( "Belgium" ) }, // :BEL:056:
245 {"BF", N_( "Burkina Faso" ) }, // :BFA:854:
246 {"BG", N_( "Bulgaria" ) }, // :BGR:100:
247 {"BH", N_( "Bahrain" ) }, // :BHR:048:
248 {"BI", N_( "Burundi" ) }, // :BDI:108:
249 {"BJ", N_( "Benin" ) }, // :BEN:204:
250 {"BM", N_( "Bermuda" ) }, // :BMU:060:
251 {"BN", N_( "Brunei Darussalam" ) }, // :BRN:096:
252 {"BO", N_( "Bolivia" ) }, // :BOL:068:
253 {"BR", N_( "Brazil" ) }, // :BRA:076:
254 {"BS", N_( "Bahamas" ) }, // :BHS:044:
255 {"BT", N_( "Bhutan" ) }, // :BTN:064:
256 {"BV", N_( "Bouvet Island" ) }, // :BVT:074:
257 {"BW", N_( "Botswana" ) }, // :BWA:072:
258 {"BY", N_( "Belarus" ) }, // :BLR:112:
259 {"BZ", N_( "Belize" ) }, // :BLZ:084:
260 {"CA", N_( "Canada" ) }, // :CAN:124:
261 {"CC", N_( "Cocos (Keeling) Islands" ) }, // :CCK:166:
262 {"CD", N_( "Congo" ) }, // :COD:180:
263 {"CF", N_( "Central African Republic" ) }, // :CAF:140:
264 {"CG", N_( "Congo" ) }, // :COG:178:
265 {"CH", N_( "Switzerland" ) }, // :CHE:756:
266 {"CI", N_( "Cote D'Ivoire" ) }, // :CIV:384:
267 {"CK", N_( "Cook Islands" ) }, // :COK:184:
268 {"CL", N_( "Chile" ) }, // :CHL:152:
269 {"CM", N_( "Cameroon" ) }, // :CMR:120:
270 {"CN", N_( "China" ) }, // :CHN:156:
271 {"CO", N_( "Colombia" ) }, // :COL:170:
272 {"CR", N_( "Costa Rica" ) }, // :CRI:188:
273 {"CS", N_( "Serbia and Montenegro" ) }, // :SCG:891:
274 {"CU", N_( "Cuba" ) }, // :CUB:192:
275 {"CV", N_( "Cape Verde" ) }, // :CPV:132:
276 {"CX", N_( "Christmas Island" ) }, // :CXR:162:
277 {"CY", N_( "Cyprus" ) }, // :CYP:196:
278 {"CZ", N_( "Czech Republic" ) }, // :CZE:203:
279 {"DE", N_( "Germany" ) }, // :DEU:276:
280 {"DJ", N_( "Djibouti" ) }, // :DJI:262:
281 {"DK", N_( "Denmark" ) }, // :DNK:208:
282 {"DM", N_( "Dominica" ) }, // :DMA:212:
283 {"DO", N_( "Dominican Republic" ) }, // :DOM:214:
284 {"DZ", N_( "Algeria" ) }, // :DZA:012:
285 {"EC", N_( "Ecuador" ) }, // :ECU:218:
286 {"EE", N_( "Estonia" ) }, // :EST:233:
287 {"EG", N_( "Egypt" ) }, // :EGY:818:
288 {"EH", N_( "Western Sahara" ) }, // :ESH:732:
289 {"ER", N_( "Eritrea" ) }, // :ERI:232:
290 {"ES", N_( "Spain" ) }, // :ESP:724:
291 {"ET", N_( "Ethiopia" ) }, // :ETH:231:
292 {"FI", N_( "Finland" ) }, // :FIN:246:
293 {"FJ", N_( "Fiji" ) }, // :FJI:242:
294 {"FK", N_( "Falkland Islands (Malvinas)" ) }, // :FLK:238:
295 {"FM", N_( "Federated States of Micronesia" ) }, // :FSM:583:
296 {"FO", N_( "Faroe Islands" ) }, // :FRO:234:
297 {"FR", N_( "France" ) }, // :FRA:250:
298 {"FX", N_( "Metropolitan France" ) }, // :FXX:249:
299 {"GA", N_( "Gabon" ) }, // :GAB:266:
300 {"GB", N_( "United Kingdom" ) }, // :GBR:826:
301 {"GD", N_( "Grenada" ) }, // :GRD:308:
302 {"GE", N_( "Georgia" ) }, // :GEO:268:
303 {"GF", N_( "French Guiana" ) }, // :GUF:254:
304 {"GH", N_( "Ghana" ) }, // :GHA:288:
305 {"GI", N_( "Gibraltar" ) }, // :GIB:292:
306 {"GL", N_( "Greenland" ) }, // :GRL:304:
307 {"GM", N_( "Gambia" ) }, // :GMB:270:
308 {"GN", N_( "Guinea" ) }, // :GIN:324:
309 {"GP", N_( "Guadeloupe" ) }, // :GLP:312:
310 {"GQ", N_( "Equatorial Guinea" ) }, // :GNQ:226:
311 {"GR", N_( "Greece" ) }, // :GRC:300:
312 {"GS", N_( "South Georgia and the South Sandwich Islands" ) }, // :SGS:239:
313 {"GT", N_( "Guatemala" ) }, // :GTM:320:
314 {"GU", N_( "Guam" ) }, // :GUM:316:
315 {"GW", N_( "Guinea-Bissau" ) }, // :GNB:624:
316 {"GY", N_( "Guyana" ) }, // :GUY:328:
317 {"HK", N_( "Hong Kong" ) }, // :HKG:344:
318 {"HM", N_( "Heard Island and McDonald Islands" ) }, // :HMD:334:
319 {"HN", N_( "Honduras" ) }, // :HND:340:
320 {"HR", N_( "Croatia" ) }, // :HRV:191:
321 {"HT", N_( "Haiti" ) }, // :HTI:332:
322 {"HU", N_( "Hungary" ) }, // :HUN:348:
323 {"ID", N_( "Indonesia" ) }, // :IDN:360:
324 {"IE", N_( "Ireland" ) }, // :IRL:372:
325 {"IL", N_( "Israel" ) }, // :ISR:376:
326 {"IN", N_( "India" ) }, // :IND:356:
327 {"IO", N_( "British Indian Ocean Territory" ) }, // :IOT:086:
328 {"IQ", N_( "Iraq" ) }, // :IRQ:368:
329 {"IR", N_( "Iran" ) }, // :IRN:364:
330 {"IS", N_( "Iceland" ) }, // :ISL:352:
331 {"IT", N_( "Italy" ) }, // :ITA:380:
332 {"JM", N_( "Jamaica" ) }, // :JAM:388:
333 {"JO", N_( "Jordan" ) }, // :JOR:400:
334 {"JP", N_( "Japan" ) }, // :JPN:392:
335 {"KE", N_( "Kenya" ) }, // :KEN:404:
336 {"KG", N_( "Kyrgyzstan" ) }, // :KGZ:417:
337 {"KH", N_( "Cambodia" ) }, // :KHM:116:
338 {"KI", N_( "Kiribati" ) }, // :KIR:296:
339 {"KM", N_( "Comoros" ) }, // :COM:174:
340 {"KN", N_( "Saint Kitts and Nevis" ) }, // :KNA:659:
341 {"KP", N_( "North Korea" ) }, // :PRK:408:
342 {"KR", N_( "South Korea" ) }, // :KOR:410:
343 {"KW", N_( "Kuwait" ) }, // :KWT:414:
344 {"KY", N_( "Cayman Islands" ) }, // :CYM:136:
345 {"KZ", N_( "Kazakhstan" ) }, // :KAZ:398:
346 {"LA", N_( "Lao People's Democratic Republic" ) }, // :LAO:418:
347 {"LB", N_( "Lebanon" ) }, // :LBN:422:
348 {"LC", N_( "Saint Lucia" ) }, // :LCA:662:
349 {"LI", N_( "Liechtenstein" ) }, // :LIE:438:
350 {"LK", N_( "Sri Lanka" ) }, // :LKA:144:
351 {"LR", N_( "Liberia" ) }, // :LBR:430:
352 {"LS", N_( "Lesotho" ) }, // :LSO:426:
353 {"LT", N_( "Lithuania" ) }, // :LTU:440:
354 {"LU", N_( "Luxembourg" ) }, // :LUX:442:
355 {"LV", N_( "Latvia" ) }, // :LVA:428:
356 {"LY", N_( "Libya" ) }, // :LBY:434:
357 {"MA", N_( "Morocco" ) }, // :MAR:504:
358 {"MC", N_( "Monaco" ) }, // :MCO:492:
359 {"MD", N_( "Moldova" ) }, // :MDA:498:
360 {"MG", N_( "Madagascar" ) }, // :MDG:450:
361 {"MH", N_( "Marshall Islands" ) }, // :MHL:584:
362 {"MK", N_( "Macedonia" ) }, // :MKD:807:
363 {"ML", N_( "Mali" ) }, // :MLI:466:
364 {"MM", N_( "Myanmar" ) }, // :MMR:104:
365 {"MN", N_( "Mongolia" ) }, // :MNG:496:
366 {"MO", N_( "Macao" ) }, // :MAC:446:
367 {"MP", N_( "Northern Mariana Islands" ) }, // :MNP:580:
368 {"MQ", N_( "Martinique" ) }, // :MTQ:474:
369 {"MR", N_( "Mauritania" ) }, // :MRT:478:
370 {"MS", N_( "Montserrat" ) }, // :MSR:500:
371 {"MT", N_( "Malta" ) }, // :MLT:470:
372 {"MU", N_( "Mauritius" ) }, // :MUS:480:
373 {"MV", N_( "Maldives" ) }, // :MDV:462:
374 {"MW", N_( "Malawi" ) }, // :MWI:454:
375 {"MX", N_( "Mexico" ) }, // :MEX:484:
376 {"MY", N_( "Malaysia" ) }, // :MYS:458:
377 {"MZ", N_( "Mozambique" ) }, // :MOZ:508:
378 {"NA", N_( "Namibia" ) }, // :NAM:516:
379 {"NC", N_( "New Caledonia" ) }, // :NCL:540:
380 {"NE", N_( "Niger" ) }, // :NER:562:
381 {"NF", N_( "Norfolk Island" ) }, // :NFK:574:
382 {"NG", N_( "Nigeria" ) }, // :NGA:566:
383 {"NI", N_( "Nicaragua" ) }, // :NIC:558:
384 {"NL", N_( "Netherlands" ) }, // :NLD:528:
385 {"NO", N_( "Norway" ) }, // :NOR:578:
386 {"NP", N_( "Nepal" ) }, // :NPL:524:
387 {"NR", N_( "Nauru" ) }, // :NRU:520:
388 {"NU", N_( "Niue" ) }, // :NIU:570:
389 {"NZ", N_( "New Zealand" ) }, // :NZL:554:
390 {"OM", N_( "Oman" ) }, // :OMN:512:
391 {"PA", N_( "Panama" ) }, // :PAN:591:
392 {"PE", N_( "Peru" ) }, // :PER:604:
393 {"PF", N_( "French Polynesia" ) }, // :PYF:258:
394 {"PG", N_( "Papua New Guinea" ) }, // :PNG:598:
395 {"PH", N_( "Philippines" ) }, // :PHL:608:
396 {"PK", N_( "Pakistan" ) }, // :PAK:586:
397 {"PL", N_( "Poland" ) }, // :POL:616:
398 {"PM", N_( "Saint Pierre and Miquelon" ) }, // :SPM:666:
399 {"PN", N_( "Pitcairn" ) }, // :PCN:612:
400 {"PR", N_( "Puerto Rico" ) }, // :PRI:630:
401 {"PS", N_( "Palestinian Territory" ) }, // :PSE:275:
402 {"PT", N_( "Portugal" ) }, // :PRT:620:
403 {"PW", N_( "Palau" ) }, // :PLW:585:
404 {"PY", N_( "Paraguay" ) }, // :PRY:600:
405 {"QA", N_( "Qatar" ) }, // :QAT:634:
406 {"RE", N_( "Reunion" ) }, // :REU:638:
407 {"RO", N_( "Romania" ) }, // :ROU:642:
408 {"RU", N_( "Russian Federation" ) }, // :RUS:643:
409 {"RW", N_( "Rwanda" ) }, // :RWA:646:
410 {"SA", N_( "Saudi Arabia" ) }, // :SAU:682:
411 {"SB", N_( "Solomon Islands" ) }, // :SLB:090:
412 {"SC", N_( "Seychelles" ) }, // :SYC:690:
413 {"SD", N_( "Sudan" ) }, // :SDN:736:
414 {"SE", N_( "Sweden" ) }, // :SWE:752:
415 {"SG", N_( "Singapore" ) }, // :SGP:702:
416 {"SH", N_( "Saint Helena" ) }, // :SHN:654:
417 {"SI", N_( "Slovenia" ) }, // :SVN:705:
418 {"SJ", N_( "Svalbard and Jan Mayen" ) }, // :SJM:744:
419 {"SK", N_( "Slovakia" ) }, // :SVK:703:
420 {"SL", N_( "Sierra Leone" ) }, // :SLE:694:
421 {"SM", N_( "San Marino" ) }, // :SMR:674:
422 {"SN", N_( "Senegal" ) }, // :SEN:686:
423 {"SO", N_( "Somalia" ) }, // :SOM:706:
424 {"SR", N_( "Suriname" ) }, // :SUR:740:
425 {"ST", N_( "Sao Tome and Principe" ) }, // :STP:678:
426 {"SV", N_( "El Salvador" ) }, // :SLV:222:
427 {"SY", N_( "Syria" ) }, // :SYR:760:
428 {"SZ", N_( "Swaziland" ) }, // :SWZ:748:
429 {"TC", N_( "Turks and Caicos Islands" ) }, // :TCA:796:
430 {"TD", N_( "Chad" ) }, // :TCD:148:
431 {"TF", N_( "French Southern Territories" ) }, // :ATF:260:
432 {"TG", N_( "Togo" ) }, // :TGO:768:
433 {"TH", N_( "Thailand" ) }, // :THA:764:
434 {"TJ", N_( "Tajikistan" ) }, // :TJK:762:
435 {"TK", N_( "Tokelau" ) }, // :TKL:772:
436 {"TM", N_( "Turkmenistan" ) }, // :TKM:795:
437 {"TN", N_( "Tunisia" ) }, // :TUN:788:
438 {"TO", N_( "Tonga" ) }, // :TON:776:
439 {"TL", N_( "East Timor" ) }, // :TLS:626:
440 {"TR", N_( "Turkey" ) }, // :TUR:792:
441 {"TT", N_( "Trinidad and Tobago" ) }, // :TTO:780:
442 {"TV", N_( "Tuvalu" ) }, // :TUV:798:
443 {"TW", N_( "Taiwan" ) }, // :TWN:158:
444 {"TZ", N_( "Tanzania" ) }, // :TZA:834:
445 {"UA", N_( "Ukraine" ) }, // :UKR:804:
446 {"UG", N_( "Uganda" ) }, // :UGA:800:
447 {"UM", N_( "United States Minor Outlying Islands" ) },// :UMI:581:
448 {"US", N_( "United States" ) }, // :USA:840:
449 {"UY", N_( "Uruguay" ) }, // :URY:858:
450 {"UZ", N_( "Uzbekistan" ) }, // :UZB:860:
451 {"VA", N_( "Holy See (Vatican City State)" ) }, // :VAT:336:
452 {"VC", N_( "Saint Vincent and the Grenadines" ) }, // :VCT:670:
453 {"VE", N_( "Venezuela" ) }, // :VEN:862:
454 {"VG", N_( "British Virgin Islands" ) }, // :VGB:092:
455 {"VI", N_( "Virgin Islands, U.S." ) }, // :VIR:850:
456 {"VN", N_( "Vietnam" ) }, // :VNM:704:
457 {"VU", N_( "Vanuatu" ) }, // :VUT:548:
458 {"WF", N_( "Wallis and Futuna" ) }, // :WLF:876:
459 {"WS", N_( "Samoa" ) }, // :WSM:882:
460 {"YE", N_( "Yemen" ) }, // :YEM:887:
461 {"YT", N_( "Mayotte" ) }, // :MYT:175:
462 {"ZA", N_( "South Africa" ) }, // :ZAF:710:
463 {"ZM", N_( "Zambia" ) }, // :ZMB:894:
464 {"ZW", N_( "Zimbabwe" ) }, // :ZWE:716:
469 for (const Init * i = init; i->iso3166 != NULL; ++i)
470 iso3166[i->iso3166] = i->name;
473 /////////////////////////////////////////////////////////////////
475 ///////////////////////////////////////////////////////////////////
477 /////////////////////////////////////////////////////////////////
479 ///////////////////////////////////////////////////////////////////