diff options
author | romankoshelev <romankoshelev@yandex-team.com> | 2023-08-14 19:51:50 +0300 |
---|---|---|
committer | romankoshelev <romankoshelev@yandex-team.com> | 2023-08-15 01:24:11 +0300 |
commit | cfcd865e05c0d0525ea27d1e153a043b32a85138 (patch) | |
tree | 68d3b3b25271e8a4998505897a269ff7ce119b76 /contrib/libs/icu/i18n/rbtz.cpp | |
parent | ccb790c507bd5e8ffe2ef9886ce5ee0a7ce22a15 (diff) | |
download | ydb-cfcd865e05c0d0525ea27d1e153a043b32a85138.tar.gz |
Update ICU to 73.2
Diffstat (limited to 'contrib/libs/icu/i18n/rbtz.cpp')
-rw-r--r-- | contrib/libs/icu/i18n/rbtz.cpp | 229 |
1 files changed, 114 insertions, 115 deletions
diff --git a/contrib/libs/icu/i18n/rbtz.cpp b/contrib/libs/icu/i18n/rbtz.cpp index 495d8310d0..e4d71436c5 100644 --- a/contrib/libs/icu/i18n/rbtz.cpp +++ b/contrib/libs/icu/i18n/rbtz.cpp @@ -39,35 +39,35 @@ deleteTransition(void* obj) { U_CDECL_END static UBool compareRules(UVector* rules1, UVector* rules2) { - if (rules1 == NULL && rules2 == NULL) { - return TRUE; - } else if (rules1 == NULL || rules2 == NULL) { - return FALSE; + if (rules1 == nullptr && rules2 == nullptr) { + return true; + } else if (rules1 == nullptr || rules2 == nullptr) { + return false; } int32_t size = rules1->size(); if (size != rules2->size()) { - return FALSE; + return false; } for (int32_t i = 0; i < size; i++) { TimeZoneRule *r1 = (TimeZoneRule*)rules1->elementAt(i); TimeZoneRule *r2 = (TimeZoneRule*)rules2->elementAt(i); if (*r1 != *r2) { - return FALSE; + return false; } } - return TRUE; + return true; } UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedTimeZone) RuleBasedTimeZone::RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule) -: BasicTimeZone(id), fInitialRule(initialRule), fHistoricRules(NULL), fFinalRules(NULL), - fHistoricTransitions(NULL), fUpToDate(FALSE) { +: BasicTimeZone(id), fInitialRule(initialRule), fHistoricRules(nullptr), fFinalRules(nullptr), + fHistoricTransitions(nullptr), fUpToDate(false) { } RuleBasedTimeZone::RuleBasedTimeZone(const RuleBasedTimeZone& source) : BasicTimeZone(source), fInitialRule(source.fInitialRule->clone()), - fHistoricTransitions(NULL), fUpToDate(FALSE) { + fHistoricTransitions(nullptr), fUpToDate(false) { fHistoricRules = copyRules(source.fHistoricRules); fFinalRules = copyRules(source.fFinalRules); if (source.fUpToDate) { @@ -90,7 +90,7 @@ RuleBasedTimeZone::operator=(const RuleBasedTimeZone& right) { fHistoricRules = copyRules(right.fHistoricRules); fFinalRules = copyRules(right.fFinalRules); deleteTransitions(); - fUpToDate = FALSE; + fUpToDate = false; } return *this; } @@ -152,7 +152,7 @@ RuleBasedTimeZone::addTransitionRule(TimeZoneRule* rule, UErrorCode& status) { fHistoricRules->adoptElement(lpRule.orphan(), status); } // Mark dirty, so transitions are recalculated at next complete() call - fUpToDate = FALSE; + fUpToDate = false; } @@ -180,35 +180,35 @@ RuleBasedTimeZone::complete(UErrorCode& status) { } // Make sure either no final rules or a pair of AnnualTimeZoneRules // are available. - if (fFinalRules != NULL && fFinalRules->size() != 2) { + if (fFinalRules != nullptr && fFinalRules->size() != 2) { status = U_INVALID_STATE_ERROR; return; } // Create a TimezoneTransition and add to the list - if (fHistoricRules != NULL || fFinalRules != NULL) { + if (fHistoricRules != nullptr || fFinalRules != nullptr) { TimeZoneRule *curRule = fInitialRule; UDate lastTransitionTime = MIN_MILLIS; // Build the transition array which represents historical time zone // transitions. - if (fHistoricRules != NULL && fHistoricRules->size() > 0) { + if (fHistoricRules != nullptr && fHistoricRules->size() > 0) { int32_t i; int32_t historicCount = fHistoricRules->size(); LocalMemory<bool> done((bool *)uprv_malloc(sizeof(bool) * historicCount)); - if (done == NULL) { + if (done == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; goto cleanup; } for (i = 0; i < historicCount; i++) { done[i] = false; } - while (TRUE) { + while (true) { int32_t curStdOffset = curRule->getRawOffset(); int32_t curDstSavings = curRule->getDSTSavings(); UDate nextTransitionTime = MAX_MILLIS; - TimeZoneRule *nextRule = NULL; - TimeZoneRule *r = NULL; + TimeZoneRule *nextRule = nullptr; + TimeZoneRule *r = nullptr; UBool avail; UDate tt; UnicodeString curName, name; @@ -237,12 +237,12 @@ RuleBasedTimeZone::complete(UErrorCode& status) { } } - if (nextRule == NULL) { + if (nextRule == nullptr) { // Check if all historic rules are done - UBool bDoneAll = TRUE; + UBool bDoneAll = true; for (int32_t j = 0; j < historicCount; j++) { if (!done[j]) { - bDoneAll = FALSE; + bDoneAll = false; break; } } @@ -251,7 +251,7 @@ RuleBasedTimeZone::complete(UErrorCode& status) { } } - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { // Check if one of final rules has earlier transition date for (i = 0; i < 2 /* fFinalRules->size() */; i++) { TimeZoneRule *fr = (TimeZoneRule*)fFinalRules->elementAt(i); @@ -269,12 +269,12 @@ RuleBasedTimeZone::complete(UErrorCode& status) { } } - if (nextRule == NULL) { + if (nextRule == nullptr) { // Nothing more break; } - if (fHistoricTransitions == NULL) { + if (fHistoricTransitions == nullptr) { LocalPointer<UVector> lpHistoricTransitions( new UVector(deleteTransition, nullptr, status), status); if (U_FAILURE(status)) { @@ -297,8 +297,8 @@ RuleBasedTimeZone::complete(UErrorCode& status) { curRule = nextRule; } } - if (fFinalRules != NULL) { - if (fHistoricTransitions == NULL) { + if (fFinalRules != nullptr) { + if (fHistoricTransitions == nullptr) { LocalPointer<UVector> lpHistoricTransitions( new UVector(deleteTransition, nullptr, status), status); if (U_FAILURE(status)) { @@ -344,12 +344,12 @@ RuleBasedTimeZone::complete(UErrorCode& status) { } } } - fUpToDate = TRUE; + fUpToDate = true; return; cleanup: deleteTransitions(); - fUpToDate = FALSE; + fUpToDate = false; } RuleBasedTimeZone* @@ -386,7 +386,7 @@ RuleBasedTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t d } int32_t rawOffset, dstOffset; UDate time = (UDate)Grego::fieldsToDay(year, month, day) * U_MILLIS_PER_DAY + millis; - getOffsetInternal(time, TRUE, kDaylight, kStandard, rawOffset, dstOffset, status); + getOffsetInternal(time, true, kDaylight, kStandard, rawOffset, dstOffset, status); if (U_FAILURE(status)) { return 0; } @@ -402,7 +402,7 @@ RuleBasedTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset, void RuleBasedTimeZone::getOffsetFromLocal(UDate date, UTimeZoneLocalOption nonExistingTimeOpt, UTimeZoneLocalOption duplicatedTimeOpt, int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const { - getOffsetInternal(date, TRUE, nonExistingTimeOpt, duplicatedTimeOpt, rawOffset, dstOffset, status); + getOffsetInternal(date, true, nonExistingTimeOpt, duplicatedTimeOpt, rawOffset, dstOffset, status); } @@ -427,8 +427,8 @@ RuleBasedTimeZone::getOffsetInternal(UDate date, UBool local, status = U_INVALID_STATE_ERROR; return; } - const TimeZoneRule *rule = NULL; - if (fHistoricTransitions == NULL) { + const TimeZoneRule *rule = nullptr; + if (fHistoricTransitions == nullptr) { rule = fInitialRule; } else { UDate tstart = getTransitionTime((Transition*)fHistoricTransitions->elementAt(0), @@ -440,10 +440,10 @@ RuleBasedTimeZone::getOffsetInternal(UDate date, UBool local, UDate tend = getTransitionTime((Transition*)fHistoricTransitions->elementAt(idx), local, NonExistingTimeOpt, DuplicatedTimeOpt); if (date > tend) { - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { rule = findRuleInFinal(date, local, NonExistingTimeOpt, DuplicatedTimeOpt); } - if (rule == NULL) { + if (rule == nullptr) { // no final rules or the given time is before the first transition // specified by the final rules -> use the last rule rule = ((Transition*)fHistoricTransitions->elementAt(idx))->to; @@ -461,7 +461,7 @@ RuleBasedTimeZone::getOffsetInternal(UDate date, UBool local, } } } - if (rule != NULL) { + if (rule != nullptr) { rawOffset = rule->getRawOffset(); dstOffset = rule->getDSTSavings(); } @@ -474,68 +474,67 @@ RuleBasedTimeZone::setRawOffset(int32_t /*offsetMillis*/) { } int32_t -RuleBasedTimeZone::getRawOffset(void) const { +RuleBasedTimeZone::getRawOffset() const { // Note: This implementation returns standard GMT offset // as of current time. UErrorCode status = U_ZERO_ERROR; int32_t raw, dst; - getOffset(uprv_getUTCtime() * U_MILLIS_PER_SECOND, - FALSE, raw, dst, status); + getOffset(uprv_getUTCtime(), false, raw, dst, status); return raw; } UBool -RuleBasedTimeZone::useDaylightTime(void) const { +RuleBasedTimeZone::useDaylightTime() const { // Note: This implementation returns true when // daylight saving time is used as of now or // after the next transition. UErrorCode status = U_ZERO_ERROR; - UDate now = uprv_getUTCtime() * U_MILLIS_PER_SECOND; + UDate now = uprv_getUTCtime(); int32_t raw, dst; - getOffset(now, FALSE, raw, dst, status); + getOffset(now, false, raw, dst, status); if (dst != 0) { - return TRUE; + return true; } // If DST is not used now, check if DST is used after the next transition UDate time; TimeZoneRule *from, *to; - UBool avail = findNext(now, FALSE, time, from, to); + UBool avail = findNext(now, false, time, from, to); if (avail && to->getDSTSavings() != 0) { - return TRUE; + return true; } - return FALSE; + return false; } UBool RuleBasedTimeZone::inDaylightTime(UDate date, UErrorCode& status) const { if (U_FAILURE(status)) { - return FALSE; + return false; } int32_t raw, dst; - getOffset(date, FALSE, raw, dst, status); + getOffset(date, false, raw, dst, status); if (dst != 0) { - return TRUE; + return true; } - return FALSE; + return false; } UBool RuleBasedTimeZone::hasSameRules(const TimeZone& other) const { if (this == &other) { - return TRUE; + return true; } if (typeid(*this) != typeid(other)) { - return FALSE; + return false; } - const RuleBasedTimeZone& that = (const RuleBasedTimeZone&)other; + const RuleBasedTimeZone& that = static_cast<const RuleBasedTimeZone&>(other); if (*fInitialRule != *(that.fInitialRule)) { - return FALSE; + return false; } if (compareRules(fHistoricRules, that.fHistoricRules) && compareRules(fFinalRules, that.fFinalRules)) { - return TRUE; + return true; } - return FALSE; + return false; } UBool @@ -543,18 +542,18 @@ RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransi UErrorCode status = U_ZERO_ERROR; completeConst(status); if (U_FAILURE(status)) { - return FALSE; + return false; } UDate transitionTime; TimeZoneRule *fromRule, *toRule; UBool found = findNext(base, inclusive, transitionTime, fromRule, toRule); if (found) { result.setTime(transitionTime); - result.setFrom((const TimeZoneRule&)*fromRule); - result.setTo((const TimeZoneRule&)*toRule); - return TRUE; + result.setFrom(*fromRule); + result.setTo(*toRule); + return true; } - return FALSE; + return false; } UBool @@ -562,27 +561,27 @@ RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTr UErrorCode status = U_ZERO_ERROR; completeConst(status); if (U_FAILURE(status)) { - return FALSE; + return false; } UDate transitionTime; TimeZoneRule *fromRule, *toRule; UBool found = findPrev(base, inclusive, transitionTime, fromRule, toRule); if (found) { result.setTime(transitionTime); - result.setFrom((const TimeZoneRule&)*fromRule); - result.setTo((const TimeZoneRule&)*toRule); - return TRUE; + result.setFrom(*fromRule); + result.setTo(*toRule); + return true; } - return FALSE; + return false; } int32_t RuleBasedTimeZone::countTransitionRules(UErrorCode& /*status*/) const { int32_t count = 0; - if (fHistoricRules != NULL) { + if (fHistoricRules != nullptr) { count += fHistoricRules->size(); } - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { count += fFinalRules->size(); } return count; @@ -602,14 +601,14 @@ RuleBasedTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial, // Transition rules int32_t cnt = 0; int32_t idx; - if (fHistoricRules != NULL && cnt < trscount) { + if (fHistoricRules != nullptr && cnt < trscount) { int32_t historicCount = fHistoricRules->size(); idx = 0; while (cnt < trscount && idx < historicCount) { trsrules[cnt++] = (const TimeZoneRule*)fHistoricRules->elementAt(idx++); } } - if (fFinalRules != NULL && cnt < trscount) { + if (fFinalRules != nullptr && cnt < trscount) { int32_t finalCount = fFinalRules->size(); idx = 0; while (cnt < trscount && idx < finalCount) { @@ -621,25 +620,25 @@ RuleBasedTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial, } void -RuleBasedTimeZone::deleteRules(void) { +RuleBasedTimeZone::deleteRules() { delete fInitialRule; - fInitialRule = NULL; - if (fHistoricRules != NULL) { + fInitialRule = nullptr; + if (fHistoricRules != nullptr) { delete fHistoricRules; - fHistoricRules = NULL; + fHistoricRules = nullptr; } - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { delete fFinalRules; - fFinalRules = NULL; + fFinalRules = nullptr; } } void -RuleBasedTimeZone::deleteTransitions(void) { - if (fHistoricTransitions != NULL) { +RuleBasedTimeZone::deleteTransitions() { + if (fHistoricTransitions != nullptr) { delete fHistoricTransitions; } - fHistoricTransitions = NULL; + fHistoricTransitions = nullptr; } UVector* @@ -667,14 +666,14 @@ RuleBasedTimeZone::copyRules(UVector* source) { TimeZoneRule* RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local, int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const { - if (fFinalRules == NULL) { - return NULL; + if (fFinalRules == nullptr) { + return nullptr; } AnnualTimeZoneRule* fr0 = (AnnualTimeZoneRule*)fFinalRules->elementAt(0); AnnualTimeZoneRule* fr1 = (AnnualTimeZoneRule*)fFinalRules->elementAt(1); - if (fr0 == NULL || fr1 == NULL) { - return NULL; + if (fr0 == nullptr || fr1 == nullptr) { + return nullptr; } UDate start0, start1; @@ -688,7 +687,7 @@ RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local, NonExistingTimeOpt, DuplicatedTimeOpt); base -= localDelta; } - UBool avail0 = fr0->getPreviousStart(base, fr1->getRawOffset(), fr1->getDSTSavings(), TRUE, start0); + UBool avail0 = fr0->getPreviousStart(base, fr1->getRawOffset(), fr1->getDSTSavings(), true, start0); base = date; if (local) { @@ -697,7 +696,7 @@ RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local, NonExistingTimeOpt, DuplicatedTimeOpt); base -= localDelta; } - UBool avail1 = fr1->getPreviousStart(base, fr0->getRawOffset(), fr0->getDSTSavings(), TRUE, start1); + UBool avail1 = fr1->getPreviousStart(base, fr0->getRawOffset(), fr0->getDSTSavings(), true, start1); if (!avail0 || !avail1) { if (avail0) { @@ -706,7 +705,7 @@ RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local, return fr1; } // Both rules take effect after the given time - return NULL; + return nullptr; } return (start0 > start1) ? fr0 : fr1; @@ -715,35 +714,35 @@ RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local, UBool RuleBasedTimeZone::findNext(UDate base, UBool inclusive, UDate& transitionTime, TimeZoneRule*& fromRule, TimeZoneRule*& toRule) const { - if (fHistoricTransitions == NULL) { - return FALSE; + if (fHistoricTransitions == nullptr) { + return false; } - UBool isFinal = FALSE; - UBool found = FALSE; + UBool isFinal = false; + UBool found = false; Transition result; Transition *tzt = (Transition*)fHistoricTransitions->elementAt(0); UDate tt = tzt->time; if (tt > base || (inclusive && tt == base)) { result = *tzt; - found = TRUE; + found = true; } else { int32_t idx = fHistoricTransitions->size() - 1; tzt = (Transition*)fHistoricTransitions->elementAt(idx); tt = tzt->time; if (inclusive && tt == base) { result = *tzt; - found = TRUE; + found = true; } else if (tt <= base) { - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { // Find a transion time with finalRules TimeZoneRule *r0 = (TimeZoneRule*)fFinalRules->elementAt(0); TimeZoneRule *r1 = (TimeZoneRule*)fFinalRules->elementAt(1); UDate start0, start1; UBool avail0 = r0->getNextStart(base, r1->getRawOffset(), r1->getDSTSavings(), inclusive, start0); UBool avail1 = r1->getNextStart(base, r0->getRawOffset(), r0->getDSTSavings(), inclusive, start1); - // avail0/avail1 should be always TRUE + // avail0/avail1 should be always true if (!avail0 && !avail1) { - return FALSE; + return false; } if (!avail1 || start0 < start1) { result.time = start0; @@ -754,8 +753,8 @@ RuleBasedTimeZone::findNext(UDate base, UBool inclusive, UDate& transitionTime, result.from = r0; result.to = r1; } - isFinal = TRUE; - found = TRUE; + isFinal = true; + found = true; } } else { // Find a transition within the historic transitions @@ -773,7 +772,7 @@ RuleBasedTimeZone::findNext(UDate base, UBool inclusive, UDate& transitionTime, result.time = prev->time; result.from = prev->from; result.to = prev->to; - found = TRUE; + found = true; } } if (found) { @@ -781,52 +780,52 @@ RuleBasedTimeZone::findNext(UDate base, UBool inclusive, UDate& transitionTime, if (result.from->getRawOffset() == result.to->getRawOffset() && result.from->getDSTSavings() == result.to->getDSTSavings()) { if (isFinal) { - return FALSE; + return false; } else { // No offset changes. Try next one if not final - return findNext(result.time, FALSE /* always exclusive */, + return findNext(result.time, false /* always exclusive */, transitionTime, fromRule, toRule); } } transitionTime = result.time; fromRule = result.from; toRule = result.to; - return TRUE; + return true; } - return FALSE; + return false; } UBool RuleBasedTimeZone::findPrev(UDate base, UBool inclusive, UDate& transitionTime, TimeZoneRule*& fromRule, TimeZoneRule*& toRule) const { - if (fHistoricTransitions == NULL) { - return FALSE; + if (fHistoricTransitions == nullptr) { + return false; } - UBool found = FALSE; + UBool found = false; Transition result; Transition *tzt = (Transition*)fHistoricTransitions->elementAt(0); UDate tt = tzt->time; if (inclusive && tt == base) { result = *tzt; - found = TRUE; + found = true; } else if (tt < base) { int32_t idx = fHistoricTransitions->size() - 1; tzt = (Transition*)fHistoricTransitions->elementAt(idx); tt = tzt->time; if (inclusive && tt == base) { result = *tzt; - found = TRUE; + found = true; } else if (tt < base) { - if (fFinalRules != NULL) { + if (fFinalRules != nullptr) { // Find a transion time with finalRules TimeZoneRule *r0 = (TimeZoneRule*)fFinalRules->elementAt(0); TimeZoneRule *r1 = (TimeZoneRule*)fFinalRules->elementAt(1); UDate start0, start1; UBool avail0 = r0->getPreviousStart(base, r1->getRawOffset(), r1->getDSTSavings(), inclusive, start0); UBool avail1 = r1->getPreviousStart(base, r0->getRawOffset(), r0->getDSTSavings(), inclusive, start1); - // avail0/avail1 should be always TRUE + // avail0/avail1 should be always true if (!avail0 && !avail1) { - return FALSE; + return false; } if (!avail1 || start0 > start1) { result.time = start0; @@ -840,7 +839,7 @@ RuleBasedTimeZone::findPrev(UDate base, UBool inclusive, UDate& transitionTime, } else { result = *tzt; } - found = TRUE; + found = true; } else { // Find a transition within the historic transitions idx--; @@ -853,7 +852,7 @@ RuleBasedTimeZone::findPrev(UDate base, UBool inclusive, UDate& transitionTime, idx--; } result = *tzt; - found = TRUE; + found = true; } } if (found) { @@ -861,15 +860,15 @@ RuleBasedTimeZone::findPrev(UDate base, UBool inclusive, UDate& transitionTime, if (result.from->getRawOffset() == result.to->getRawOffset() && result.from->getDSTSavings() == result.to->getDSTSavings()) { // No offset changes. Try next one if not final - return findPrev(result.time, FALSE /* always exclusive */, + return findPrev(result.time, false /* always exclusive */, transitionTime, fromRule, toRule); } transitionTime = result.time; fromRule = result.from; toRule = result.to; - return TRUE; + return true; } - return FALSE; + return false; } UDate |