aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/timezone.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:15 +0300
commite9d19cec64684c9c1e6b0c98297e5b895cf904fe (patch)
tree2768b1223e96a8a0610a93d18425d9647c1123c8 /contrib/libs/icu/i18n/timezone.cpp
parent60040c91ffe701a84689b2c6310ff845e65cff42 (diff)
downloadydb-e9d19cec64684c9c1e6b0c98297e5b895cf904fe.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/icu/i18n/timezone.cpp')
-rw-r--r--contrib/libs/icu/i18n/timezone.cpp186
1 files changed, 93 insertions, 93 deletions
diff --git a/contrib/libs/icu/i18n/timezone.cpp b/contrib/libs/icu/i18n/timezone.cpp
index 284334ebf7..2ed29b0a34 100644
--- a/contrib/libs/icu/i18n/timezone.cpp
+++ b/contrib/libs/icu/i18n/timezone.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
@@ -115,14 +115,14 @@ static const int32_t UNKNOWN_ZONE_ID_LENGTH = 11;
static icu::TimeZone* DEFAULT_ZONE = NULL;
static icu::UInitOnce gDefaultZoneInitOnce = U_INITONCE_INITIALIZER;
-alignas(icu::SimpleTimeZone)
-static char gRawGMT[sizeof(icu::SimpleTimeZone)];
-
-alignas(icu::SimpleTimeZone)
-static char gRawUNKNOWN[sizeof(icu::SimpleTimeZone)];
-
+alignas(icu::SimpleTimeZone)
+static char gRawGMT[sizeof(icu::SimpleTimeZone)];
+
+alignas(icu::SimpleTimeZone)
+static char gRawUNKNOWN[sizeof(icu::SimpleTimeZone)];
+
static icu::UInitOnce gStaticZonesInitOnce = U_INITONCE_INITIALIZER;
-static UBool gStaticZonesInitialized = FALSE; // Whether the static zones are initialized and ready to use.
+static UBool gStaticZonesInitialized = FALSE; // Whether the static zones are initialized and ready to use.
static char TZDATA_VERSION[16];
static icu::UInitOnce gTZDataVersionInitOnce = U_INITONCE_INITIALIZER;
@@ -147,12 +147,12 @@ static UBool U_CALLCONV timeZone_cleanup(void)
DEFAULT_ZONE = NULL;
gDefaultZoneInitOnce.reset();
- if (gStaticZonesInitialized) {
- reinterpret_cast<SimpleTimeZone*>(gRawGMT)->~SimpleTimeZone();
- reinterpret_cast<SimpleTimeZone*>(gRawUNKNOWN)->~SimpleTimeZone();
- gStaticZonesInitialized = FALSE;
- gStaticZonesInitOnce.reset();
- }
+ if (gStaticZonesInitialized) {
+ reinterpret_cast<SimpleTimeZone*>(gRawGMT)->~SimpleTimeZone();
+ reinterpret_cast<SimpleTimeZone*>(gRawUNKNOWN)->~SimpleTimeZone();
+ gStaticZonesInitialized = FALSE;
+ gStaticZonesInitOnce.reset();
+ }
uprv_memset(TZDATA_VERSION, 0, sizeof(TZDATA_VERSION));
gTZDataVersionInitOnce.reset();
@@ -278,7 +278,7 @@ static UResourceBundle* openOlsonResource(const UnicodeString& id,
UResourceBundle& res,
UErrorCode& ec)
{
-#ifdef U_DEBUG_TZ
+#ifdef U_DEBUG_TZ
char buf[128];
id.extract(0, sizeof(buf)-1, buf, sizeof(buf), "");
#endif
@@ -310,12 +310,12 @@ void U_CALLCONV initStaticTimeZones() {
// Initialize _GMT independently of other static data; it should
// be valid even if we can't load the time zone UDataMemory.
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
-
- // new can't fail below, as we use placement new into staticly allocated space.
- new(gRawGMT) SimpleTimeZone(0, UnicodeString(TRUE, GMT_ID, GMT_ID_LENGTH));
- new(gRawUNKNOWN) SimpleTimeZone(0, UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH));
-
- gStaticZonesInitialized = TRUE;
+
+ // new can't fail below, as we use placement new into staticly allocated space.
+ new(gRawGMT) SimpleTimeZone(0, UnicodeString(TRUE, GMT_ID, GMT_ID_LENGTH));
+ new(gRawUNKNOWN) SimpleTimeZone(0, UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH));
+
+ gStaticZonesInitialized = TRUE;
}
} // anonymous namespace
@@ -324,14 +324,14 @@ const TimeZone& U_EXPORT2
TimeZone::getUnknown()
{
umtx_initOnce(gStaticZonesInitOnce, &initStaticTimeZones);
- return *reinterpret_cast<SimpleTimeZone*>(gRawUNKNOWN);
+ return *reinterpret_cast<SimpleTimeZone*>(gRawUNKNOWN);
}
const TimeZone* U_EXPORT2
TimeZone::getGMT(void)
{
umtx_initOnce(gStaticZonesInitOnce, &initStaticTimeZones);
- return reinterpret_cast<SimpleTimeZone*>(gRawGMT);
+ return reinterpret_cast<SimpleTimeZone*>(gRawGMT);
}
// *****************************************************************************
@@ -392,22 +392,22 @@ createSystemTimeZone(const UnicodeString& id, UErrorCode& ec) {
return NULL;
}
TimeZone* z = 0;
- StackUResourceBundle res;
+ StackUResourceBundle res;
U_DEBUG_TZ_MSG(("pre-err=%s\n", u_errorName(ec)));
- UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
+ UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
U_DEBUG_TZ_MSG(("post-err=%s\n", u_errorName(ec)));
if (U_SUCCESS(ec)) {
- z = new OlsonTimeZone(top, res.getAlias(), id, ec);
+ z = new OlsonTimeZone(top, res.getAlias(), id, ec);
if (z == NULL) {
- ec = U_MEMORY_ALLOCATION_ERROR;
- U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec)));
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec)));
}
}
ures_close(top);
if (U_FAILURE(ec)) {
U_DEBUG_TZ_MSG(("cstz: failed to create, err %s\n", u_errorName(ec)));
delete z;
- z = NULL;
+ z = NULL;
}
return z;
}
@@ -445,8 +445,8 @@ TimeZone::createTimeZone(const UnicodeString& ID)
if (result == NULL) {
U_DEBUG_TZ_MSG(("failed to load time zone with id - falling to Etc/Unknown(GMT)"));
const TimeZone& unknown = getUnknown();
- // Unknown zone uses staticly allocated memory, so creation of it can never fail due to OOM.
- result = unknown.clone();
+ // Unknown zone uses staticly allocated memory, so creation of it can never fail due to OOM.
+ result = unknown.clone();
}
return result;
}
@@ -456,11 +456,11 @@ TimeZone::createTimeZone(const UnicodeString& ID)
TimeZone* U_EXPORT2
TimeZone::detectHostTimeZone()
{
- // We access system timezone data through uprv_tzset(), uprv_tzname(), and others,
- // which have platform specific implementations in putil.cpp
+ // We access system timezone data through uprv_tzset(), uprv_tzname(), and others,
+ // which have platform specific implementations in putil.cpp
int32_t rawOffset = 0;
const char *hostID;
- UBool hostDetectionSucceeded = TRUE;
+ UBool hostDetectionSucceeded = TRUE;
// First, try to create a system timezone, based
// on the string ID in tzname[0].
@@ -471,7 +471,7 @@ TimeZone::detectHostTimeZone()
// Get the timezone ID from the host. This function should do
// any required host-specific remapping; e.g., on Windows this
- // function maps the Windows Time Zone name to an ICU timezone ID.
+ // function maps the Windows Time Zone name to an ICU timezone ID.
hostID = uprv_tzname(0);
// Invert sign because UNIX semantics are backwards
@@ -480,14 +480,14 @@ TimeZone::detectHostTimeZone()
TimeZone* hostZone = NULL;
UnicodeString hostStrID(hostID, -1, US_INV);
-
- if (hostStrID.length() == 0) {
- // The host time zone detection (or remapping) above has failed and
- // we have no name at all. Fallback to using the Unknown zone.
- hostStrID = UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH);
- hostDetectionSucceeded = FALSE;
- }
-
+
+ if (hostStrID.length() == 0) {
+ // The host time zone detection (or remapping) above has failed and
+ // we have no name at all. Fallback to using the Unknown zone.
+ hostStrID = UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH);
+ hostDetectionSucceeded = FALSE;
+ }
+
hostZone = createSystemTimeZone(hostStrID);
#if U_PLATFORM_USES_ONLY_WIN32_API
@@ -507,19 +507,19 @@ TimeZone::detectHostTimeZone()
// Construct a fixed standard zone with the host's ID
// and raw offset.
- if (hostZone == NULL && hostDetectionSucceeded) {
+ if (hostZone == NULL && hostDetectionSucceeded) {
hostZone = new SimpleTimeZone(rawOffset, hostStrID);
}
- // If we _still_ don't have a time zone, use the Unknown zone.
+ // If we _still_ don't have a time zone, use the Unknown zone.
//
// Note: This is extremely unlikely situation. If
// new SimpleTimeZone(...) above fails, the following
// code may also fail.
if (hostZone == NULL) {
- // Unknown zone uses static allocated memory, so it must always exist.
- // However, clone() allocates memory and can fail.
- hostZone = TimeZone::getUnknown().clone();
+ // Unknown zone uses static allocated memory, so it must always exist.
+ // However, clone() allocates memory and can fail.
+ hostZone = TimeZone::getUnknown().clone();
}
return hostZone;
@@ -527,8 +527,8 @@ TimeZone::detectHostTimeZone()
// -------------------------------------
-static UMutex gDefaultZoneMutex;
-
+static UMutex gDefaultZoneMutex;
+
/**
* Initialize DEFAULT_ZONE from the system default time zone.
* Upon return, DEFAULT_ZONE will not be NULL, unless operator new()
@@ -538,7 +538,7 @@ static void U_CALLCONV initDefault()
{
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
- Mutex lock(&gDefaultZoneMutex);
+ Mutex lock(&gDefaultZoneMutex);
// If setDefault() has already been called we can skip getting the
// default zone information from the system.
if (DEFAULT_ZONE != NULL) {
@@ -571,10 +571,10 @@ TimeZone* U_EXPORT2
TimeZone::createDefault()
{
umtx_initOnce(gDefaultZoneInitOnce, initDefault);
- {
- Mutex lock(&gDefaultZoneMutex);
- return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
- }
+ {
+ Mutex lock(&gDefaultZoneMutex);
+ return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
+ }
}
// -------------------------------------
@@ -584,12 +584,12 @@ TimeZone::adoptDefault(TimeZone* zone)
{
if (zone != NULL)
{
- {
- Mutex lock(&gDefaultZoneMutex);
- TimeZone *old = DEFAULT_ZONE;
- DEFAULT_ZONE = zone;
- delete old;
- }
+ {
+ Mutex lock(&gDefaultZoneMutex);
+ TimeZone *old = DEFAULT_ZONE;
+ DEFAULT_ZONE = zone;
+ delete old;
+ }
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
}
}
@@ -753,7 +753,7 @@ private:
len = mapLen;
}
- UBool getID(int32_t i, UErrorCode& ec) {
+ UBool getID(int32_t i, UErrorCode& ec) {
int32_t idLen = 0;
const UChar* id = NULL;
UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec);
@@ -943,7 +943,7 @@ public:
virtual const UnicodeString* snext(UErrorCode& status) {
if (U_SUCCESS(status) && map != NULL && pos < len) {
- getID(map[pos], status);
+ getID(map[pos], status);
++pos;
return &unistr;
}
@@ -1000,13 +1000,13 @@ int32_t U_EXPORT2
TimeZone::countEquivalentIDs(const UnicodeString& id) {
int32_t result = 0;
UErrorCode ec = U_ZERO_ERROR;
- StackUResourceBundle res;
+ StackUResourceBundle res;
U_DEBUG_TZ_MSG(("countEquivalentIDs..\n"));
- UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
+ UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
if (U_SUCCESS(ec)) {
- StackUResourceBundle r;
- ures_getByKey(res.getAlias(), kLINKS, r.getAlias(), &ec);
- ures_getIntVector(r.getAlias(), &result, &ec);
+ StackUResourceBundle r;
+ ures_getByKey(res.getAlias(), kLINKS, r.getAlias(), &ec);
+ ures_getIntVector(r.getAlias(), &result, &ec);
}
ures_close(top);
return result;
@@ -1019,14 +1019,14 @@ TimeZone::getEquivalentID(const UnicodeString& id, int32_t index) {
U_DEBUG_TZ_MSG(("gEI(%d)\n", index));
UnicodeString result;
UErrorCode ec = U_ZERO_ERROR;
- StackUResourceBundle res;
- UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
+ StackUResourceBundle res;
+ UResourceBundle *top = openOlsonResource(id, res.ref(), ec);
int32_t zone = -1;
if (U_SUCCESS(ec)) {
- StackUResourceBundle r;
+ StackUResourceBundle r;
int32_t size;
- ures_getByKey(res.getAlias(), kLINKS, r.getAlias(), &ec);
- const int32_t *v = ures_getIntVector(r.getAlias(), &size, &ec);
+ ures_getByKey(res.getAlias(), kLINKS, r.getAlias(), &ec);
+ const int32_t *v = ures_getIntVector(r.getAlias(), &size, &ec);
if (U_SUCCESS(ec)) {
if (index >= 0 && index < size) {
zone = v[index];
@@ -1037,8 +1037,8 @@ TimeZone::getEquivalentID(const UnicodeString& id, int32_t index) {
UResourceBundle *ares = ures_getByKey(top, kNAMES, NULL, &ec); // dereference Zones section
if (U_SUCCESS(ec)) {
int32_t idLen = 0;
- const UChar* id2 = ures_getStringByIndex(ares, zone, &idLen, &ec);
- result.fastCopyFrom(UnicodeString(TRUE, id2, idLen));
+ const UChar* id2 = ures_getStringByIndex(ares, zone, &idLen, &ec);
+ result.fastCopyFrom(UnicodeString(TRUE, id2, idLen));
U_DEBUG_TZ_MSG(("gei(%d) -> %d, len%d, %s\n", index, zone, result.length(), u_errorName(ec)));
}
ures_close(ares);
@@ -1187,9 +1187,9 @@ TimeZone::getDisplayName(const Locale& locale, UnicodeString& result) const
}
UnicodeString&
-TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const
+TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, UnicodeString& result) const
{
- return getDisplayName(inDaylight,style, Locale::getDefault(), result);
+ return getDisplayName(inDaylight,style, Locale::getDefault(), result);
}
//--------------------------------------
int32_t
@@ -1201,11 +1201,11 @@ TimeZone::getDSTSavings()const {
}
//---------------------------------------
UnicodeString&
-TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const
+TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& locale, UnicodeString& result) const
{
UErrorCode status = U_ZERO_ERROR;
UDate date = Calendar::getNow();
- UTimeZoneFormatTimeType timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ UTimeZoneFormatTimeType timeType = UTZFMT_TIME_TYPE_UNKNOWN;
int32_t offset;
if (style == GENERIC_LOCATION || style == LONG_GENERIC || style == SHORT_GENERIC) {
@@ -1226,13 +1226,13 @@ TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& loc
tzfmt->format(UTZFMT_STYLE_GENERIC_SHORT, *this, date, result, &timeType);
break;
default:
- UPRV_UNREACHABLE;
+ UPRV_UNREACHABLE;
}
// Generic format many use Localized GMT as the final fallback.
// When Localized GMT format is used, the result might not be
// appropriate for the requested daylight value.
- if ((inDaylight && timeType == UTZFMT_TIME_TYPE_STANDARD) || (!inDaylight && timeType == UTZFMT_TIME_TYPE_DAYLIGHT)) {
- offset = inDaylight ? getRawOffset() + getDSTSavings() : getRawOffset();
+ if ((inDaylight && timeType == UTZFMT_TIME_TYPE_STANDARD) || (!inDaylight && timeType == UTZFMT_TIME_TYPE_DAYLIGHT)) {
+ offset = inDaylight ? getRawOffset() + getDSTSavings() : getRawOffset();
if (style == SHORT_GENERIC) {
tzfmt->formatOffsetShortLocalizedGMT(offset, result, status);
} else {
@@ -1245,7 +1245,7 @@ TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& loc
result.remove();
return result;
}
- offset = inDaylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
+ offset = inDaylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
switch (style) {
case LONG_GMT:
tzfmt->formatOffsetLocalizedGMT(offset, result, status);
@@ -1254,7 +1254,7 @@ TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& loc
tzfmt->formatOffsetISO8601Basic(offset, FALSE, FALSE, FALSE, result, status);
break;
default:
- UPRV_UNREACHABLE;
+ UPRV_UNREACHABLE;
}
} else {
@@ -1262,14 +1262,14 @@ TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& loc
UTimeZoneNameType nameType = UTZNM_UNKNOWN;
switch (style) {
case LONG:
- nameType = inDaylight ? UTZNM_LONG_DAYLIGHT : UTZNM_LONG_STANDARD;
+ nameType = inDaylight ? UTZNM_LONG_DAYLIGHT : UTZNM_LONG_STANDARD;
break;
case SHORT:
case SHORT_COMMONLY_USED:
- nameType = inDaylight ? UTZNM_SHORT_DAYLIGHT : UTZNM_SHORT_STANDARD;
+ nameType = inDaylight ? UTZNM_SHORT_DAYLIGHT : UTZNM_SHORT_STANDARD;
break;
default:
- UPRV_UNREACHABLE;
+ UPRV_UNREACHABLE;
}
LocalPointer<TimeZoneNames> tznames(TimeZoneNames::createInstance(locale, status));
if (U_FAILURE(status)) {
@@ -1281,7 +1281,7 @@ TimeZone::getDisplayName(UBool inDaylight, EDisplayType style, const Locale& loc
if (result.isEmpty()) {
// Fallback to localized GMT
LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(locale, status));
- offset = inDaylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
+ offset = inDaylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
if (style == LONG) {
tzfmt->formatOffsetLocalizedGMT(offset, result, status);
} else {
@@ -1502,9 +1502,9 @@ TimeZone::hasSameRules(const TimeZone& other) const
static void U_CALLCONV initTZDataVersion(UErrorCode &status) {
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
int32_t len = 0;
- StackUResourceBundle bundle;
- ures_openDirectFillIn(bundle.getAlias(), NULL, kZONEINFO, &status);
- const UChar *tzver = ures_getStringByKey(bundle.getAlias(), kTZVERSION, &len, &status);
+ StackUResourceBundle bundle;
+ ures_openDirectFillIn(bundle.getAlias(), NULL, kZONEINFO, &status);
+ const UChar *tzver = ures_getStringByKey(bundle.getAlias(), kTZVERSION, &len, &status);
if (U_SUCCESS(status)) {
if (len >= (int32_t)sizeof(TZDATA_VERSION)) {
@@ -1617,7 +1617,7 @@ TimeZone::getWindowsID(const UnicodeString& id, UnicodeString& winid, UErrorCode
end = tzids + len;
hasNext = FALSE;
}
- if (canonicalID.compare(start, static_cast<int32_t>(end - start)) == 0) {
+ if (canonicalID.compare(start, static_cast<int32_t>(end - start)) == 0) {
winid = UnicodeString(ures_getKey(winzone), -1 , US_INV);
found = TRUE;
break;
@@ -1678,7 +1678,7 @@ TimeZone::getIDForWindowsID(const UnicodeString& winid, const char* region, Unic
if (end == NULL) {
id.setTo(tzids, -1);
} else {
- id.setTo(tzids, static_cast<int32_t>(end - tzids));
+ id.setTo(tzids, static_cast<int32_t>(end - tzids));
}
gotID = TRUE;
}