Changed out string to nsString.

This commit is contained in:
nhotta%netscape.com 1999-02-01 23:40:02 +00:00
Родитель 57c01c80e1
Коммит 034a3ff9b8
7 изменённых файлов: 109 добавлений и 114 удалений

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsString.h"
#include <time.h>
// {2BBAA0B0-A591-11d2-9119-006008A6EDF6}
#define NS_IDATETIMEFORMAT_IID \
{ 0x2bbaa0b0, 0xa591, 0x11d2, \
@ -47,27 +48,25 @@ typedef enum {
} nsTimeFormatSelector;
// Locale sensitive date and time format interface
//
class nsIDateTimeFormat : public nsISupports {
public:
// performs a locale sensitive date formatting operation on the time_t parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen) = 0;
const time_t timetTime,
nsString& stringOut) = 0;
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen) = 0;
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsString& stringOut) = 0;
};
#endif /* nsIDateTimeFormat_h__ */

Просмотреть файл

@ -22,46 +22,27 @@ NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_IMPL_ISUPPORTS(nsDateTimeFormatMac, kIDateTimeFormatIID);
// performs a locale sensitive date formatting operation on the time_t parameter
nsresult nsDateTimeFormatMac::FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen)
nsString& stringOut)
{
// Temporary implementation, real implementation to be done by FE.
//
struct tm *today;
char *str;
today = localtime( &timetTime );
str = asctime(today);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
return NS_OK;
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, localtime(&timetTime), stringOut);
}
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
nsresult nsDateTimeFormatMac::FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen)
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsString& stringOut)
{
// Temporary implementation, real implementation to be done by FE.
//
char *str = asctime(tmTime);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
stringOut.SetString(asctime(tmTime));
return NS_OK;
}

Просмотреть файл

@ -29,22 +29,18 @@ public:
NS_DECL_ISUPPORTS
// performs a locale sensitive date formatting operation on the time_t parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen);
nsString& stringOut);
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen);
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsString& stringOut);
nsDateTimeFormatMac() {NS_INIT_REFCNT();};
};

Просмотреть файл

@ -26,42 +26,75 @@ nsresult nsDateTimeFormatUnix::FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen)
nsString& stringOut)
{
// Temporary implementation, real implementation to be done by FE.
//
struct tm *today;
char *str;
today = localtime( &timetTime );
str = asctime(today);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
return NS_OK;
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, localtime(&timetTime), stringOut);
}
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
nsresult nsDateTimeFormatUnix::FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen)
nsString& stringOut)
{
// Temporary implementation, real implementation to be done by FE.
//
#define NSDATETIME_FORMAT_BUFFER_LEN 80
char strOut[NSDATETIME_FORMAT_BUFFER_LEN];
char fmtD[32], fmtT[32];
char *str = asctime(tmTime);
nsString aString(str);
*outLen = aString.Length();
memcpy((void *) stringOut, (void *) aString.GetUnicode(), aString.Length() * sizeof(PRUnichar));
switch (dateFormatSelector) {
case kDateFormatNone:
strcpy(fmtD, "");
break;
case kDateFormatLong:
strcpy(fmtD, "%c");
break;
case kDateFormatShort:
strcpy(fmtD, "%x");
break;
case kDateFormatYearMonth:
strcpy(fmtD, "%y/%m");
break;
case kDateFormatWeekday:
strcpy(fmtD, "%a");
break;
default:
strcpy(fmtD, "");
}
switch (timeFormatSelector) {
case kTimeFormatNone:
strcpy(fmtT, "");
break;
case kTimeFormatSeconds:
strcpy(fmtT, "%I:%M:%S %p");
break;
case kTimeFormatNoSeconds:
strcpy(fmtT, "%I:%M %p");
break;
case kTimeFormatSecondsForce24Hour:
strcpy(fmtT, "%H:%M:%S");
break;
case kTimeFormatNoSecondsForce24Hour:
strcpy(fmtT, "%H:%M");
break;
default:
strcpy(fmtT, "");
}
if (strlen(fmtD) && strlen(fmtT)) {
strcat(fmtD, " ");
strcat(fmtD, fmtT);
strftime(strOut, NSDATETIME_FORMAT_BUFFER_LEN, fmtD, tmTime);
}
else if (strlen(fmtD) && !strlen(fmtT)) {
strftime(strOut, NSDATETIME_FORMAT_BUFFER_LEN, fmtD, tmTime);
}
else if (!strlen(fmtD) && strlen(fmtT)) {
strftime(strOut, NSDATETIME_FORMAT_BUFFER_LEN, fmtT, tmTime);
}
else {
strcpy(strOut, "");
}
stringOut.SetString(strOut);
return NS_OK;
}

Просмотреть файл

@ -29,22 +29,18 @@ public:
NS_DECL_ISUPPORTS
// performs a locale sensitive date formatting operation on the time_t parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen);
nsString& stringOut);
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen);
nsString& stringOut);
nsDateTimeFormatUnix() {NS_INIT_REFCNT();};
};

Просмотреть файл

@ -25,24 +25,23 @@ NS_DEFINE_IID(kIDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
NS_IMPL_ISUPPORTS(nsDateTimeFormatWin, kIDateTimeFormatIID);
// performs a locale sensitive date formatting operation on the time_t parameter
nsresult nsDateTimeFormatWin::FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen)
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
nsString& stringOut)
{
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, localtime( &timetTime ), stringOut, outLen);
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, localtime( &timetTime ), stringOut);
}
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
nsresult nsDateTimeFormatWin::FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen)
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsString& stringOut)
{
SYSTEMTIME system_time;
DWORD dwFlags_Date = 0, dwFlags_Time = 0;
@ -127,26 +126,19 @@ nsresult nsDateTimeFormatWin::FormatTMTime(const nsString& locale,
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (PRUint32) (dateLen + 1), "internal date buffer is not large enough");
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (PRUint32) (timeLen + 1), "internal time buffer is not large enough");
NS_ASSERTION(*outLen >= (PRUint32) (dateLen + timeLen + 1 + 1), "input buffer is not large enough");
// Copy the result
stringOut[0] = 0;
stringOut.SetString("");
if (dateLen != 0 && timeLen != 0) {
(void) wcscpy((wchar_t *) stringOut, (const wchar_t *) dateBuffer);
(void) wcscat((wchar_t *) stringOut, (const wchar_t *) L" ");
(void) wcscat((wchar_t *) stringOut, (const wchar_t *) timeBuffer);
*outLen = dateLen + timeLen + 1;
stringOut.SetString(dateBuffer, dateLen);
stringOut.Append((PRUnichar *)(L" "), 1);
stringOut.Append(timeBuffer, timeLen);
}
else if (timeLen == 0) {
(void) wcscpy((wchar_t *) stringOut, (const wchar_t *) dateBuffer);
*outLen = dateLen;
else if (dateLen != 0 && timeLen == 0) {
stringOut.SetString(dateBuffer, dateLen);
}
else if (dateLen == 0) {
(void) wcscpy((wchar_t *) stringOut, (const wchar_t *) timeBuffer);
*outLen = timeLen;
}
else {
*outLen = 0;
else if (dateLen == 0 && timeLen != 0) {
stringOut.SetString(timeBuffer, timeLen);
}
return NS_OK;

Просмотреть файл

@ -24,28 +24,26 @@
#include <windows.h>
// Locale sensitive date and time format interface
//
class nsDateTimeFormatWin : public nsIDateTimeFormat {
public:
NS_DECL_ISUPPORTS
// performs a locale sensitive date formatting operation on the time_t parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const time_t timetTime,
PRUnichar *stringOut,
PRUint32 *outLen);
nsString& stringOut);
// performs a locale sensitive date formatting operation on the struct tm parameter
// locale RFC1766 (e.g. "en-US"), caller should allocate the buffer, outLen is in/out
NS_IMETHOD FormatTMTime(const nsString& locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
PRUnichar *stringOut,
PRUint32 *outLen);
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsString& stringOut);
nsDateTimeFormatWin() {NS_INIT_REFCNT();};
};