Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: base/i18n/timezone.cc

Issue 573623003: Use a more suitable storage for the timezone table. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/timezone.h" 5 #include "base/i18n/timezone.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 17 matching lines...) Expand all
28 28
29 return std::string(); 29 return std::string();
30 } 30 }
31 31
32 private: 32 private:
33 TimezoneMap() { 33 TimezoneMap() {
34 // These mappings are adapted from zone.tab, which is available at 34 // These mappings are adapted from zone.tab, which is available at
35 // <http://www.ietf.org/timezones/data/zone.tab> and is a part of public 35 // <http://www.ietf.org/timezones/data/zone.tab> and is a part of public
36 // domain. 36 // domain.
37 struct OlsonCodeData { 37 struct OlsonCodeData {
38 std::string country_code; 38 const char* country_code;
39 std::string olson_code; 39 const char* olson_code;
40 } olson_code_data[] = { 40 };
41 static const OlsonCodeData olson_code_data[] = {
41 { "AD", "Europe/Andorra" }, 42 { "AD", "Europe/Andorra" },
42 { "AE", "Asia/Dubai" }, 43 { "AE", "Asia/Dubai" },
43 { "AF", "Asia/Kabul" }, 44 { "AF", "Asia/Kabul" },
44 { "AG", "America/Antigua" }, 45 { "AG", "America/Antigua" },
45 { "AI", "America/Anguilla" }, 46 { "AI", "America/Anguilla" },
46 { "AL", "Europe/Tirane" }, 47 { "AL", "Europe/Tirane" },
47 { "AM", "Asia/Yerevan" }, 48 { "AM", "Asia/Yerevan" },
48 { "AO", "Africa/Luanda" }, 49 { "AO", "Africa/Luanda" },
49 { "AQ", "Antarctica/McMurdo" }, 50 { "AQ", "Antarctica/McMurdo" },
50 { "AQ", "Antarctica/Rothera" }, 51 { "AQ", "Antarctica/Rothera" },
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 { "YT", "Indian/Mayotte" }, 453 { "YT", "Indian/Mayotte" },
453 { "ZA", "Africa/Johannesburg" }, 454 { "ZA", "Africa/Johannesburg" },
454 { "ZM", "Africa/Lusaka" }, 455 { "ZM", "Africa/Lusaka" },
455 { "ZW", "Africa/Harare" }, 456 { "ZW", "Africa/Harare" },
456 // The mappings below are custom additions to zone.tab. 457 // The mappings below are custom additions to zone.tab.
457 { "GB", "Etc/GMT" }, 458 { "GB", "Etc/GMT" },
458 { "GB", "Etc/UTC" }, 459 { "GB", "Etc/UTC" },
459 { "GB", "Etc/UCT" }, 460 { "GB", "Etc/UCT" },
460 }; 461 };
461 462
462 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(olson_code_data); ++i) { 463 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(olson_code_data); ++i) {
Mark Mentovai 2014/10/01 13:05:07 This can be normal arraysize now. Same below.
Daniel Bratell 2014/10/01 19:56:22 Done.
463 map_[olson_code_data[i].olson_code] = olson_code_data[i].country_code; 464 map_[std::string(olson_code_data[i].olson_code)] =
465 std::string(olson_code_data[i].country_code);
Mark Mentovai 2014/10/01 13:05:07 You can make the “value” side of the map store con
Daniel Bratell 2014/10/01 19:56:22 Done.
464 } 466 }
465 467
466 // These are mapping from old codenames to new codenames. They are also 468 // These are mapping from old codenames to new codenames. They are also
467 // part of public domain, and available at 469 // part of public domain, and available at
468 // <http://www.ietf.org/timezones/data/backward>. 470 // <http://www.ietf.org/timezones/data/backward>.
469 struct LinkData { 471 struct LinkData {
470 std::string old_code; 472 const char* old_code;
471 std::string new_code; 473 const char* new_code;
472 } link_data[] = { 474 };
475 static const LinkData link_data[] = {
473 { "Africa/Asmera", "Africa/Asmara" }, 476 { "Africa/Asmera", "Africa/Asmara" },
474 { "Africa/Timbuktu", "Africa/Bamako" }, 477 { "Africa/Timbuktu", "Africa/Bamako" },
475 { "America/Argentina/ComodRivadavia", "America/Argentina/Catamarca" }, 478 { "America/Argentina/ComodRivadavia", "America/Argentina/Catamarca" },
476 { "America/Atka", "America/Adak" }, 479 { "America/Atka", "America/Adak" },
477 { "America/Buenos_Aires", "America/Argentina/Buenos_Aires" }, 480 { "America/Buenos_Aires", "America/Argentina/Buenos_Aires" },
478 { "America/Catamarca", "America/Argentina/Catamarca" }, 481 { "America/Catamarca", "America/Argentina/Catamarca" },
479 { "America/Coral_Harbour", "America/Atikokan" }, 482 { "America/Coral_Harbour", "America/Atikokan" },
480 { "America/Cordoba", "America/Argentina/Cordoba" }, 483 { "America/Cordoba", "America/Argentina/Cordoba" },
481 { "America/Ensenada", "America/Tijuana" }, 484 { "America/Ensenada", "America/Tijuana" },
482 { "America/Fort_Wayne", "America/Indiana/Indianapolis" }, 485 { "America/Fort_Wayne", "America/Indiana/Indianapolis" },
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 { "US/Mountain", "America/Denver" }, 579 { "US/Mountain", "America/Denver" },
577 { "US/Pacific", "America/Los_Angeles" }, 580 { "US/Pacific", "America/Los_Angeles" },
578 { "US/Samoa", "Pacific/Pago_Pago" }, 581 { "US/Samoa", "Pacific/Pago_Pago" },
579 { "UTC", "Etc/UTC" }, 582 { "UTC", "Etc/UTC" },
580 { "Universal", "Etc/UTC" }, 583 { "Universal", "Etc/UTC" },
581 { "W-SU", "Europe/Moscow" }, 584 { "W-SU", "Europe/Moscow" },
582 { "Zulu", "Etc/UTC" }, 585 { "Zulu", "Etc/UTC" },
583 }; 586 };
584 587
585 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(link_data); ++i) { 588 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(link_data); ++i) {
586 map_[link_data[i].old_code] = map_[link_data[i].new_code]; 589 map_[std::string(link_data[i].old_code)] =
590 map_[std::string(link_data[i].new_code)];
587 } 591 }
588 } 592 }
589 593
590 friend struct DefaultSingletonTraits<TimezoneMap>; 594 friend struct DefaultSingletonTraits<TimezoneMap>;
591 595
592 std::map<std::string, std::string> map_; 596 std::map<std::string, std::string> map_;
593 597
594 DISALLOW_COPY_AND_ASSIGN(TimezoneMap); 598 DISALLOW_COPY_AND_ASSIGN(TimezoneMap);
595 }; 599 };
596 600
597 } // namespace 601 } // namespace
598 602
599 std::string CountryCodeForCurrentTimezone() { 603 std::string CountryCodeForCurrentTimezone() {
600 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); 604 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
601 icu::UnicodeString id; 605 icu::UnicodeString id;
602 zone->getID(id); 606 zone->getID(id);
603 string16 olson_code(id.getBuffer(), id.length()); 607 string16 olson_code(id.getBuffer(), id.length());
604 return TimezoneMap::GetInstance()->CountryCodeForTimezone( 608 return TimezoneMap::GetInstance()->CountryCodeForTimezone(
605 UTF16ToUTF8(olson_code)); 609 UTF16ToUTF8(olson_code));
606 } 610 }
607 611
608 } // namespace base 612 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698