Index: source/i18n/dtitvfmt.cpp |
diff --git a/source/i18n/dtitvfmt.cpp b/source/i18n/dtitvfmt.cpp |
index 21377e111a0806cd7d1d9c21acae89bc10b2a4f1..48068d3cc2da2061dec63d9e11b3beb0f840a0dd 100644 |
--- a/source/i18n/dtitvfmt.cpp |
+++ b/source/i18n/dtitvfmt.cpp |
@@ -1,9 +1,11 @@ |
+// Copyright (C) 2016 and later: Unicode, Inc. and others. |
+// License & terms of use: http://www.unicode.org/copyright.html |
/******************************************************************************* |
-* Copyright (C) 2008-2015, International Business Machines Corporation and |
+* Copyright (C) 2008-2016, International Business Machines Corporation and |
* others. All Rights Reserved. |
******************************************************************************* |
* |
-* File DTITVFMT.CPP |
+* File DTITVFMT.CPP |
* |
******************************************************************************* |
*/ |
@@ -17,25 +19,25 @@ |
//TODO: put in compilation |
//#define DTITVFMT_DEBUG 1 |
-#include "cstring.h" |
-#include "unicode/msgfmt.h" |
+#include "unicode/calendar.h" |
#include "unicode/dtptngen.h" |
#include "unicode/dtitvinf.h" |
-#include "unicode/calendar.h" |
+#include "unicode/simpleformatter.h" |
+#include "cmemory.h" |
+#include "cstring.h" |
#include "dtitv_impl.h" |
+#include "mutex.h" |
+#include "uresimp.h" |
-#ifdef DTITVFMT_DEBUG |
+#ifdef DTITVFMT_DEBUG |
#include <iostream> |
-#include "cstring.h" |
#endif |
-#include "gregoimp.h" |
- |
U_NAMESPACE_BEGIN |
-#ifdef DTITVFMT_DEBUG |
+#ifdef DTITVFMT_DEBUG |
#define PRINTMESG(msg) { std::cout << "(" << __FILE__ << ":" << __LINE__ << ") " << msg << "\n"; } |
#endif |
@@ -51,7 +53,9 @@ static const UChar gDateFormatSkeleton[][11] = { |
{LOW_Y, CAP_M, LOW_D, 0} }; |
-static const char gDateTimePatternsTag[]="DateTimePatterns"; |
+static const char gCalendarTag[] = "calendar"; |
+static const char gGregorianTag[] = "gregorian"; |
+static const char gDateTimePatternsTag[] = "DateTimePatterns"; |
// latestFirst: |
@@ -63,18 +67,21 @@ static const UChar gEarlierFirstPrefix[] = {LOW_E, LOW_A, LOW_R, LOW_L, LOW_I, L |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateIntervalFormat) |
+// Mutex, protects access to fDateFormat, fFromCalendar and fToCalendar. |
+// Needed because these data members are modified by const methods of DateIntervalFormat. |
+static UMutex gFormatterMutex = U_MUTEX_INITIALIZER; |
DateIntervalFormat* U_EXPORT2 |
-DateIntervalFormat::createInstance(const UnicodeString& skeleton, |
+DateIntervalFormat::createInstance(const UnicodeString& skeleton, |
UErrorCode& status) { |
return createInstance(skeleton, Locale::getDefault(), status); |
} |
DateIntervalFormat* U_EXPORT2 |
-DateIntervalFormat::createInstance(const UnicodeString& skeleton, |
- const Locale& locale, |
+DateIntervalFormat::createInstance(const UnicodeString& skeleton, |
+ const Locale& locale, |
UErrorCode& status) { |
#ifdef DTITVFMT_DEBUG |
char result[1000]; |
@@ -148,26 +155,29 @@ DateIntervalFormat::operator=(const DateIntervalFormat& itvfmt) { |
delete fDatePattern; |
delete fTimePattern; |
delete fDateTimeFormat; |
- if ( itvfmt.fDateFormat ) { |
- fDateFormat = (SimpleDateFormat*)itvfmt.fDateFormat->clone(); |
- } else { |
- fDateFormat = NULL; |
+ { |
+ Mutex lock(&gFormatterMutex); |
+ if ( itvfmt.fDateFormat ) { |
+ fDateFormat = (SimpleDateFormat*)itvfmt.fDateFormat->clone(); |
+ } else { |
+ fDateFormat = NULL; |
+ } |
+ if ( itvfmt.fFromCalendar ) { |
+ fFromCalendar = itvfmt.fFromCalendar->clone(); |
+ } else { |
+ fFromCalendar = NULL; |
+ } |
+ if ( itvfmt.fToCalendar ) { |
+ fToCalendar = itvfmt.fToCalendar->clone(); |
+ } else { |
+ fToCalendar = NULL; |
+ } |
} |
if ( itvfmt.fInfo ) { |
fInfo = itvfmt.fInfo->clone(); |
} else { |
fInfo = NULL; |
} |
- if ( itvfmt.fFromCalendar ) { |
- fFromCalendar = itvfmt.fFromCalendar->clone(); |
- } else { |
- fFromCalendar = NULL; |
- } |
- if ( itvfmt.fToCalendar ) { |
- fToCalendar = itvfmt.fToCalendar->clone(); |
- } else { |
- fToCalendar = NULL; |
- } |
fSkeleton = itvfmt.fSkeleton; |
int8_t i; |
for ( i = 0; i< DateIntervalInfo::kIPI_MAX_INDEX; ++i ) { |
@@ -201,52 +211,37 @@ DateIntervalFormat::clone(void) const { |
UBool |
DateIntervalFormat::operator==(const Format& other) const { |
- if (typeid(*this) == typeid(other)) { |
- const DateIntervalFormat* fmt = (DateIntervalFormat*)&other; |
-#ifdef DTITVFMT_DEBUG |
- UBool equal; |
- equal = (this == fmt); |
- |
- equal = (*fInfo == *fmt->fInfo); |
- equal = (*fDateFormat == *fmt->fDateFormat); |
- equal = fFromCalendar->isEquivalentTo(*fmt->fFromCalendar) ; |
- equal = fToCalendar->isEquivalentTo(*fmt->fToCalendar) ; |
- equal = (fSkeleton == fmt->fSkeleton); |
- equal = ((fDatePattern == NULL && fmt->fDatePattern == NULL) || (fDatePattern && fmt->fDatePattern && *fDatePattern == *fmt->fDatePattern)); |
- equal = ((fTimePattern == NULL && fmt->fTimePattern == NULL) || (fTimePattern && fmt->fTimePattern && *fTimePattern == *fmt->fTimePattern)); |
- equal = ((fDateTimeFormat == NULL && fmt->fDateTimeFormat == NULL) || (fDateTimeFormat && fmt->fDateTimeFormat && *fDateTimeFormat == *fmt->fDateTimeFormat)); |
-#endif |
- UBool res; |
- res = ( this == fmt ) || |
- ( Format::operator==(other) && |
- fInfo && |
- ( *fInfo == *fmt->fInfo ) && |
- fDateFormat && |
- ( *fDateFormat == *fmt->fDateFormat ) && |
- fFromCalendar && |
- fFromCalendar->isEquivalentTo(*fmt->fFromCalendar) && |
- fToCalendar && |
- fToCalendar->isEquivalentTo(*fmt->fToCalendar) && |
- fSkeleton == fmt->fSkeleton && |
- ((fDatePattern == NULL && fmt->fDatePattern == NULL) || (fDatePattern && fmt->fDatePattern && *fDatePattern == *fmt->fDatePattern)) && |
- ((fTimePattern == NULL && fmt->fTimePattern == NULL) || (fTimePattern && fmt->fTimePattern && *fTimePattern == *fmt->fTimePattern)) && |
- ((fDateTimeFormat == NULL && fmt->fDateTimeFormat == NULL) || (fDateTimeFormat && fmt->fDateTimeFormat && *fDateTimeFormat == *fmt->fDateTimeFormat)) && fLocale == fmt->fLocale); |
- int8_t i; |
- for (i = 0; i< DateIntervalInfo::kIPI_MAX_INDEX && res == TRUE; ++i ) { |
- res = ( fIntervalPatterns[i].firstPart == |
- fmt->fIntervalPatterns[i].firstPart) && |
- ( fIntervalPatterns[i].secondPart == |
- fmt->fIntervalPatterns[i].secondPart ) && |
- ( fIntervalPatterns[i].laterDateFirst == |
- fmt->fIntervalPatterns[i].laterDateFirst) ; |
- } |
- return res; |
- } |
- return FALSE; |
+ if (typeid(*this) != typeid(other)) {return FALSE;} |
+ const DateIntervalFormat* fmt = (DateIntervalFormat*)&other; |
+ if (this == fmt) {return TRUE;} |
+ if (!Format::operator==(other)) {return FALSE;} |
+ if ((fInfo != fmt->fInfo) && (fInfo == NULL || fmt->fInfo == NULL)) {return FALSE;} |
+ if (fInfo && fmt->fInfo && (*fInfo != *fmt->fInfo )) {return FALSE;} |
+ { |
+ Mutex lock(&gFormatterMutex); |
+ if (fDateFormat != fmt->fDateFormat && (fDateFormat == NULL || fmt->fDateFormat == NULL)) {return FALSE;} |
+ if (fDateFormat && fmt->fDateFormat && (*fDateFormat != *fmt->fDateFormat)) {return FALSE;} |
+ } |
+ // note: fFromCalendar and fToCalendar hold no persistent state, and therefore do not participate in operator ==. |
+ // fDateFormat has the master calendar for the DateIntervalFormat. |
+ if (fSkeleton != fmt->fSkeleton) {return FALSE;} |
+ if (fDatePattern != fmt->fDatePattern && (fDatePattern == NULL || fmt->fDatePattern == NULL)) {return FALSE;} |
+ if (fDatePattern && fmt->fDatePattern && (*fDatePattern != *fmt->fDatePattern)) {return FALSE;} |
+ if (fTimePattern != fmt->fTimePattern && (fTimePattern == NULL || fmt->fTimePattern == NULL)) {return FALSE;} |
+ if (fTimePattern && fmt->fTimePattern && (*fTimePattern != *fmt->fTimePattern)) {return FALSE;} |
+ if (fDateTimeFormat != fmt->fDateTimeFormat && (fDateTimeFormat == NULL || fmt->fDateTimeFormat == NULL)) {return FALSE;} |
+ if (fDateTimeFormat && fmt->fDateTimeFormat && (*fDateTimeFormat != *fmt->fDateTimeFormat)) {return FALSE;} |
+ if (fLocale != fmt->fLocale) {return FALSE;} |
+ |
+ for (int32_t i = 0; i< DateIntervalInfo::kIPI_MAX_INDEX; ++i ) { |
+ if (fIntervalPatterns[i].firstPart != fmt->fIntervalPatterns[i].firstPart) {return FALSE;} |
+ if (fIntervalPatterns[i].secondPart != fmt->fIntervalPatterns[i].secondPart ) {return FALSE;} |
+ if (fIntervalPatterns[i].laterDateFirst != fmt->fIntervalPatterns[i].laterDateFirst) {return FALSE;} |
+ } |
+ return TRUE; |
} |
- |
UnicodeString& |
DateIntervalFormat::format(const Formattable& obj, |
UnicodeString& appendTo, |
@@ -259,7 +254,7 @@ DateIntervalFormat::format(const Formattable& obj, |
if ( obj.getType() == Formattable::kObject ) { |
const UObject* formatObj = obj.getObject(); |
const DateInterval* interval = dynamic_cast<const DateInterval*>(formatObj); |
- if (interval != NULL){ |
+ if (interval != NULL) { |
return format(interval, appendTo, fieldPosition, status); |
} |
} |
@@ -276,16 +271,15 @@ DateIntervalFormat::format(const DateInterval* dtInterval, |
if ( U_FAILURE(status) ) { |
return appendTo; |
} |
- |
- if ( fFromCalendar != NULL && fToCalendar != NULL && |
- fDateFormat != NULL && fInfo != NULL ) { |
- fFromCalendar->setTime(dtInterval->getFromDate(), status); |
- fToCalendar->setTime(dtInterval->getToDate(), status); |
- if ( U_SUCCESS(status) ) { |
- return format(*fFromCalendar, *fToCalendar, appendTo,fieldPosition, status); |
- } |
+ if (fFromCalendar == NULL || fToCalendar == NULL || fDateFormat == NULL || fInfo == NULL) { |
+ status = U_INVALID_STATE_ERROR; |
+ return appendTo; |
} |
- return appendTo; |
+ |
+ Mutex lock(&gFormatterMutex); |
+ fFromCalendar->setTime(dtInterval->getFromDate(), status); |
+ fToCalendar->setTime(dtInterval->getToDate(), status); |
+ return formatImpl(*fFromCalendar, *fToCalendar, appendTo,fieldPosition, status); |
} |
@@ -295,6 +289,17 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
UnicodeString& appendTo, |
FieldPosition& pos, |
UErrorCode& status) const { |
+ Mutex lock(&gFormatterMutex); |
+ return formatImpl(fromCalendar, toCalendar, appendTo, pos, status); |
+} |
+ |
+ |
+UnicodeString& |
+DateIntervalFormat::formatImpl(Calendar& fromCalendar, |
+ Calendar& toCalendar, |
+ UnicodeString& appendTo, |
+ FieldPosition& pos, |
+ UErrorCode& status) const { |
if ( U_FAILURE(status) ) { |
return appendTo; |
} |
@@ -311,7 +316,7 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
if ( fromCalendar.get(UCAL_ERA,status) != toCalendar.get(UCAL_ERA,status)) { |
field = UCAL_ERA; |
- } else if ( fromCalendar.get(UCAL_YEAR, status) != |
+ } else if ( fromCalendar.get(UCAL_YEAR, status) != |
toCalendar.get(UCAL_YEAR, status) ) { |
field = UCAL_YEAR; |
} else if ( fromCalendar.get(UCAL_MONTH, status) != |
@@ -344,7 +349,7 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
return fDateFormat->format(fromCalendar, appendTo, pos); |
} |
UBool fromToOnSameDay = (field==UCAL_AM_PM || field==UCAL_HOUR || field==UCAL_MINUTE || field==UCAL_SECOND); |
- |
+ |
// following call should not set wrong status, |
// all the pass-in fields are valid till here |
int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field, |
@@ -362,7 +367,7 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
} |
return fallbackFormat(fromCalendar, toCalendar, fromToOnSameDay, appendTo, pos, status); |
} |
- // If the first part in interval pattern is empty, |
+ // If the first part in interval pattern is empty, |
// the 2nd part of it saves the full-pattern used in fall-back. |
// For a 'real' interval pattern, the first part will never be empty. |
if ( intervalPattern.firstPart.isEmpty() ) { |
@@ -384,7 +389,7 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
secondCal = &toCalendar; |
} |
// break the interval pattern into 2 parts, |
- // first part should not be empty, |
+ // first part should not be empty, |
UnicodeString originalPattern; |
fDateFormat->toPattern(originalPattern); |
fDateFormat->applyPattern(intervalPattern.firstPart); |
@@ -405,11 +410,11 @@ DateIntervalFormat::format(Calendar& fromCalendar, |
void |
-DateIntervalFormat::parseObject(const UnicodeString& /* source */, |
+DateIntervalFormat::parseObject(const UnicodeString& /* source */, |
Formattable& /* result */, |
ParsePosition& /* parse_pos */) const { |
// parseObject(const UnicodeString&, Formattable&, UErrorCode&) const |
- // will set status as U_INVALID_FORMAT_ERROR if |
+ // will set status as U_INVALID_FORMAT_ERROR if |
// parse_pos is still 0 |
} |
@@ -436,13 +441,13 @@ DateIntervalFormat::setDateIntervalInfo(const DateIntervalInfo& newItvPattern, |
delete fDateTimeFormat; |
fDateTimeFormat = NULL; |
- if ( fDateFormat ) { |
+ if (fDateFormat) { |
initializePattern(status); |
} |
} |
- |
+ |
const DateFormat* |
DateIntervalFormat::getDateFormat() const { |
return fDateFormat; |
@@ -487,6 +492,7 @@ const TimeZone& |
DateIntervalFormat::getTimeZone() const |
{ |
if (fDateFormat != NULL) { |
+ Mutex lock(&gFormatterMutex); |
return fDateFormat->getTimeZone(); |
} |
// If fDateFormat is NULL (unexpected), create default timezone. |
@@ -496,7 +502,7 @@ DateIntervalFormat::getTimeZone() const |
DateIntervalFormat::DateIntervalFormat(const Locale& locale, |
DateIntervalInfo* dtItvInfo, |
const UnicodeString* skeleton, |
- UErrorCode& status) |
+ UErrorCode& status) |
: fInfo(NULL), |
fDateFormat(NULL), |
fFromCalendar(NULL), |
@@ -506,37 +512,21 @@ DateIntervalFormat::DateIntervalFormat(const Locale& locale, |
fTimePattern(NULL), |
fDateTimeFormat(NULL) |
{ |
- if ( U_FAILURE(status) ) { |
- delete dtItvInfo; |
- return; |
- } |
- SimpleDateFormat* dtfmt = |
- static_cast<SimpleDateFormat *>( |
- DateFormat::createInstanceForSkeleton( |
- *skeleton, locale, status)); |
- if ( U_FAILURE(status) ) { |
- delete dtItvInfo; |
- delete dtfmt; |
- return; |
- } |
- if ( dtfmt == NULL || dtItvInfo == NULL) { |
- status = U_MEMORY_ALLOCATION_ERROR; |
- // safe to delete NULL |
- delete dtfmt; |
- delete dtItvInfo; |
+ LocalPointer<DateIntervalInfo> info(dtItvInfo, status); |
+ LocalPointer<SimpleDateFormat> dtfmt(static_cast<SimpleDateFormat *>( |
+ DateFormat::createInstanceForSkeleton(*skeleton, locale, status)), status); |
+ if (U_FAILURE(status)) { |
return; |
} |
+ |
if ( skeleton ) { |
fSkeleton = *skeleton; |
} |
- fInfo = dtItvInfo; |
- fDateFormat = dtfmt; |
- if ( dtfmt->getCalendar() ) { |
- fFromCalendar = dtfmt->getCalendar()->clone(); |
- fToCalendar = dtfmt->getCalendar()->clone(); |
- } else { |
- fFromCalendar = NULL; |
- fToCalendar = NULL; |
+ fInfo = info.orphan(); |
+ fDateFormat = dtfmt.orphan(); |
+ if ( fDateFormat->getCalendar() ) { |
+ fFromCalendar = fDateFormat->getCalendar()->clone(); |
+ fToCalendar = fDateFormat->getCalendar()->clone(); |
} |
initializePattern(status); |
} |
@@ -546,7 +536,7 @@ DateIntervalFormat::create(const Locale& locale, |
DateIntervalInfo* dtitvinf, |
const UnicodeString* skeleton, |
UErrorCode& status) { |
- DateIntervalFormat* f = new DateIntervalFormat(locale, dtitvinf, |
+ DateIntervalFormat* f = new DateIntervalFormat(locale, dtitvinf, |
skeleton, status); |
if ( f == NULL ) { |
status = U_MEMORY_ALLOCATION_ERROR; |
@@ -561,10 +551,10 @@ DateIntervalFormat::create(const Locale& locale, |
-/** |
+/** |
* Initialize interval patterns locale to this formatter |
- * |
- * This code is a bit complicated since |
+ * |
+ * This code is a bit complicated since |
* 1. the interval patterns saved in resource bundle files are interval |
* patterns based on date or time only. |
* It does not have interval patterns based on both date and time. |
@@ -572,30 +562,30 @@ DateIntervalFormat::create(const Locale& locale, |
* |
* For example, it has interval patterns on skeleton "dMy" and "hm", |
* but it does not have interval patterns on skeleton "dMyhm". |
- * |
+ * |
* The rule to genearte interval patterns for both date and time skeleton are |
- * 1) when the year, month, or day differs, concatenate the two original |
- * expressions with a separator between, |
- * For example, interval pattern from "Jan 10, 2007 10:10 am" |
- * to "Jan 11, 2007 10:10am" is |
- * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am" |
+ * 1) when the year, month, or day differs, concatenate the two original |
+ * expressions with a separator between, |
+ * For example, interval pattern from "Jan 10, 2007 10:10 am" |
+ * to "Jan 11, 2007 10:10am" is |
+ * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am" |
* |
- * 2) otherwise, present the date followed by the range expression |
+ * 2) otherwise, present the date followed by the range expression |
* for the time. |
- * For example, interval pattern from "Jan 10, 2007 10:10 am" |
- * to "Jan 10, 2007 11:10am" is |
- * "Jan 10, 2007 10:10 am - 11:10am" |
+ * For example, interval pattern from "Jan 10, 2007 10:10 am" |
+ * to "Jan 10, 2007 11:10am" is |
+ * "Jan 10, 2007 10:10 am - 11:10am" |
* |
* 2. even a pattern does not request a certion calendar field, |
* the interval pattern needs to include such field if such fields are |
* different between 2 dates. |
- * For example, a pattern/skeleton is "hm", but the interval pattern |
+ * For example, a pattern/skeleton is "hm", but the interval pattern |
* includes year, month, and date when year, month, and date differs. |
- * |
+ * |
* @param status output param set to success/failure code on exit |
- * @stable ICU 4.0 |
+ * @stable ICU 4.0 |
*/ |
-void |
+void |
DateIntervalFormat::initializePattern(UErrorCode& status) { |
if ( U_FAILURE(status) ) { |
return; |
@@ -617,7 +607,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
fSkeleton = DateTimePatternGenerator::staticGetSkeleton( |
fullPattern, status); |
if ( U_FAILURE(status) ) { |
- return; |
+ return; |
} |
} |
@@ -639,7 +629,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
/* the difference between time skeleton and normalizedTimeSkeleton are: |
* 1. (Formerly, normalized time skeleton folded 'H' to 'h'; no longer true) |
* 2. 'a' is omitted in normalized time skeleton. |
- * 3. there is only one appearance for 'h' or 'H', 'm','v', 'z' in normalized |
+ * 3. there is only one appearance for 'h' or 'H', 'm','v', 'z' in normalized |
* time skeleton |
* |
* The difference between date skeleton and normalizedDateSkeleton are: |
@@ -665,30 +655,25 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
// with the time interval. |
// The date/time pattern ( such as {0} {1} ) is saved in |
// calendar, that is why need to get the CalendarData here. |
- CalendarData* calData = new CalendarData(locale, NULL, status); |
- if ( U_FAILURE(status) ) { |
- delete calData; |
- return; |
- } |
- if ( calData == NULL ) { |
- status = U_MEMORY_ALLOCATION_ERROR; |
- return; |
- } |
- |
- const UResourceBundle* dateTimePatternsRes = calData->getByKey( |
- gDateTimePatternsTag, status); |
+ LocalUResourceBundlePointer dateTimePatternsRes(ures_open(NULL, locale.getBaseName(), &status)); |
+ ures_getByKey(dateTimePatternsRes.getAlias(), gCalendarTag, |
+ dateTimePatternsRes.getAlias(), &status); |
+ ures_getByKeyWithFallback(dateTimePatternsRes.getAlias(), gGregorianTag, |
+ dateTimePatternsRes.getAlias(), &status); |
+ ures_getByKeyWithFallback(dateTimePatternsRes.getAlias(), gDateTimePatternsTag, |
+ dateTimePatternsRes.getAlias(), &status); |
+ |
int32_t dateTimeFormatLength; |
const UChar* dateTimeFormat = ures_getStringByIndex( |
- dateTimePatternsRes, |
+ dateTimePatternsRes.getAlias(), |
(int32_t)DateFormat::kDateTime, |
&dateTimeFormatLength, &status); |
if ( U_SUCCESS(status) && dateTimeFormatLength >= 3 ) { |
fDateTimeFormat = new UnicodeString(dateTimeFormat, dateTimeFormatLength); |
} |
- delete calData; |
} |
- UBool found = setSeparateDateTimePtn(normalizedDateSkeleton, |
+ UBool found = setSeparateDateTimePtn(normalizedDateSkeleton, |
normalizedTimeSkeleton); |
// for skeletons with seconds, found is false and we enter this block |
@@ -702,15 +687,15 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
UnicodeString pattern = DateFormat::getBestPattern( |
locale, timeSkeleton, status); |
if ( U_FAILURE(status) ) { |
- return; |
+ return; |
} |
// for fall back interval patterns, |
// the first part of the pattern is empty, |
// the second part of the pattern is the full-pattern |
// should be used in fall-back. |
- setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder()); |
- setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder()); |
- setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder()); |
} else { |
// TODO: fall back |
} |
@@ -719,7 +704,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
} |
return; |
} // end of skeleton not found |
- // interval patterns for skeleton are found in resource |
+ // interval patterns for skeleton are found in resource |
if ( timeSkeleton.length() == 0 ) { |
// done |
} else if ( dateSkeleton.length() == 0 ) { |
@@ -728,25 +713,25 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
UnicodeString pattern = DateFormat::getBestPattern( |
locale, timeSkeleton, status); |
if ( U_FAILURE(status) ) { |
- return; |
+ return; |
} |
// for fall back interval patterns, |
// the first part of the pattern is empty, |
// the second part of the pattern is the full-pattern |
// should be used in fall-back. |
- setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder()); |
- setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder()); |
- setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder()); |
+ setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder()); |
} else { |
/* if both present, |
- * 1) when the year, month, or day differs, |
- * concatenate the two original expressions with a separator between, |
- * 2) otherwise, present the date followed by the |
- * range expression for the time. |
+ * 1) when the year, month, or day differs, |
+ * concatenate the two original expressions with a separator between, |
+ * 2) otherwise, present the date followed by the |
+ * range expression for the time. |
*/ |
/* |
- * 1) when the year, month, or day differs, |
- * concatenate the two original expressions with a separator between, |
+ * 1) when the year, month, or day differs, |
+ * concatenate the two original expressions with a separator between, |
*/ |
// if field exists, use fall back |
UnicodeString skeleton = fSkeleton; |
@@ -765,13 +750,13 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
skeleton.insert(0, LOW_Y); |
setFallbackPattern(UCAL_YEAR, skeleton, status); |
} |
- |
+ |
/* |
- * 2) otherwise, present the date followed by the |
- * range expression for the time. |
+ * 2) otherwise, present the date followed by the |
+ * range expression for the time. |
*/ |
- if ( fDateTimeFormat == 0 ) { |
+ if ( fDateTimeFormat == NULL ) { |
// earlier failure getting dateTimeFormat |
return; |
} |
@@ -787,10 +772,10 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { |
-void U_EXPORT2 |
-DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
- UnicodeString& dateSkeleton, |
- UnicodeString& normalizedDateSkeleton, |
+void U_EXPORT2 |
+DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
+ UnicodeString& dateSkeleton, |
+ UnicodeString& normalizedDateSkeleton, |
UnicodeString& timeSkeleton, |
UnicodeString& normalizedTimeSkeleton) { |
// dateSkeleton follows the sequence of y*M*E*d* |
@@ -845,7 +830,7 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
dateSkeleton.append(ch); |
break; |
case LOW_A: |
- // 'a' is implicitly handled |
+ // 'a' is implicitly handled |
timeSkeleton.append(ch); |
break; |
case LOW_H: |
@@ -878,7 +863,7 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
case CAP_A: |
timeSkeleton.append(ch); |
normalizedTimeSkeleton.append(ch); |
- break; |
+ break; |
} |
} |
@@ -935,7 +920,7 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
* Generate date or time interval pattern from resource, |
* and set them into the interval pattern locale to this formatter. |
* |
- * It needs to handle the following: |
+ * It needs to handle the following: |
* 1. need to adjust field width. |
* For example, the interval patterns saved in DateIntervalInfo |
* includes "dMMMy", but not "dMMMMy". |
@@ -955,7 +940,7 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, |
* FALSE otherwise. |
* @stable ICU 4.0 |
*/ |
-UBool |
+UBool |
DateIntervalFormat::setSeparateDateTimePtn( |
const UnicodeString& dateSkeleton, |
const UnicodeString& timeSkeleton) { |
@@ -971,17 +956,17 @@ DateIntervalFormat::setSeparateDateTimePtn( |
skeleton = &dateSkeleton; |
} |
- /* interval patterns for skeleton "dMMMy" (but not "dMMMMy") |
+ /* interval patterns for skeleton "dMMMy" (but not "dMMMMy") |
* are defined in resource, |
* interval patterns for skeleton "dMMMMy" are calculated by |
* 1. get the best match skeleton for "dMMMMy", which is "dMMMy" |
* 2. get the interval patterns for "dMMMy", |
- * 3. extend "MMM" to "MMMM" in above interval patterns for "dMMMMy" |
+ * 3. extend "MMM" to "MMMM" in above interval patterns for "dMMMMy" |
* getBestSkeleton() is step 1. |
*/ |
// best skeleton, and the difference information |
int8_t differenceInfo = 0; |
- const UnicodeString* bestSkeleton = fInfo->getBestSkeleton(*skeleton, |
+ const UnicodeString* bestSkeleton = fInfo->getBestSkeleton(*skeleton, |
differenceInfo); |
/* best skeleton could be NULL. |
For example: in "ca" resource file, |
@@ -993,9 +978,9 @@ DateIntervalFormat::setSeparateDateTimePtn( |
and the best skeleton match could be NULL |
*/ |
if ( bestSkeleton == NULL ) { |
- return false; |
- } |
- |
+ return false; |
+ } |
+ |
// Set patterns for fallback use, need to do this |
// before returning if differenceInfo == -1 |
UErrorCode status; |
@@ -1014,10 +999,10 @@ DateIntervalFormat::setSeparateDateTimePtn( |
// 0 means the best matched skeleton is the same as input skeleton |
// 1 means the fields are the same, but field width are different |
// 2 means the only difference between fields are v/z, |
- // -1 means there are other fields difference |
+ // -1 means there are other fields difference |
// (this will happen, for instance, if the supplied skeleton has seconds, |
// but no skeletons in the intervalFormats data do) |
- if ( differenceInfo == -1 ) { |
+ if ( differenceInfo == -1 ) { |
// skeleton has different fields, not only v/z difference |
return false; |
} |
@@ -1029,10 +1014,10 @@ DateIntervalFormat::setSeparateDateTimePtn( |
setIntervalPattern(UCAL_DATE, skeleton, bestSkeleton, differenceInfo, |
&extendedSkeleton, &extendedBestSkeleton); |
- UBool extended = setIntervalPattern(UCAL_MONTH, skeleton, bestSkeleton, |
+ UBool extended = setIntervalPattern(UCAL_MONTH, skeleton, bestSkeleton, |
differenceInfo, |
&extendedSkeleton, &extendedBestSkeleton); |
- |
+ |
if ( extended ) { |
bestSkeleton = &extendedBestSkeleton; |
skeleton = &extendedSkeleton; |
@@ -1068,9 +1053,9 @@ DateIntervalFormat::setFallbackPattern(UCalendarDateFields field, |
void |
-DateIntervalFormat::setPatternInfo(UCalendarDateFields field, |
+DateIntervalFormat::setPatternInfo(UCalendarDateFields field, |
const UnicodeString* firstPart, |
- const UnicodeString* secondPart, |
+ const UnicodeString* secondPart, |
UBool laterDateFirst) { |
// for fall back interval patterns, |
// the first part of the pattern is empty, |
@@ -1108,12 +1093,12 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
const UnicodeString* pattern = &intervalPattern; |
UBool order = laterDateFirst; |
// check for "latestFirst:" or "earliestFirst:" prefix |
- int8_t prefixLength = sizeof(gLaterFirstPrefix)/sizeof(gLaterFirstPrefix[0]); |
- int8_t earliestFirstLength = sizeof(gEarlierFirstPrefix)/sizeof(gEarlierFirstPrefix[0]); |
+ int8_t prefixLength = UPRV_LENGTHOF(gLaterFirstPrefix); |
+ int8_t earliestFirstLength = UPRV_LENGTHOF(gEarlierFirstPrefix); |
UnicodeString realPattern; |
if ( intervalPattern.startsWith(gLaterFirstPrefix, prefixLength) ) { |
order = true; |
- intervalPattern.extract(prefixLength, |
+ intervalPattern.extract(prefixLength, |
intervalPattern.length() - prefixLength, |
realPattern); |
pattern = &realPattern; |
@@ -1127,7 +1112,7 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
} |
int32_t splitPoint = splitPatternInto2Part(*pattern); |
- |
+ |
UnicodeString firstPart; |
UnicodeString secondPart; |
pattern->extract(0, splitPoint, firstPart); |
@@ -1154,11 +1139,11 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
* 0 means the best matched skeleton is the same as input skeleton |
* 1 means the fields are the same, but field width are different |
* 2 means the only difference between fields are v/z, |
- * -1 means there are other fields difference |
+ * -1 means there are other fields difference |
* |
* @param extendedSkeleton extended skeleton |
* @param extendedBestSkeleton extended best match skeleton |
- * @return whether the interval pattern is found |
+ * @return whether the interval pattern is found |
* through extending skeleton or not. |
* TRUE if interval pattern is found by |
* extending skeleton, FALSE otherwise. |
@@ -1183,7 +1168,7 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
} |
// for 24 hour system, interval patterns in resource file |
- // might not include pattern when am_pm differ, |
+ // might not include pattern when am_pm differ, |
// which should be the same as hour differ. |
// add it here for simplicity |
if ( field == UCAL_AM_PM ) { |
@@ -1192,7 +1177,7 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
setIntervalPattern(field, pattern); |
} |
return false; |
- } |
+ } |
// else, looking for pattern when 'y' differ for 'dMMMM' skeleton, |
// first, get best match pattern "MMMd", |
// since there is no pattern for 'y' differs for skeleton 'MMMd', |
@@ -1206,11 +1191,11 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
extendedSkeleton->insert(0, fieldLetter); |
extendedBestSkeleton->insert(0, fieldLetter); |
// for example, looking for patterns when 'y' differ for |
- // skeleton "MMMM". |
+ // skeleton "MMMM". |
fInfo->getIntervalPattern(*extendedBestSkeleton,field,pattern,status); |
if ( pattern.isEmpty() && differenceInfo == 0 ) { |
// if there is no skeleton "yMMMM" defined, |
- // look for the best match skeleton, for example: "yMMM" |
+ // look for the best match skeleton, for example: "yMMM" |
const UnicodeString* tmpBest = fInfo->getBestSkeleton( |
*extendedBestSkeleton, differenceInfo); |
if ( tmpBest != 0 && differenceInfo != -1 ) { |
@@ -1219,7 +1204,7 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
} |
} |
} |
- } |
+ } |
if ( !pattern.isEmpty() ) { |
if ( differenceInfo != 0 ) { |
UnicodeString adjustIntervalPattern; |
@@ -1238,7 +1223,7 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, |
-int32_t U_EXPORT2 |
+int32_t U_EXPORT2 |
DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) { |
UBool inQuote = false; |
UChar prevCh = 0; |
@@ -1248,7 +1233,7 @@ DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) |
It is a pattern applies to first calendar if it is first time seen, |
otherwise, it is a pattern applies to the second calendar |
*/ |
- UBool patternRepeated[] = |
+ UBool patternRepeated[] = |
{ |
// A B C D E F G H I J K L M N O |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
@@ -1261,16 +1246,16 @@ DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) |
}; |
int8_t PATTERN_CHAR_BASE = 0x41; |
- |
+ |
/* loop through the pattern string character by character looking for |
* the first repeated pattern letter, which breaks the interval pattern |
- * into 2 parts. |
+ * into 2 parts. |
*/ |
int32_t i; |
UBool foundRepetition = false; |
for (i = 0; i < intervalPattern.length(); ++i) { |
UChar ch = intervalPattern.charAt(i); |
- |
+ |
if (ch != prevCh && count > 0) { |
// check the repeativeness of pattern letter |
UBool repeated = patternRepeated[(int)(prevCh - PATTERN_CHAR_BASE)]; |
@@ -1282,26 +1267,26 @@ DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) |
} |
count = 0; |
} |
- if (ch == '\'') { |
+ if (ch == 0x0027 /*'*/) { |
// Consecutive single quotes are a single quote literal, |
// either outside of quotes or between quotes |
- if ((i+1) < intervalPattern.length() && |
- intervalPattern.charAt(i+1) == '\'') { |
+ if ((i+1) < intervalPattern.length() && |
+ intervalPattern.charAt(i+1) == 0x0027 /*'*/) { |
++i; |
} else { |
inQuote = ! inQuote; |
} |
- } |
+ } |
else if (!inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/) |
|| (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) { |
- // ch is a date-time pattern character |
+ // ch is a date-time pattern character |
prevCh = ch; |
++count; |
} |
} |
// check last pattern char, distinguish |
- // "dd MM" ( no repetition ), |
- // "d-d"(last char repeated ), and |
+ // "dd MM" ( no repetition ), |
+ // "d-d"(last char repeated ), and |
// "d-d MM" ( repetition found ) |
if ( count > 0 && foundRepetition == FALSE ) { |
if ( patternRepeated[(int)(prevCh - PATTERN_CHAR_BASE)] == FALSE ) { |
@@ -1348,7 +1333,7 @@ DateIntervalFormat::adjustPosition(UnicodeString& combiningPattern, // has {0} a |
} |
} |
-UnicodeString& |
+UnicodeString& |
DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, |
Calendar& toCalendar, |
UBool fromToOnSameDay, // new |
@@ -1361,38 +1346,36 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, |
UnicodeString fullPattern; // for saving the pattern in fDateFormat |
UBool formatDatePlusTimeRange = (fromToOnSameDay && fDatePattern && fTimePattern); |
// the fall back |
- // no need delete earlierDate and laterDate since they are adopted |
if (formatDatePlusTimeRange) { |
fDateFormat->toPattern(fullPattern); // save current pattern, restore later |
fDateFormat->applyPattern(*fTimePattern); |
} |
FieldPosition otherPos; |
otherPos.setField(pos.getField()); |
- UnicodeString* earlierDate = new UnicodeString(); |
- fDateFormat->format(fromCalendar, *earlierDate, pos); |
- UnicodeString* laterDate = new UnicodeString(); |
- fDateFormat->format(toCalendar, *laterDate, otherPos); |
+ UnicodeString earlierDate; |
+ fDateFormat->format(fromCalendar, earlierDate, pos); |
+ UnicodeString laterDate; |
+ fDateFormat->format(toCalendar, laterDate, otherPos); |
UnicodeString fallbackPattern; |
fInfo->getFallbackIntervalPattern(fallbackPattern); |
- adjustPosition(fallbackPattern, *earlierDate, pos, *laterDate, otherPos, pos); |
- Formattable fmtArray[2]; |
- fmtArray[0].adoptString(earlierDate); |
- fmtArray[1].adoptString(laterDate); |
- |
+ adjustPosition(fallbackPattern, earlierDate, pos, laterDate, otherPos, pos); |
UnicodeString fallbackRange; |
- MessageFormat::format(fallbackPattern, fmtArray, 2, fallbackRange, status); |
+ SimpleFormatter(fallbackPattern, 2, 2, status). |
+ format(earlierDate, laterDate, fallbackRange, status); |
if ( U_SUCCESS(status) && formatDatePlusTimeRange ) { |
// fallbackRange has just the time range, need to format the date part and combine that |
fDateFormat->applyPattern(*fDatePattern); |
- UnicodeString* datePortion = new UnicodeString(); |
+ UnicodeString datePortion; |
otherPos.setBeginIndex(0); |
otherPos.setEndIndex(0); |
- fDateFormat->format(fromCalendar, *datePortion, otherPos); |
- adjustPosition(*fDateTimeFormat, fallbackRange, pos, *datePortion, otherPos, pos); |
- fmtArray[0].setString(fallbackRange); // {0} is time range |
- fmtArray[1].adoptString(datePortion); // {1} is single date portion |
- fallbackRange.remove(); |
- MessageFormat::format(*fDateTimeFormat, fmtArray, 2, fallbackRange, status); |
+ fDateFormat->format(fromCalendar, datePortion, otherPos); |
+ adjustPosition(*fDateTimeFormat, fallbackRange, pos, datePortion, otherPos, pos); |
+ const UnicodeString *values[2] = { |
+ &fallbackRange, // {0} is time range |
+ &datePortion, // {1} is single date portion |
+ }; |
+ SimpleFormatter(*fDateTimeFormat, 2, 2, status). |
+ formatAndReplace(values, 2, fallbackRange, NULL, 0, status); |
} |
if ( U_SUCCESS(status) ) { |
appendTo.append(fallbackRange); |
@@ -1407,7 +1390,7 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, |
-UBool U_EXPORT2 |
+UBool U_EXPORT2 |
DateIntervalFormat::fieldExistsInSkeleton(UCalendarDateFields field, |
const UnicodeString& skeleton) |
{ |
@@ -1417,14 +1400,14 @@ DateIntervalFormat::fieldExistsInSkeleton(UCalendarDateFields field, |
-void U_EXPORT2 |
+void U_EXPORT2 |
DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
const UnicodeString& bestMatchSkeleton, |
const UnicodeString& bestIntervalPattern, |
int8_t differenceInfo, |
UnicodeString& adjustedPtn) { |
adjustedPtn = bestIntervalPattern; |
- int32_t inputSkeletonFieldWidth[] = |
+ int32_t inputSkeletonFieldWidth[] = |
{ |
// A B C D E F G H I J K L M N O |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
@@ -1436,7 +1419,7 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
}; |
- int32_t bestMatchSkeletonFieldWidth[] = |
+ int32_t bestMatchSkeletonFieldWidth[] = |
{ |
// A B C D E F G H I J K L M N O |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
@@ -1460,8 +1443,8 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
int32_t count = 0; |
const int8_t PATTERN_CHAR_BASE = 0x41; |
- |
- // loop through the pattern string character by character |
+ |
+ // loop through the pattern string character by character |
int32_t adjustedPtnLength = adjustedPtn.length(); |
int32_t i; |
for (i = 0; i < adjustedPtnLength; ++i) { |
@@ -1470,9 +1453,9 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
// check the repeativeness of pattern letter |
UChar skeletonChar = prevCh; |
if ( skeletonChar == CAP_L ) { |
- // there is no "L" (always be "M") in skeleton, |
+ // there is no "L" (always be "M") in skeleton, |
// but there is "L" in pattern. |
- // for skeleton "M+", the pattern might be "...L..." |
+ // for skeleton "M+", the pattern might be "...L..." |
skeletonChar = CAP_M; |
} |
int32_t fieldCount = bestMatchSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)]; |
@@ -1481,25 +1464,25 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
count = inputFieldCount - fieldCount; |
int32_t j; |
for ( j = 0; j < count; ++j ) { |
- adjustedPtn.insert(i, prevCh); |
- } |
+ adjustedPtn.insert(i, prevCh); |
+ } |
i += count; |
adjustedPtnLength += count; |
} |
count = 0; |
} |
- if (ch == '\'') { |
+ if (ch == 0x0027 /*'*/) { |
// Consecutive single quotes are a single quote literal, |
// either outside of quotes or between quotes |
- if ((i+1) < adjustedPtn.length() && adjustedPtn.charAt(i+1) == '\'') { |
+ if ((i+1) < adjustedPtn.length() && adjustedPtn.charAt(i+1) == 0x0027 /* ' */) { |
++i; |
} else { |
inQuote = ! inQuote; |
} |
- } |
- else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/) |
+ } |
+ else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/) |
|| (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) { |
- // ch is a date-time pattern character |
+ // ch is a date-time pattern character |
prevCh = ch; |
++count; |
} |
@@ -1509,9 +1492,9 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
// check the repeativeness of pattern letter |
UChar skeletonChar = prevCh; |
if ( skeletonChar == CAP_L ) { |
- // there is no "L" (always be "M") in skeleton, |
+ // there is no "L" (always be "M") in skeleton, |
// but there is "L" in pattern. |
- // for skeleton "M+", the pattern might be "...L..." |
+ // for skeleton "M+", the pattern might be "...L..." |
skeletonChar = CAP_M; |
} |
int32_t fieldCount = bestMatchSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)]; |
@@ -1520,15 +1503,15 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, |
count = inputFieldCount - fieldCount; |
int32_t j; |
for ( j = 0; j < count; ++j ) { |
- adjustedPtn.append(prevCh); |
- } |
+ adjustedPtn.append(prevCh); |
+ } |
} |
} |
} |
-void |
+void |
DateIntervalFormat::concatSingleDate2TimeInterval(UnicodeString& format, |
const UnicodeString& datePattern, |
UCalendarDateFields field, |
@@ -1541,20 +1524,16 @@ DateIntervalFormat::concatSingleDate2TimeInterval(UnicodeString& format, |
} |
PatternInfo& timeItvPtnInfo = fIntervalPatterns[itvPtnIndex]; |
if ( !timeItvPtnInfo.firstPart.isEmpty() ) { |
- // UnicodeString allocated here is adopted, so no need to delete |
- UnicodeString* timeIntervalPattern = new UnicodeString(timeItvPtnInfo.firstPart); |
- timeIntervalPattern->append(timeItvPtnInfo.secondPart); |
- UnicodeString* dateStr = new UnicodeString(datePattern); |
- Formattable fmtArray[2]; |
- fmtArray[0].adoptString(timeIntervalPattern); |
- fmtArray[1].adoptString(dateStr); |
+ UnicodeString timeIntervalPattern(timeItvPtnInfo.firstPart); |
+ timeIntervalPattern.append(timeItvPtnInfo.secondPart); |
UnicodeString combinedPattern; |
- MessageFormat::format(format, fmtArray, 2, combinedPattern, status); |
+ SimpleFormatter(format, 2, 2, status). |
+ format(timeIntervalPattern, datePattern, combinedPattern, status); |
if ( U_FAILURE(status) ) { |
return; |
} |
setIntervalPattern(field, combinedPattern, timeItvPtnInfo.laterDateFirst); |
- } |
+ } |
// else: fall back |
// it should not happen if the interval format defined is valid |
} |