/*
*******************************************************************************
-* Copyright (C) 2007-2008, International Business Machines Corporation and *
+* Copyright (C) 2007-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
#include "unicode/unistr.h"
#include "unicode/calendar.h"
-#include "hash.h"
+#include "uhash.h"
#include "uvector.h"
U_NAMESPACE_BEGIN
virtual ~TextTrieMapSearchResultHandler(); //added to avoid warning
};
+
+/*
+ * ZSFStringPool Pool of (UChar *) strings. Provides for sharing of repeated
+ * strings within ZoneStringFormats.
+ */
+class ZSFStringPoolChunk;
+class ZSFStringPool: public UMemory {
+ public:
+ ZSFStringPool(UErrorCode &status);
+ ~ZSFStringPool();
+
+ /* Get the pooled string that is equal to the supplied string s.
+ * Copy the string into the pool if it is not already present.
+ *
+ * Life time of the returned string is that of the pool.
+ */
+ const UChar *get(const UChar *s, UErrorCode &status);
+
+ /* Get the pooled string that is equal to the supplied string s.
+ * Copy the string into the pool if it is not already present.
+ */
+ const UChar *get(const UnicodeString &s, UErrorCode &status);
+
+ /* Adopt a string into the pool, without copying it.
+ * Used for strings from resource bundles, which will persist without copying.
+ */
+ const UChar *adopt(const UChar *s, UErrorCode &status);
+
+ /* Freeze the string pool. Discards the hash table that is used
+ * for looking up a string. All pointers to pooled strings remain valid.
+ */
+ void freeze();
+
+ private:
+ ZSFStringPoolChunk *fChunks;
+ UHashtable *fHash;
+};
+
+
/**
* TextTrieMap is a trie implementation for supporting
* fast prefix match for the string key.
TextTrieMap(UBool ignoreCase);
virtual ~TextTrieMap();
- void put(const UnicodeString &key, void *value, UErrorCode &status);
+ void put(const UnicodeString &key, void *value, ZSFStringPool &sp, UErrorCode &status);
void search(const UnicodeString &text, int32_t start,
TextTrieMapSearchResultHandler *handler, UErrorCode& status) const;
- inline int32_t isEmpty() const;
+ int32_t isEmpty() const;
private:
UBool fIgnoreCase;
int32_t fNodesCapacity;
int32_t fNodesCount;
+ UVector *fLazyContents;
+ UBool fIsEmpty;
+
UBool growNodes();
CharacterNode* addChildNode(CharacterNode *parent, UChar c, UErrorCode &status);
CharacterNode* getChildNode(CharacterNode *parent, UChar c) const;
+ void putImpl(const UnicodeString &key, void *value, UErrorCode &status);
+ void buildTrie(UErrorCode &status);
void search(CharacterNode *node, const UnicodeString &text, int32_t start,
int32_t index, TextTrieMapSearchResultHandler *handler, UErrorCode &status) const;
};
-inline UChar32 TextTrieMap::isEmpty(void) const {
- return fNodes == NULL;
-}
// Name types, these bit flag are used for zone string lookup
enum TimeZoneTranslationType {
class MessageFormat;
+
/*
* ZoneStringInfo is a class holding a localized zone string
* information.
friend class ZoneStringFormat;
friend class ZoneStringSearchResultHandler;
- ZoneStringInfo(const UnicodeString &id, const UnicodeString &str, TimeZoneTranslationType type);
+ ZoneStringInfo(const UnicodeString &id, const UnicodeString &str,
+ TimeZoneTranslationType type, ZSFStringPool &sp, UErrorCode &status);
- UnicodeString fId;
- UnicodeString fStr;
+ const UChar *fId;
+ const UChar *fStr;
TimeZoneTranslationType fType;
};
inline UnicodeString& ZoneStringInfo::getID(UnicodeString &result) const {
- return result.setTo(fId);
+ return result.setTo(fId, -1);
}
inline UnicodeString& ZoneStringInfo::getString(UnicodeString &result) const {
- return result.setTo(fStr);
+ return result.setTo(fStr, -1);
}
inline UBool ZoneStringInfo::isStandard(void) const {
ZoneStringFormat(const Locale& locale, UErrorCode &status);
virtual ~ZoneStringFormat();
+ /* Gets zone string format from cache if available, create it if not cached. */
static SafeZoneStringFormatPtr* getZoneStringFormat(const Locale& locale, UErrorCode &status);
/*
*/
UnicodeString** createZoneStringsArray(UDate date, int32_t &rowCount, int32_t &colCount, UErrorCode &status) const;
+ /* TODO: There is no implementation for this function. Delete declaration? */
const UnicodeString** getZoneStrings(int32_t &rowCount, int32_t &columnCount) const;
UnicodeString& getSpecificLongString(const Calendar &cal,
inline UnicodeString& getGenericLocation(const UnicodeString &tzid, UnicodeString &result) const;
private:
- Locale fLocale;
- Hashtable fTzidToStrings;
- Hashtable fMzidToStrings;
- TextTrieMap fZoneStringsTrie;
+ Locale fLocale;
+ UHashtable *fTzidToStrings;
+ UHashtable *fMzidToStrings;
+
+ TextTrieMap fZoneStringsTrie;
+ ZSFStringPool fStringPool;
+
+ UResourceBundle *fZoneStringsArray;
+ UResourceBundle *fMetazoneItem;
+ UResourceBundle *fZoneItem;
+
+ UBool fIsFullyLoaded;
+
+ void loadZone(const UnicodeString &utzid, UErrorCode &status);
+ void addSingleZone(UnicodeString &utzid, UErrorCode &status);
+ void loadFull(UErrorCode &status);
+
/*
* Private method to get a zone string except generic partial location types.
*/
const ZoneStringInfo* find(const UnicodeString &text, int32_t start, int32_t types,
int32_t &matchLength, UErrorCode &status) const;
+ const ZoneStringInfo* subFind(const UnicodeString &text, int32_t start, int32_t types,
+ int32_t &matchLength, UErrorCode &status) const;
UnicodeString& getRegion(UnicodeString ®ion) const;
static MessageFormat* getFallbackFormat(const Locale &locale, UErrorCode &status);
static MessageFormat* getRegionFormat(const Locale &locale, UErrorCode &status);
- static const UChar* getZoneStringFromBundle(const UResourceBundle *zoneitem, const char *key);
+ const UChar* getZoneStringFromBundle(const UResourceBundle *zoneitem, const char *key);
static UBool isCommonlyUsed(const UResourceBundle *zoneitem);
static UnicodeString& getLocalizedCountry(const UnicodeString &countryCode, const Locale &locale,
UnicodeString &displayCountry);
/*
- * ZooneStrings is a container of localized zone strings used by ZoneStringFormat
+ * ZoneStrings is a container of localized zone strings used by ZoneStringFormat
*/
class ZoneStrings : public UMemory {
public:
- ZoneStrings(UnicodeString *strings, int32_t stringsCount, UBool commonlyUsed,
- UnicodeString **genericPartialLocationStrings, int32_t genericRowCount, int32_t genericColCount);
- virtual ~ZoneStrings();
-
- UnicodeString& getString(int32_t typeIdx, UnicodeString &result) const;
- inline UBool isShortFormatCommonlyUsed(void) const;
- UnicodeString& getGenericPartialLocationString(const UnicodeString &mzid, UBool isShort,
- UBool commonlyUsedOnly, UnicodeString &result) const;
+ ZoneStrings(UnicodeString *strings,
+ int32_t stringsCount,
+ UBool commonlyUsed,
+ UnicodeString **genericPartialLocationStrings,
+ int32_t genericRowCount,
+ int32_t genericColCount,
+ ZSFStringPool &sp,
+ UErrorCode &status);
+ virtual ~ZoneStrings();
+
+ UnicodeString& getString(int32_t typeIdx, UnicodeString &result) const;
+ inline UBool isShortFormatCommonlyUsed(void) const;
+ UnicodeString& getGenericPartialLocationString(const UnicodeString &mzid, UBool isShort,
+ UBool commonlyUsedOnly, UnicodeString &result) const;
private:
- UnicodeString *fStrings;
+ const UChar **fStrings;
int32_t fStringsCount;
UBool fIsCommonlyUsed;
- UnicodeString **fGenericPartialLocationStrings;
+ const UChar * **fGenericPartialLocationStrings;
int32_t fGenericPartialLocationRowCount;
int32_t fGenericPartialLocationColCount;
};