]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/windtfmt.cpp
ICU-57149.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / windtfmt.cpp
index 0fda3419bcee60713d6a32c92505e94cbc1a3775..93aa473afef1aee7d187b496730555c99f31869a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ********************************************************************************
-*   Copyright (C) 2005-2011, International Business Machines
+*   Copyright (C) 2005-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
@@ -19,7 +19,7 @@
 #include "unicode/format.h"
 #include "unicode/fmtable.h"
 #include "unicode/datefmt.h"
-#include "unicode/msgfmt.h"
+#include "unicode/simpleformatter.h"
 #include "unicode/calendar.h"
 #include "unicode/gregocal.h"
 #include "unicode/locid.h"
@@ -45,8 +45,6 @@ U_NAMESPACE_BEGIN
 
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Win32DateFormat)
 
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
-
 #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
 #define DELETE_ARRAY(array) uprv_free((void *) (array))
 
@@ -70,7 +68,7 @@ UnicodeString* Win32DateFormat::getTimeDateFormat(const Calendar *cal, const Loc
 
     if (U_FAILURE(status)) {
         static const UChar defaultPattern[] = {0x007B, 0x0031, 0x007D, 0x0020, 0x007B, 0x0030, 0x007D, 0x0000}; // "{1} {0}"
-        return new UnicodeString(defaultPattern, ARRAY_SIZE(defaultPattern));
+        return new UnicodeString(defaultPattern, UPRV_LENGTHOF(defaultPattern));
     }
 
     int32_t resStrLen = 0;
@@ -94,7 +92,7 @@ UnicodeString* Win32DateFormat::getTimeDateFormat(const Calendar *cal, const Loc
 
 // TODO: Range-check timeStyle, dateStyle
 Win32DateFormat::Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status)
-  : DateFormat(), fDateTimeMsg(NULL), fTimeStyle(timeStyle), fDateStyle(dateStyle), fLocale(&locale), fZoneID()
+  : DateFormat(), fDateTimeMsg(NULL), fTimeStyle(timeStyle), fDateStyle(dateStyle), fLocale(locale), fZoneID()
 {
     if (U_SUCCESS(status)) {
         fLCID = locale.getLCID();
@@ -124,9 +122,10 @@ Win32DateFormat &Win32DateFormat::operator=(const Win32DateFormat &other)
 
 //    delete fCalendar;
 
-    this->fDateTimeMsg = other.fDateTimeMsg;
+    this->fDateTimeMsg = other.fDateTimeMsg == NULL ? NULL : new UnicodeString(*other.fDateTimeMsg);
     this->fTimeStyle   = other.fTimeStyle;
     this->fDateStyle   = other.fDateStyle;
+    this->fLocale      = other.fLocale;
     this->fLCID        = other.fLCID;
 //    this->fCalendar    = other.fCalendar->clone();
     this->fZoneID      = other.fZoneID;
@@ -166,22 +165,18 @@ UnicodeString &Win32DateFormat::format(Calendar &cal, UnicodeString &appendTo, F
 
 
     if (fDateStyle != DateFormat::kNone && fTimeStyle != DateFormat::kNone) {
-        UnicodeString *date = new UnicodeString();
-        UnicodeString *time = new UnicodeString();
+        UnicodeString date;
+        UnicodeString time;
         UnicodeString *pattern = fDateTimeMsg;
-        Formattable timeDateArray[2];
-
-        formatDate(&st_local, *date);
-        formatTime(&st_local, *time);
 
-        timeDateArray[0].adoptString(time);
-        timeDateArray[1].adoptString(date);
+        formatDate(&st_local, date);
+        formatTime(&st_local, time);
 
         if (strcmp(fCalendar->getType(), cal.getType()) != 0) {
-            pattern = getTimeDateFormat(&cal, fLocale, status);
+            pattern = getTimeDateFormat(&cal, &fLocale, status);
         }
 
-        MessageFormat::format(*pattern, timeDateArray, 2, appendTo, status);
+        SimpleFormatter(*pattern, 2, 2, status).format(time, date, appendTo, status);
     } else if (fDateStyle != DateFormat::kNone) {
         formatDate(&st_local, appendTo);
     } else if (fTimeStyle != DateFormat::kNone) {
@@ -203,7 +198,7 @@ void Win32DateFormat::adoptCalendar(Calendar *newCalendar)
 
         if (fDateStyle != DateFormat::kNone && fTimeStyle != DateFormat::kNone) {
             delete fDateTimeMsg;
-            fDateTimeMsg = getTimeDateFormat(newCalendar, fLocale, status);
+            fDateTimeMsg = getTimeDateFormat(newCalendar, &fLocale, status);
         }
     }