OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2011-2013, International Business Machines Corporation and | 3 * Copyright (C) 2011-2015, 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 "tzgnames.h" | 12 #include "tzgnames.h" |
13 | 13 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } else if (regionLen < (int32_t)sizeof(fTargetRegion)) { | 427 } else if (regionLen < (int32_t)sizeof(fTargetRegion)) { |
428 uprv_strcpy(fTargetRegion, region); | 428 uprv_strcpy(fTargetRegion, region); |
429 } else { | 429 } else { |
430 fTargetRegion[0] = 0; | 430 fTargetRegion[0] = 0; |
431 } | 431 } |
432 | 432 |
433 // preload generic names for the default zone | 433 // preload generic names for the default zone |
434 TimeZone *tz = TimeZone::createDefault(); | 434 TimeZone *tz = TimeZone::createDefault(); |
435 const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz); | 435 const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz); |
436 if (tzID != NULL) { | 436 if (tzID != NULL) { |
437 loadStrings(UnicodeString(tzID)); | 437 loadStrings(UnicodeString(TRUE, tzID, -1)); |
438 } | 438 } |
439 delete tz; | 439 delete tz; |
440 } | 440 } |
441 | 441 |
442 void | 442 void |
443 TZGNCore::cleanup() { | 443 TZGNCore::cleanup() { |
444 if (fRegionFormat != NULL) { | 444 if (fRegionFormat != NULL) { |
445 delete fRegionFormat; | 445 delete fRegionFormat; |
446 } | 446 } |
447 if (fFallbackFormat != NULL) { | 447 if (fFallbackFormat != NULL) { |
(...skipping 12 matching lines...) Expand all Loading... |
460 | 460 |
461 | 461 |
462 UnicodeString& | 462 UnicodeString& |
463 TZGNCore::getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type, UDat
e date, UnicodeString& name) const { | 463 TZGNCore::getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type, UDat
e date, UnicodeString& name) const { |
464 name.setToBogus(); | 464 name.setToBogus(); |
465 switch (type) { | 465 switch (type) { |
466 case UTZGNM_LOCATION: | 466 case UTZGNM_LOCATION: |
467 { | 467 { |
468 const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz); | 468 const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz); |
469 if (tzCanonicalID != NULL) { | 469 if (tzCanonicalID != NULL) { |
470 getGenericLocationName(UnicodeString(tzCanonicalID), name); | 470 getGenericLocationName(UnicodeString(TRUE, tzCanonicalID, -1), n
ame); |
471 } | 471 } |
472 } | 472 } |
473 break; | 473 break; |
474 case UTZGNM_LONG: | 474 case UTZGNM_LONG: |
475 case UTZGNM_SHORT: | 475 case UTZGNM_SHORT: |
476 formatGenericNonLocationName(tz, type, date, name); | 476 formatGenericNonLocationName(tz, type, date, name); |
477 if (name.isEmpty()) { | 477 if (name.isEmpty()) { |
478 const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz); | 478 const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz); |
479 if (tzCanonicalID != NULL) { | 479 if (tzCanonicalID != NULL) { |
480 getGenericLocationName(UnicodeString(tzCanonicalID), name); | 480 getGenericLocationName(UnicodeString(TRUE, tzCanonicalID, -1), n
ame); |
481 } | 481 } |
482 } | 482 } |
483 break; | 483 break; |
484 default: | 484 default: |
485 break; | 485 break; |
486 } | 486 } |
487 return name; | 487 return name; |
488 } | 488 } |
489 | 489 |
490 UnicodeString& | 490 UnicodeString& |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 UnicodeString& | 613 UnicodeString& |
614 TZGNCore::formatGenericNonLocationName(const TimeZone& tz, UTimeZoneGenericNameT
ype type, UDate date, UnicodeString& name) const { | 614 TZGNCore::formatGenericNonLocationName(const TimeZone& tz, UTimeZoneGenericNameT
ype type, UDate date, UnicodeString& name) const { |
615 U_ASSERT(type == UTZGNM_LONG || type == UTZGNM_SHORT); | 615 U_ASSERT(type == UTZGNM_LONG || type == UTZGNM_SHORT); |
616 name.setToBogus(); | 616 name.setToBogus(); |
617 | 617 |
618 const UChar* uID = ZoneMeta::getCanonicalCLDRID(tz); | 618 const UChar* uID = ZoneMeta::getCanonicalCLDRID(tz); |
619 if (uID == NULL) { | 619 if (uID == NULL) { |
620 return name; | 620 return name; |
621 } | 621 } |
622 | 622 |
623 UnicodeString tzID(uID); | 623 UnicodeString tzID(TRUE, uID, -1); |
624 | 624 |
625 // Try to get a name from time zone first | 625 // Try to get a name from time zone first |
626 UTimeZoneNameType nameType = (type == UTZGNM_LONG) ? UTZNM_LONG_GENERIC : UT
ZNM_SHORT_GENERIC; | 626 UTimeZoneNameType nameType = (type == UTZGNM_LONG) ? UTZNM_LONG_GENERIC : UT
ZNM_SHORT_GENERIC; |
627 fTimeZoneNames->getTimeZoneDisplayName(tzID, nameType, name); | 627 fTimeZoneNames->getTimeZoneDisplayName(tzID, nameType, name); |
628 | 628 |
629 if (!name.isEmpty()) { | 629 if (!name.isEmpty()) { |
630 return name; | 630 return name; |
631 } | 631 } |
632 | 632 |
633 // Try meta zone | 633 // Try meta zone |
634 UnicodeString mzID; | 634 UChar mzIDBuf[32]; |
| 635 UnicodeString mzID(mzIDBuf, 0, UPRV_LENGTHOF(mzIDBuf)); |
635 fTimeZoneNames->getMetaZoneID(tzID, date, mzID); | 636 fTimeZoneNames->getMetaZoneID(tzID, date, mzID); |
636 if (!mzID.isEmpty()) { | 637 if (!mzID.isEmpty()) { |
637 UErrorCode status = U_ZERO_ERROR; | 638 UErrorCode status = U_ZERO_ERROR; |
638 UBool useStandard = FALSE; | 639 UBool useStandard = FALSE; |
639 int32_t raw, sav; | 640 int32_t raw, sav; |
| 641 UChar tmpNameBuf[64]; |
640 | 642 |
641 tz.getOffset(date, FALSE, raw, sav, status); | 643 tz.getOffset(date, FALSE, raw, sav, status); |
642 if (U_FAILURE(status)) { | 644 if (U_FAILURE(status)) { |
643 return name; | 645 return name; |
644 } | 646 } |
645 | 647 |
646 if (sav == 0) { | 648 if (sav == 0) { |
647 useStandard = TRUE; | 649 useStandard = TRUE; |
648 | 650 |
649 TimeZone *tmptz = tz.clone(); | 651 TimeZone *tmptz = tz.clone(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 if (U_FAILURE(status)) { | 689 if (U_FAILURE(status)) { |
688 delete tmptz; | 690 delete tmptz; |
689 return name; | 691 return name; |
690 } | 692 } |
691 } | 693 } |
692 delete tmptz; | 694 delete tmptz; |
693 } | 695 } |
694 if (useStandard) { | 696 if (useStandard) { |
695 UTimeZoneNameType stdNameType = (nameType == UTZNM_LONG_GENERIC) | 697 UTimeZoneNameType stdNameType = (nameType == UTZNM_LONG_GENERIC) |
696 ? UTZNM_LONG_STANDARD : UTZNM_SHORT_STANDARD; | 698 ? UTZNM_LONG_STANDARD : UTZNM_SHORT_STANDARD; |
697 UnicodeString stdName; | 699 UnicodeString stdName(tmpNameBuf, 0, UPRV_LENGTHOF(tmpNameBuf)); |
698 fTimeZoneNames->getDisplayName(tzID, stdNameType, date, stdName); | 700 fTimeZoneNames->getDisplayName(tzID, stdNameType, date, stdName); |
699 if (!stdName.isEmpty()) { | 701 if (!stdName.isEmpty()) { |
700 name.setTo(stdName); | 702 name.setTo(stdName); |
701 | 703 |
702 // TODO: revisit this issue later | 704 // TODO: revisit this issue later |
703 // In CLDR, a same display name is used for both generic and sta
ndard | 705 // In CLDR, a same display name is used for both generic and sta
ndard |
704 // for some meta zones in some locales. This looks like a data
bugs. | 706 // for some meta zones in some locales. This looks like a data
bugs. |
705 // For now, we check if the standard name is different from its
generic | 707 // For now, we check if the standard name is different from its
generic |
706 // name below. | 708 // name below. |
707 UnicodeString mzGenericName; | 709 UChar genNameBuf[64]; |
| 710 UnicodeString mzGenericName(genNameBuf, 0, UPRV_LENGTHOF(genName
Buf)); |
708 fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzGeneric
Name); | 711 fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzGeneric
Name); |
709 if (stdName.caseCompare(mzGenericName, 0) == 0) { | 712 if (stdName.caseCompare(mzGenericName, 0) == 0) { |
710 name.setToBogus(); | 713 name.setToBogus(); |
711 } | 714 } |
712 } | 715 } |
713 } | 716 } |
714 if (name.isEmpty()) { | 717 if (name.isEmpty()) { |
715 // Get a name from meta zone | 718 // Get a name from meta zone |
716 UnicodeString mzName; | 719 UnicodeString mzName(tmpNameBuf, 0, UPRV_LENGTHOF(tmpNameBuf)); |
717 fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzName); | 720 fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzName); |
718 if (!mzName.isEmpty()) { | 721 if (!mzName.isEmpty()) { |
719 // Check if we need to use a partial location format. | 722 // Check if we need to use a partial location format. |
720 // This check is done by comparing offset with the meta zone's | 723 // This check is done by comparing offset with the meta zone's |
721 // golden zone at the given date. | 724 // golden zone at the given date. |
722 UnicodeString goldenID; | 725 UChar idBuf[32]; |
| 726 UnicodeString goldenID(idBuf, 0, UPRV_LENGTHOF(idBuf)); |
723 fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, goldenID
); | 727 fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, goldenID
); |
724 if (!goldenID.isEmpty() && goldenID != tzID) { | 728 if (!goldenID.isEmpty() && goldenID != tzID) { |
725 TimeZone *goldenZone = TimeZone::createTimeZone(goldenID); | 729 TimeZone *goldenZone = TimeZone::createTimeZone(goldenID); |
726 int32_t raw1, sav1; | 730 int32_t raw1, sav1; |
727 | 731 |
728 // Check offset in the golden zone with wall time. | 732 // Check offset in the golden zone with wall time. |
729 // With getOffset(date, false, offsets1), | 733 // With getOffset(date, false, offsets1), |
730 // you may get incorrect results because of time overlap at
DST->STD | 734 // you may get incorrect results because of time overlap at
DST->STD |
731 // transition. | 735 // transition. |
732 goldenZone->getOffset(date + raw + sav, TRUE, raw1, sav1, st
atus); | 736 goldenZone->getOffset(date + raw + sav, TRUE, raw1, sav1, st
atus); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 uprv_free(entry); | 1182 uprv_free(entry); |
1179 } | 1183 } |
1180 U_CDECL_END | 1184 U_CDECL_END |
1181 | 1185 |
1182 /** | 1186 /** |
1183 * Function used for removing unreferrenced cache entries exceeding | 1187 * Function used for removing unreferrenced cache entries exceeding |
1184 * the expiration time. This function must be called with in the mutex | 1188 * the expiration time. This function must be called with in the mutex |
1185 * block. | 1189 * block. |
1186 */ | 1190 */ |
1187 static void sweepCache() { | 1191 static void sweepCache() { |
1188 int32_t pos = -1; | 1192 int32_t pos = UHASH_FIRST; |
1189 const UHashElement* elem; | 1193 const UHashElement* elem; |
1190 double now = (double)uprv_getUTCtime(); | 1194 double now = (double)uprv_getUTCtime(); |
1191 | 1195 |
1192 while ((elem = uhash_nextElement(gTZGNCoreCache, &pos))) { | 1196 while ((elem = uhash_nextElement(gTZGNCoreCache, &pos))) { |
1193 TZGNCoreRef *entry = (TZGNCoreRef *)elem->value.pointer; | 1197 TZGNCoreRef *entry = (TZGNCoreRef *)elem->value.pointer; |
1194 if (entry->refCount <= 0 && (now - entry->lastAccess) > CACHE_EXPIRATION
) { | 1198 if (entry->refCount <= 0 && (now - entry->lastAccess) > CACHE_EXPIRATION
) { |
1195 // delete this entry | 1199 // delete this entry |
1196 uhash_removeElement(gTZGNCoreCache, elem); | 1200 uhash_removeElement(gTZGNCoreCache, elem); |
1197 } | 1201 } |
1198 } | 1202 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 } | 1344 } |
1341 | 1345 |
1342 int32_t | 1346 int32_t |
1343 TimeZoneGenericNames::findBestMatch(const UnicodeString& text, int32_t start, ui
nt32_t types, | 1347 TimeZoneGenericNames::findBestMatch(const UnicodeString& text, int32_t start, ui
nt32_t types, |
1344 UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& stat
us) const { | 1348 UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& stat
us) const { |
1345 return fRef->obj->findBestMatch(text, start, types, tzID, timeType, status); | 1349 return fRef->obj->findBestMatch(text, start, types, tzID, timeType, status); |
1346 } | 1350 } |
1347 | 1351 |
1348 U_NAMESPACE_END | 1352 U_NAMESPACE_END |
1349 #endif | 1353 #endif |
OLD | NEW |