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