X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..277af7082f210d5fa7e37ce63392ac8568371616:/icuSources/tools/tzcode/tz2icu.cpp diff --git a/icuSources/tools/tzcode/tz2icu.cpp b/icuSources/tools/tzcode/tz2icu.cpp index 238e8656..aeae5893 100644 --- a/icuSources/tools/tzcode/tz2icu.cpp +++ b/icuSources/tools/tzcode/tz2icu.cpp @@ -1,7 +1,7 @@ /* ********************************************************************** -* Copyright (c) 2003-2010, International Business Machines +* Copyright (c) 2003-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -304,9 +304,9 @@ void readzoneinfo(ifstream& file, ZoneInfo& info, bool is64bitData) { } // skip additional Olson byte version file.read(buf, 1); - // if '\0', we have just one copy of data, if '2', there is additional + // if '\0', we have just one copy of data, if '2' or '3', there is additional // 64 bit version at the end. - if(buf[0]!=0 && buf[0]!='2') { + if(buf[0]!=0 && buf[0]!='2' && buf[0]!='3') { throw invalid_argument("Bad Olson version info"); } @@ -742,7 +742,7 @@ struct FinalZone { << " and rule ID " << ruleid; throw invalid_argument(os.str()); } - if (year < 1900 || year >= 2050) { + if (year < 1900) { ostringstream os; os << "Invalid input year " << year << " with offset " << offset @@ -829,7 +829,7 @@ struct FinalRulePart { if (mode != DOM && (dow < 0 || dow >= 7)) { os << "Invalid input day of week " << dow; } - if (offset < 0 || offset > HOUR) { + if (offset < 0 || offset > (2 * HOUR)) { os << "Invalid input offset " << offset; } if (isgmt && !isstd) { @@ -1581,8 +1581,36 @@ int main(int argc, char *argv[]) { } // Create the country map + map icuRegions; // ICU's custom zone -> country override map > countryMap; // country -> set of zones map reverseCountryMap; // zone -> country + + try { + // Read icuregions file to collect ICU's own zone-region mapping data. + ifstream frg(ICU_REGIONS); + if (frg) { + string line; + while (getline(frg, line)) { + if (line[0] == '#') continue; + + string zone, country; + istringstream is(line); + is >> zone >> country; + if (zone.size() == 0) continue; + if (country.size() < 2) { + cerr << "Error: Can't parse " << line << " in " << ICU_REGIONS << endl; + return 1; + } + icuRegions[zone] = country; + } + } else { + cout << "No custom region map [icuregions]" << endl; + } + } catch (const exception& error) { + cerr << "Error: While reading " << ICU_REGIONS << ": " << error.what() << endl; + return 1; + } + try { ifstream f(zonetab.c_str()); if (!f) { @@ -1609,6 +1637,13 @@ int main(int argc, char *argv[]) { << " in " << zonetab << endl; return 1; } + if (icuRegions.find(zone) != icuRegions.end()) { + // Custom override + string customCountry = icuRegions[zone]; + cout << "Region Mapping: custom override for " << zone + << " " << country << " -> " << customCountry << endl; + country = customCountry; + } countryMap[country].insert(zone); reverseCountryMap[zone] = country; //cerr << (n+1) << ": " << country << " <=> " << zone << endl; @@ -1621,6 +1656,20 @@ int main(int argc, char *argv[]) { return 1; } + // Merge ICU's own zone-region mapping data + for (map::const_iterator i = icuRegions.begin(); + i != icuRegions.end(); ++i) { + const string& zid(i->first); + if (reverseCountryMap.find(zid) != reverseCountryMap.end()) { + continue; + } + cout << "Region Mapping: custom data zone=" << zid + << ", region=" << i->second << endl; + + reverseCountryMap[zid] = i->second; + countryMap[i->second].insert(zid); + } + // Merge ICU aliases into country map. Don't merge any alias // that already has a country map, since that doesn't make sense. // E.g. "Link Europe/Oslo Arctic/Longyearbyen" doesn't mean we @@ -1671,10 +1720,10 @@ int main(int argc, char *argv[]) { file << ", International Business Machines" << endl << "// Corporation and others. All Rights Reserved." << endl << "//---------------------------------------------------------" << endl - << "// Build tool: tz2icu" << endl - << "// Build date: " << asctime(now) /* << endl -- asctime emits CR */ - << "// Olson source: ftp://elsie.nci.nih.gov/pub/" << endl - << "// Olson version: " << version << endl + << "// Build tool: tz2icu" << endl + << "// Build date: " << asctime(now) /* << endl -- asctime emits CR */ + << "// tz database: ftp://ftp.iana.org/tz/" << endl + << "// tz version: " << version << endl << "// ICU version: " << U_ICU_VERSION << endl << "//---------------------------------------------------------" << endl << "// >> !!! >> THIS IS A MACHINE-GENERATED FILE << !!! <<" << endl