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

Side by Side Diff: source/i18n/zonemeta.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 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 | « source/i18n/wintzimpl.cpp ('k') | source/icudefs.mk.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ******************************************************************************* 2 *******************************************************************************
3 * Copyright (C) 2007-2013, International Business Machines Corporation and 3 * Copyright (C) 2007-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 */ 6 */
7 7
8 #include "unicode/utypes.h" 8 #include "unicode/utypes.h"
9 9
10 #if !UCONFIG_NO_FORMATTING 10 #if !UCONFIG_NO_FORMATTING
11 11
12 #include "zonemeta.h" 12 #include "zonemeta.h"
13 13
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); 228 ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
229 } 229 }
230 230
231 231
232 const UChar* U_EXPORT2 232 const UChar* U_EXPORT2
233 ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) { 233 ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
234 if (U_FAILURE(status)) { 234 if (U_FAILURE(status)) {
235 return NULL; 235 return NULL;
236 } 236 }
237 237
238 int32_t len = tzid.length(); 238 if (tzid.isBogus() || tzid.length() > ZID_KEY_MAX) {
239 if (len > ZID_KEY_MAX) {
240 status = U_ILLEGAL_ARGUMENT_ERROR; 239 status = U_ILLEGAL_ARGUMENT_ERROR;
241 return NULL; 240 return NULL;
242 } 241 }
243 242
244 // Checking the cached results 243 // Checking the cached results
245 umtx_initOnce(gCanonicalIDCacheInitOnce, &initCanonicalIDCache, status); 244 umtx_initOnce(gCanonicalIDCacheInitOnce, &initCanonicalIDCache, status);
246 if (U_FAILURE(status)) { 245 if (U_FAILURE(status)) {
247 return NULL; 246 return NULL;
248 } 247 }
249 248
(...skipping 11 matching lines...) Expand all
261 } 260 }
262 umtx_unlock(&gZoneMetaLock); 261 umtx_unlock(&gZoneMetaLock);
263 262
264 if (canonicalID != NULL) { 263 if (canonicalID != NULL) {
265 return canonicalID; 264 return canonicalID;
266 } 265 }
267 266
268 // If not, resolve CLDR canonical ID with resource data 267 // If not, resolve CLDR canonical ID with resource data
269 UBool isInputCanonical = FALSE; 268 UBool isInputCanonical = FALSE;
270 char id[ZID_KEY_MAX + 1]; 269 char id[ZID_KEY_MAX + 1];
271 const UChar* idChars = tzid.getBuffer(); 270 tzid.extract(0, 0x7fffffff, id, UPRV_LENGTHOF(id), US_INV);
272
273 u_UCharsToChars(idChars,id,len);
274 id[len] = (char) 0; // Make sure it is null terminated.
275 271
276 // replace '/' with ':' 272 // replace '/' with ':'
277 char *p = id; 273 char *p = id;
278 while (*p++) { 274 while (*p++) {
279 if (*p == '/') { 275 if (*p == '/') {
280 *p = ':'; 276 *p = ':';
281 } 277 }
282 } 278 }
283 279
284 UResourceBundle *top = ures_openDirect(NULL, gKeyTypeData, &tmpStatus); 280 UResourceBundle *top = ures_openDirect(NULL, gKeyTypeData, &tmpStatus);
(...skipping 17 matching lines...) Expand all
302 // canonical map found 298 // canonical map found
303 canonicalID = canonical; 299 canonicalID = canonical;
304 } 300 }
305 301
306 if (canonicalID == NULL) { 302 if (canonicalID == NULL) {
307 // Dereference the input ID using the tz data 303 // Dereference the input ID using the tz data
308 const UChar *derefer = TimeZone::dereferOlsonLink(tzid); 304 const UChar *derefer = TimeZone::dereferOlsonLink(tzid);
309 if (derefer == NULL) { 305 if (derefer == NULL) {
310 status = U_ILLEGAL_ARGUMENT_ERROR; 306 status = U_ILLEGAL_ARGUMENT_ERROR;
311 } else { 307 } else {
312 len = u_strlen(derefer); 308 int32_t len = u_strlen(derefer);
313 u_UCharsToChars(derefer,id,len); 309 u_UCharsToChars(derefer,id,len);
314 id[len] = (char) 0; // Make sure it is null terminated. 310 id[len] = (char) 0; // Make sure it is null terminated.
315 311
316 // replace '/' with ':' 312 // replace '/' with ':'
317 char *p = id; 313 char *p = id;
318 while (*p++) { 314 while (*p++) {
319 if (*p == '/') { 315 if (*p == '/') {
320 *p = ':'; 316 *p = ':';
321 } 317 }
322 } 318 }
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 706 }
711 707
712 UnicodeString& U_EXPORT2 708 UnicodeString& U_EXPORT2
713 ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &re gion, UnicodeString &result) { 709 ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &re gion, UnicodeString &result) {
714 UErrorCode status = U_ZERO_ERROR; 710 UErrorCode status = U_ZERO_ERROR;
715 const UChar *tzid = NULL; 711 const UChar *tzid = NULL;
716 int32_t tzidLen = 0; 712 int32_t tzidLen = 0;
717 char keyBuf[ZID_KEY_MAX + 1]; 713 char keyBuf[ZID_KEY_MAX + 1];
718 int32_t keyLen = 0; 714 int32_t keyLen = 0;
719 715
720 if (mzid.length() > ZID_KEY_MAX) { 716 if (mzid.isBogus() || mzid.length() > ZID_KEY_MAX) {
721 result.setToBogus(); 717 result.setToBogus();
722 return result; 718 return result;
723 } 719 }
724 720
725 keyLen = mzid.extract(0, mzid.length(), keyBuf, ZID_KEY_MAX + 1, US_INV); 721 keyLen = mzid.extract(0, mzid.length(), keyBuf, ZID_KEY_MAX + 1, US_INV);
726 keyBuf[keyLen] = 0; 722 keyBuf[keyLen] = 0;
727 723
728 UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status); 724 UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
729 ures_getByKey(rb, gMapTimezonesTag, rb, &status); 725 ures_getByKey(rb, gMapTimezonesTag, rb, &status);
730 ures_getByKey(rb, keyBuf, rb, &status); 726 ures_getByKey(rb, keyBuf, rb, &status);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 ures_getByKey(rb, gTimezoneTag, rb, &status); 926 ures_getByKey(rb, gTimezoneTag, rb, &status);
931 shortID = ures_getStringByKey(rb, tzidKey, NULL, &status); 927 shortID = ures_getStringByKey(rb, tzidKey, NULL, &status);
932 ures_close(rb); 928 ures_close(rb);
933 929
934 return shortID; 930 return shortID;
935 } 931 }
936 932
937 U_NAMESPACE_END 933 U_NAMESPACE_END
938 934
939 #endif /* #if !UCONFIG_NO_FORMATTING */ 935 #endif /* #if !UCONFIG_NO_FORMATTING */
OLDNEW
« no previous file with comments | « source/i18n/wintzimpl.cpp ('k') | source/icudefs.mk.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698