Index: source/i18n/dtfmtsym.cpp |
diff --git a/source/i18n/dtfmtsym.cpp b/source/i18n/dtfmtsym.cpp |
index 6dc1d4bcfa64ebd45f6531a15334155bac8d4dd8..e99670d4c5dab92d8cbecca4cd1322d770d43ea1 100644 |
--- a/source/i18n/dtfmtsym.cpp |
+++ b/source/i18n/dtfmtsym.cpp |
@@ -1,6 +1,6 @@ |
/* |
******************************************************************************* |
-* Copyright (C) 1997-2014, International Business Machines Corporation and * |
+* Copyright (C) 1997-2015, International Business Machines Corporation and * |
* others. All Rights Reserved. * |
******************************************************************************* |
* |
@@ -23,9 +23,11 @@ |
#if !UCONFIG_NO_FORMATTING |
#include "unicode/ustring.h" |
+#include "unicode/localpointer.h" |
#include "unicode/dtfmtsym.h" |
#include "unicode/smpdtfmt.h" |
#include "unicode/msgfmt.h" |
+#include "unicode/numsys.h" |
#include "unicode/tznames.h" |
#include "cpputils.h" |
#include "umutex.h" |
@@ -36,6 +38,9 @@ |
#include "hash.h" |
#include "uresimp.h" |
#include "ureslocs.h" |
+#include "shareddateformatsymbols.h" |
+#include "unicode/calendar.h" |
+#include "unifiedcache.h" |
// ***************************************************************************** |
// class DateFormatSymbols |
@@ -46,18 +51,30 @@ |
* resource data. |
*/ |
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
+#define PATTERN_CHARS_LEN 36 |
+#else |
#define PATTERN_CHARS_LEN 35 |
+#endif |
/** |
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All |
* locales use the same these unlocalized pattern characters. |
*/ |
static const UChar gPatternChars[] = { |
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
+ // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr: |
+#else |
// GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr |
+#endif |
0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, |
0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, |
0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56, |
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR |
+ 0x55, 0x4F, 0x58, 0x78, 0x72, 0x3a, 0 |
+#else |
0x55, 0x4F, 0x58, 0x78, 0x72, 0 |
+#endif |
}; |
/* length of an array */ |
@@ -146,6 +163,32 @@ typedef enum LastResortSize { |
U_NAMESPACE_BEGIN |
+SharedDateFormatSymbols::~SharedDateFormatSymbols() { |
+} |
+ |
+template<> U_I18N_API |
+const SharedDateFormatSymbols * |
+ LocaleCacheKey<SharedDateFormatSymbols>::createObject( |
+ const void */*unusedContext*/, UErrorCode &status) const { |
+ char type[256]; |
+ Calendar::getCalendarTypeFromLocale(fLoc, type, UPRV_LENGTHOF(type), status); |
+ if (U_FAILURE(status)) { |
+ return NULL; |
+ } |
+ SharedDateFormatSymbols *shared |
+ = new SharedDateFormatSymbols(fLoc, type, status); |
+ if (shared == NULL) { |
+ status = U_MEMORY_ALLOCATION_ERROR; |
+ return NULL; |
+ } |
+ if (U_FAILURE(status)) { |
+ delete shared; |
+ return NULL; |
+ } |
+ shared->addRef(); |
+ return shared; |
+} |
+ |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols) |
#define kSUPPLEMENTAL "supplementalData" |
@@ -171,7 +214,11 @@ static const char gNamesFormatTag[]="format"; |
static const char gNamesStandaloneTag[]="stand-alone"; |
static const char gNamesNumericTag[]="numeric"; |
static const char gAmPmMarkersTag[]="AmPmMarkers"; |
+static const char gAmPmMarkersNarrowTag[]="AmPmMarkersNarrow"; |
static const char gQuartersTag[]="quarters"; |
+static const char gNumberElementsTag[]="NumberElements"; |
+static const char gSymbolsTag[]="symbols"; |
+static const char gTimeSeparatorTag[]="timeSeparator"; |
// static const char gZoneStringsTag[]="zoneStrings"; |
@@ -191,6 +238,23 @@ static inline UnicodeString* newUnicodeStringArray(size_t count) { |
//------------------------------------------------------ |
+DateFormatSymbols * U_EXPORT2 |
+DateFormatSymbols::createForLocale( |
+ const Locale& locale, UErrorCode &status) { |
+ const SharedDateFormatSymbols *shared = NULL; |
+ UnifiedCache::getByLocale(locale, shared, status); |
+ if (U_FAILURE(status)) { |
+ return NULL; |
+ } |
+ DateFormatSymbols *result = new DateFormatSymbols(shared->get()); |
+ shared->removeRef(); |
+ if (result == NULL) { |
+ status = U_MEMORY_ALLOCATION_ERROR; |
+ return NULL; |
+ } |
+ return result; |
+} |
+ |
DateFormatSymbols::DateFormatSymbols(const Locale& locale, |
UErrorCode& status) |
: UObject() |
@@ -294,6 +358,11 @@ DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings) |
*/ |
void |
DateFormatSymbols::copyData(const DateFormatSymbols& other) { |
+ UErrorCode status = U_ZERO_ERROR; |
+ U_LOCALE_BASED(locBased, *this); |
+ locBased.setLocaleIDs( |
+ other.getLocale(ULOC_VALID_LOCALE, status), |
+ other.getLocale(ULOC_ACTUAL_LOCALE, status)); |
assignArray(fEras, fErasCount, other.fEras, other.fErasCount); |
assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount); |
assignArray(fNarrowEras, fNarrowErasCount, other.fNarrowEras, other.fNarrowErasCount); |
@@ -312,6 +381,8 @@ DateFormatSymbols::copyData(const DateFormatSymbols& other) { |
assignArray(fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, other.fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdaysCount); |
assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount); |
assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount); |
+ assignArray(fNarrowAmPms, fNarrowAmPmsCount, other.fNarrowAmPms, other.fNarrowAmPmsCount ); |
+ fTimeSeparator.fastCopyFrom(other.fTimeSeparator); // fastCopyFrom() - see assignArray comments |
assignArray(fQuarters, fQuartersCount, other.fQuarters, other.fQuartersCount); |
assignArray(fShortQuarters, fShortQuartersCount, other.fShortQuarters, other.fShortQuartersCount); |
assignArray(fStandaloneQuarters, fStandaloneQuartersCount, other.fStandaloneQuarters, other.fStandaloneQuartersCount); |
@@ -391,6 +462,7 @@ void DateFormatSymbols::dispose() |
if (fStandaloneShorterWeekdays) delete[] fStandaloneShorterWeekdays; |
if (fStandaloneNarrowWeekdays) delete[] fStandaloneNarrowWeekdays; |
if (fAmPms) delete[] fAmPms; |
+ if (fNarrowAmPms) delete[] fNarrowAmPms; |
if (fQuarters) delete[] fQuarters; |
if (fShortQuarters) delete[] fShortQuarters; |
if (fStandaloneQuarters) delete[] fStandaloneQuarters; |
@@ -462,6 +534,7 @@ DateFormatSymbols::operator==(const DateFormatSymbols& other) const |
fStandaloneShorterWeekdaysCount == other.fStandaloneShorterWeekdaysCount && |
fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount && |
fAmPmsCount == other.fAmPmsCount && |
+ fNarrowAmPmsCount == other.fNarrowAmPmsCount && |
fQuartersCount == other.fQuartersCount && |
fShortQuartersCount == other.fShortQuartersCount && |
fStandaloneQuartersCount == other.fStandaloneQuartersCount && |
@@ -490,6 +563,8 @@ DateFormatSymbols::operator==(const DateFormatSymbols& other) const |
arrayCompare(fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount) && |
arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) && |
arrayCompare(fAmPms, other.fAmPms, fAmPmsCount) && |
+ arrayCompare(fNarrowAmPms, other.fNarrowAmPms, fNarrowAmPmsCount) && |
+ fTimeSeparator == other.fTimeSeparator && |
arrayCompare(fQuarters, other.fQuarters, fQuartersCount) && |
arrayCompare(fShortQuarters, other.fShortQuarters, fShortQuartersCount) && |
arrayCompare(fStandaloneQuarters, other.fStandaloneQuarters, fStandaloneQuartersCount) && |
@@ -725,6 +800,13 @@ DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthTyp |
return returnValue; |
} |
+UnicodeString& |
+DateFormatSymbols::getTimeSeparatorString(UnicodeString& result) const |
+{ |
+ // fastCopyFrom() - see assignArray comments |
+ return result.fastCopyFrom(fTimeSeparator); |
+} |
+ |
const UnicodeString* |
DateFormatSymbols::getAmPmStrings(int32_t &count) const |
{ |
@@ -1114,6 +1196,12 @@ DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count |
fAmPmsCount = count; |
} |
+void |
+DateFormatSymbols::setTimeSeparatorString(const UnicodeString& newTimeSeparator) |
+{ |
+ fTimeSeparator = newTimeSeparator; |
+} |
+ |
const UnicodeString** |
DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const |
{ |
@@ -1430,6 +1518,9 @@ DateFormatSymbols::initializeData(const Locale& locale, const char *type, UError |
fStandaloneNarrowWeekdaysCount=0; |
fAmPms = NULL; |
fAmPmsCount=0; |
+ fNarrowAmPms = NULL; |
+ fNarrowAmPmsCount=0; |
+ fTimeSeparator.setToBogus(); |
fQuarters = NULL; |
fQuartersCount = 0; |
fShortQuarters = NULL; |
@@ -1577,9 +1668,34 @@ DateFormatSymbols::initializeData(const Locale& locale, const char *type, UError |
} |
ures_close(contextTransforms); |
} |
+ |
+ tempStatus = U_ZERO_ERROR; |
+ const LocalPointer<NumberingSystem> numberingSystem( |
+ NumberingSystem::createInstance(locale, tempStatus), tempStatus); |
+ if (U_SUCCESS(tempStatus)) { |
+ // These functions all fail gracefully if passed NULL pointers and |
+ // do nothing unless U_SUCCESS(tempStatus), so it's only necessary |
+ // to check for errors once after all calls are made. |
+ const LocalUResourceBundlePointer numberElementsData(ures_getByKeyWithFallback( |
+ localeBundle, gNumberElementsTag, NULL, &tempStatus)); |
+ const LocalUResourceBundlePointer nsNameData(ures_getByKeyWithFallback( |
+ numberElementsData.getAlias(), numberingSystem->getName(), NULL, &tempStatus)); |
+ const LocalUResourceBundlePointer symbolsData(ures_getByKeyWithFallback( |
+ nsNameData.getAlias(), gSymbolsTag, NULL, &tempStatus)); |
+ fTimeSeparator = ures_getUnicodeStringByKey( |
+ symbolsData.getAlias(), gTimeSeparatorTag, &tempStatus); |
+ if (U_FAILURE(tempStatus)) { |
+ fTimeSeparator.setToBogus(); |
+ } |
+ } |
+ |
ures_close(localeBundle); |
} |
+ if (fTimeSeparator.isBogus()) { |
+ fTimeSeparator.setTo(DateFormatSymbols::DEFAULT_TIME_SEPARATOR); |
+ } |
+ |
UResourceBundle *weekdaysData = NULL; // Data closed by calData |
UResourceBundle *abbrWeekdaysData = NULL; // Data closed by calData |
UResourceBundle *shorterWeekdaysData = NULL; // Data closed by calData |
@@ -1619,6 +1735,7 @@ DateFormatSymbols::initializeData(const Locale& locale, const char *type, UError |
initField(&fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); |
initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); |
initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status); |
+ initField(&fNarrowAmPms, fNarrowAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status); |
initField(&fQuarters, fQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); |
initField(&fShortQuarters, fShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); |
initField(&fStandaloneQuarters, fStandaloneQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); |
@@ -1671,6 +1788,7 @@ DateFormatSymbols::initializeData(const Locale& locale, const char *type, UError |
} |
} |
initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status); |
+ initField(&fNarrowAmPms, fNarrowAmPmsCount, calData.getByKey(gAmPmMarkersNarrowTag, status), status); |
initField(&fQuarters, fQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); |
initField(&fShortQuarters, fShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); |