| Index: source/i18n/windtfmt.cpp
|
| diff --git a/source/i18n/windtfmt.cpp b/source/i18n/windtfmt.cpp
|
| index 9c9b57baf13e3098912fc69ecc9af7b0697db1ca..10243a702b7b445cab847fbae79890be6d40df1d 100644
|
| --- a/source/i18n/windtfmt.cpp
|
| +++ b/source/i18n/windtfmt.cpp
|
| @@ -1,6 +1,8 @@
|
| +// Copyright (C) 2016 and later: Unicode, Inc. and others.
|
| +// License & terms of use: http://www.unicode.org/copyright.html
|
| /*
|
| ********************************************************************************
|
| -* Copyright (C) 2005-2014, International Business Machines
|
| +* Copyright (C) 2005-2016, International Business Machines
|
| * Corporation and others. All Rights Reserved.
|
| ********************************************************************************
|
| *
|
| @@ -19,7 +21,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 +47,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 +70,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;
|
| @@ -167,22 +167,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);
|
| }
|
|
|
| - 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) {
|
| @@ -236,8 +232,8 @@ static const DWORD dfFlags[] = {DATE_LONGDATE, DATE_LONGDATE, DATE_SHORTDATE, DA
|
| void Win32DateFormat::formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const
|
| {
|
| int result;
|
| - UChar stackBuffer[STACK_BUFFER_SIZE];
|
| - UChar *buffer = stackBuffer;
|
| + wchar_t stackBuffer[STACK_BUFFER_SIZE];
|
| + wchar_t *buffer = stackBuffer;
|
|
|
| result = GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, STACK_BUFFER_SIZE);
|
|
|
| @@ -245,12 +241,12 @@ void Win32DateFormat::formatDate(const SYSTEMTIME *st, UnicodeString &appendTo)
|
| if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
| int newLength = GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, NULL, 0);
|
|
|
| - buffer = NEW_ARRAY(UChar, newLength);
|
| + buffer = NEW_ARRAY(wchar_t, newLength);
|
| GetDateFormatW(fLCID, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, newLength);
|
| }
|
| }
|
|
|
| - appendTo.append(buffer, (int32_t) wcslen(buffer));
|
| + appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
|
|
|
| if (buffer != stackBuffer) {
|
| DELETE_ARRAY(buffer);
|
| @@ -262,8 +258,8 @@ static const DWORD tfFlags[] = {0, 0, 0, TIME_NOSECONDS};
|
| void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const
|
| {
|
| int result;
|
| - UChar stackBuffer[STACK_BUFFER_SIZE];
|
| - UChar *buffer = stackBuffer;
|
| + wchar_t stackBuffer[STACK_BUFFER_SIZE];
|
| + wchar_t *buffer = stackBuffer;
|
|
|
| result = GetTimeFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, buffer, STACK_BUFFER_SIZE);
|
|
|
| @@ -271,12 +267,12 @@ void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo)
|
| if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
| int newLength = GetTimeFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, NULL, 0);
|
|
|
| - buffer = NEW_ARRAY(UChar, newLength);
|
| + buffer = NEW_ARRAY(wchar_t, newLength);
|
| GetDateFormatW(fLCID, tfFlags[fTimeStyle], st, NULL, buffer, newLength);
|
| }
|
| }
|
|
|
| - appendTo.append(buffer, (int32_t) wcslen(buffer));
|
| + appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
|
|
|
| if (buffer != stackBuffer) {
|
| DELETE_ARRAY(buffer);
|
|
|