ICU-11912 TimeZoneNames data sink implementation in C++.

X-SVN-Rev: 38960
This commit is contained in:
Shane Carr 2016-07-08 18:16:21 +00:00
parent 28ed27b463
commit ad409a250e
6 changed files with 661 additions and 385 deletions

View File

@ -1273,6 +1273,12 @@ DateFormatSymbols::initZoneStringsArray(void) {
TimeZoneNames *tzNames = NULL;
int32_t rows = 0;
static const UTimeZoneNameType TYPES[] = {
UTZNM_LONG_STANDARD, UTZNM_SHORT_STANDARD,
UTZNM_LONG_DAYLIGHT, UTZNM_SHORT_DAYLIGHT
};
static const int32_t NUM_TYPES = 4;
do { // dummy do-while
tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status);
@ -1291,6 +1297,8 @@ DateFormatSymbols::initZoneStringsArray(void) {
uprv_memset(zarray, 0, size);
tzNames = TimeZoneNames::createInstance(fZSFLocale, status);
tzNames->loadAllDisplayNames(status);
if (U_FAILURE(status)) { break; }
const UnicodeString *tzid;
int32_t i = 0;
@ -1309,10 +1317,7 @@ DateFormatSymbols::initZoneStringsArray(void) {
}
zarray[i][0].setTo(*tzid);
zarray[i][1].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_STANDARD, now, tzDispName));
zarray[i][2].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_STANDARD, now, tzDispName));
zarray[i][3].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_DAYLIGHT, now, tzDispName));
zarray[i][4].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_DAYLIGHT, now, tzDispName));
tzNames->getDisplayNames(*tzid, TYPES, NUM_TYPES, now, zarray[i]+1);
i++;
}
@ -1338,7 +1343,7 @@ DateFormatSymbols::initZoneStringsArray(void) {
fLocaleZoneStrings = zarray;
fZoneStringsRowCount = rows;
fZoneStringsColCount = 5;
fZoneStringsColCount = 1 + NUM_TYPES;
}
void

View File

@ -118,6 +118,8 @@ public:
UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const;
void loadAllDisplayNames(UErrorCode& status);
MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
private:
TimeZoneNamesDelegate();
@ -280,6 +282,11 @@ TimeZoneNamesDelegate::getExemplarLocationName(const UnicodeString& tzID, Unicod
return fTZnamesCacheEntry->names->getExemplarLocationName(tzID, name);
}
void
TimeZoneNamesDelegate::loadAllDisplayNames(UErrorCode& status) {
fTZnamesCacheEntry->names->loadAllDisplayNames(status);
}
TimeZoneNames::MatchInfoCollection*
TimeZoneNamesDelegate::find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
return fTZnamesCacheEntry->names->find(text, start, types, status);
@ -332,6 +339,29 @@ TimeZoneNames::getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type,
return name;
}
void
TimeZoneNames::loadAllDisplayNames(UErrorCode& status) {
return loadAllDisplayNames(status);
}
void
TimeZoneNames::getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[]) const {
if (tzID.isEmpty()) { return; }
UnicodeString mzID;
for (int i = 0; i < numTypes; i++) {
UnicodeString name;
UTimeZoneNameType type = types[i];
getTimeZoneDisplayName(tzID, type, name);
if (name.isEmpty()) {
if (mzID.isEmpty()) {
getMetaZoneID(tzID, date, mzID);
}
getMetaZoneDisplayName(mzID, type, name);
}
dest[i].setTo(name);
}
}
struct MatchInfo : UMemory {
UTimeZoneNameType nameType;

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,8 @@
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2011-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
* Copyright (C) 2011-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -161,8 +161,8 @@ private:
class ZNames;
class TZNames;
class TextTrieMap;
class ZNameSearchHandler;
class TimeZoneNamesImpl : public TimeZoneNames {
public:
@ -186,6 +186,9 @@ public:
TimeZoneNames::MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
void loadAllDisplayNames(UErrorCode& errorCode);
void internalLoadAllDisplayNames(UErrorCode& errorCode);
static UnicodeString& getDefaultExemplarLocationName(const UnicodeString& tzID, UnicodeString& name);
static StringEnumeration* _getAvailableMetaZoneIDs(UErrorCode& status);
@ -203,6 +206,7 @@ private:
UHashtable* fMZNamesMap;
UBool fNamesTrieFullyLoaded;
UBool fNamesFullyLoaded;
TextTrieMap fNamesTrie;
void initialize(const Locale& locale, UErrorCode& status);
@ -211,7 +215,12 @@ private:
void loadStrings(const UnicodeString& tzCanonicalID);
ZNames* loadMetaZoneNames(const UnicodeString& mzId);
TZNames* loadTimeZoneNames(const UnicodeString& mzId);
ZNames* loadTimeZoneNames(const UnicodeString& mzId);
TimeZoneNames::MatchInfoCollection* doFind(ZNameSearchHandler& handler,
const UnicodeString& text, int32_t start, UErrorCode& status) const;
void addAllNamesIntoTrie(UErrorCode& errorCode);
struct ZoneStringsLoader;
};
class TZDBNames;

View File

@ -2,7 +2,7 @@
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2011-2015, International Business Machines Corporation and
* Copyright (C) 2011-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -135,7 +135,7 @@ public:
virtual ~TimeZoneNames();
/**
* Return true if the given TimeZoneNames objects are emantically equal.
* Return true if the given TimeZoneNames objects are semantically equal.
* @param other the object to be compared with.
* @return Return TRUE if the given Format objects are semantically equal.
* @stable ICU 50
@ -290,6 +290,18 @@ public:
*/
virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const;
/**
* @internal For specific users only until proposed publicly.
* @deprecated This API is ICU internal only.
*/
virtual void loadAllDisplayNames(UErrorCode& status);
/**
* @internal For specific users only until proposed publicly.
* @deprecated This API is ICU internal only.
*/
virtual void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[]) const;
/**
* <code>MatchInfoCollection</code> represents a collection of time zone name matches used by
* {@link TimeZoneNames#find}.

View File

@ -833,7 +833,7 @@ TimeZoneFormatTest::TestParse(void) {
delete tz;
} else {
if (DATA[i].expected) {
errln((UnicodeString)"Fail: Parse failure - expected: " + DATA[i].expected);
errMsg = (UnicodeString)"Parse failure - expected: " + DATA[i].expected;
}
}
if (errMsg.length() > 0) {