]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/zonemeta.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / i18n / zonemeta.cpp
index 84a965780291c9de458f4931c19f960ba18380ad..92268eb1b251e2859ffdabb2e1fa903e813e17bc 100644 (file)
@@ -30,7 +30,7 @@
 #include "olsontz.h"
 #include "uinvchar.h"
 
-static UMutex gZoneMetaLock = U_MUTEX_INITIALIZER;
+static icu::UMutex gZoneMetaLock;
 
 // CLDR Canonical ID mapping table
 static UHashtable *gCanonicalIDCache = NULL;
@@ -319,10 +319,10 @@ ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
                 id[len] = (char) 0; // Make sure it is null terminated.
 
                 // replace '/' with ':'
-                char *p = id;
-                while (*p++) {
-                    if (*p == '/') {
-                        *p = ':';
+                char *q = id;
+                while (*q++) {
+                    if (*q == '/') {
+                        *q = ':';
                     }
                 }
 
@@ -690,7 +690,7 @@ ZoneMeta::createMetazoneMappings(const UnicodeString &tzid) {
                     mzMappings = new UVector(deleteOlsonToMetaMappingEntry, NULL, status);
                     if (U_FAILURE(status)) {
                         delete mzMappings;
-                        deleteOlsonToMetaMappingEntry(entry);
+                        mzMappings = NULL;
                         uprv_free(entry);
                         break;
                     }
@@ -766,13 +766,11 @@ static void U_CALLCONV initAvailableMetaZoneIDs () {
     ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
 
     UErrorCode status = U_ZERO_ERROR;
-    gMetaZoneIDTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status);
+    gMetaZoneIDTable = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
     if (U_FAILURE(status) || gMetaZoneIDTable == NULL) {
         gMetaZoneIDTable = NULL;
         return;
     }
-    uhash_setKeyDeleter(gMetaZoneIDTable, uprv_deleteUObject);
-    // No valueDeleter, because the vector maintain the value objects
     gMetaZoneIDs = new UVector(NULL, uhash_compareUChars, status);
     if (U_FAILURE(status) || gMetaZoneIDs == NULL) {
         gMetaZoneIDs = NULL;
@@ -784,15 +782,14 @@ static void U_CALLCONV initAvailableMetaZoneIDs () {
 
     UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
     UResourceBundle *bundle = ures_getByKey(rb, gMapTimezonesTag, NULL, &status);
-    UResourceBundle res;
-    ures_initStackObject(&res);
+    StackUResourceBundle res;
     while (U_SUCCESS(status) && ures_hasNext(bundle)) {
-        ures_getNextResource(bundle, &res, &status);
+        ures_getNextResource(bundle, res.getAlias(), &status);
         if (U_FAILURE(status)) {
             break;
         }
-        const char *mzID = ures_getKey(&res);
-        int32_t len = uprv_strlen(mzID);
+        const char *mzID = ures_getKey(res.getAlias());
+        int32_t len = static_cast<int32_t>(uprv_strlen(mzID));
         UChar *uMzID = (UChar*)uprv_malloc(sizeof(UChar) * (len + 1));
         if (uMzID == NULL) {
             status = U_MEMORY_ALLOCATION_ERROR;
@@ -800,16 +797,13 @@ static void U_CALLCONV initAvailableMetaZoneIDs () {
         }
         u_charsToUChars(mzID, uMzID, len);
         uMzID[len] = 0;
-        UnicodeString *usMzID = new UnicodeString(uMzID);
-        if (uhash_get(gMetaZoneIDTable, usMzID) == NULL) {
+        if (uhash_get(gMetaZoneIDTable, uMzID) == NULL) {
             gMetaZoneIDs->addElement((void *)uMzID, status);
-            uhash_put(gMetaZoneIDTable, (void *)usMzID, (void *)uMzID, &status);
+            uhash_put(gMetaZoneIDTable, (void *)uMzID, (void *)uMzID, &status);
         } else {
             uprv_free(uMzID);
-            delete usMzID;
         }
     }
-    ures_close(&res);
     ures_close(bundle);
     ures_close(rb);
 
@@ -833,7 +827,8 @@ ZoneMeta::findMetaZoneID(const UnicodeString& mzid) {
     if (gMetaZoneIDTable == NULL) {
         return NULL;
     }
-    return (const UChar*)uhash_get(gMetaZoneIDTable, &mzid);
+    UnicodeString localMzid = mzid;
+    return (const UChar*)uhash_get(gMetaZoneIDTable, localMzid.getTerminatedBuffer());
 }
 
 const UChar*
@@ -850,13 +845,13 @@ ZoneMeta::createCustomTimeZone(int32_t offset) {
         negative = TRUE;
         tmp = -offset;
     }
-    int32_t hour, min, sec;
+    uint8_t hour, min, sec;
 
     tmp /= 1000;
-    sec = tmp % 60;
+    sec = static_cast<uint8_t>(tmp % 60);
     tmp /= 60;
-    min = tmp % 60;
-    hour = tmp / 60;
+    min = static_cast<uint8_t>(tmp % 60);
+    hour = static_cast<uint8_t>(tmp / 60);
 
     UnicodeString zid;
     formatCustomID(hour, min, sec, negative, zid);