1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
* Copyright (C) 1996-2001, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/udat.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/datefmt.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/fieldpos.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/parsepos.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/numfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/ustring.h"
|
2001-08-16 00:55:16 +00:00
|
|
|
/*
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDateFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_open( UDateFormatStyle timeStyle,
|
|
|
|
UDateFormatStyle dateStyle,
|
|
|
|
const char* locale,
|
|
|
|
const UChar *tzID,
|
|
|
|
int32_t tzIDLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
DateFormat *fmt;
|
|
|
|
if(locale == 0)
|
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle);
|
|
|
|
else
|
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle,
|
2000-04-15 21:23:28 +00:00
|
|
|
Locale(locale));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(fmt == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tzID != 0) {
|
|
|
|
TimeZone *zone = 0;
|
|
|
|
int32_t length = (tzIDLength == -1 ? u_strlen(tzID) : tzIDLength);
|
|
|
|
zone = TimeZone::createTimeZone(UnicodeString((UChar*)tzID,
|
|
|
|
length, length));
|
|
|
|
if(zone == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
delete fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fmt->adoptTimeZone(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UDateFormat*)fmt;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDateFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_openPattern( const UChar *pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
const char *locale,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
UDateFormat *retVal = 0;
|
|
|
|
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(UnicodeString((UChar*)pattern,
|
|
|
|
len, len),
|
|
|
|
*status);
|
|
|
|
else
|
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(UnicodeString((UChar*)pattern,
|
|
|
|
len, len),
|
2000-04-15 21:23:28 +00:00
|
|
|
Locale(locale),
|
1999-08-16 21:50:52 +00:00
|
|
|
*status);
|
|
|
|
|
|
|
|
if(retVal == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
2001-08-16 00:55:16 +00:00
|
|
|
*/
|
|
|
|
U_CAPI UDateFormat*
|
|
|
|
udat_open(UDateFormatStyle timeStyle,
|
|
|
|
UDateFormatStyle dateStyle,
|
|
|
|
const char *locale,
|
|
|
|
const UChar *tzID,
|
|
|
|
int32_t tzIDLength,
|
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(timeStyle != UDAT_IGNORE)
|
|
|
|
{
|
|
|
|
DateFormat *fmt;
|
|
|
|
if(locale == 0)
|
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle);
|
|
|
|
else
|
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle,
|
|
|
|
Locale(locale));
|
|
|
|
|
|
|
|
if(fmt == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tzID != 0) {
|
|
|
|
TimeZone *zone = 0;
|
|
|
|
int32_t length = (tzIDLength == -1 ? u_strlen(tzID) : tzIDLength);
|
|
|
|
zone = TimeZone::createTimeZone(UnicodeString((UChar*)tzID,
|
|
|
|
length, length));
|
|
|
|
if(zone == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
delete fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fmt->adoptTimeZone(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UDateFormat*)fmt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
UDateFormat *retVal = 0;
|
|
|
|
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(UnicodeString((UChar*)pattern,
|
|
|
|
len, len),
|
|
|
|
*status);
|
|
|
|
else
|
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(UnicodeString((UChar*)pattern,
|
|
|
|
len, len),
|
|
|
|
Locale(locale),
|
|
|
|
*status);
|
|
|
|
|
|
|
|
if(retVal == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_close(UDateFormat* format)
|
|
|
|
{
|
|
|
|
delete (DateFormat*)format;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDateFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_clone(const UDateFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
Format *res = ((SimpleDateFormat*)fmt)->clone();
|
|
|
|
|
|
|
|
if(res == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UDateFormat*) res;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_format( const UDateFormat* format,
|
|
|
|
UDate dateToFormat,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition* position,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString res(result, 0, resultLength);
|
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(position != 0)
|
|
|
|
fp.setField(position->field);
|
|
|
|
|
|
|
|
((DateFormat*)format)->format(dateToFormat, res, fp);
|
|
|
|
|
|
|
|
if(position != 0) {
|
|
|
|
position->beginIndex = fp.getBeginIndex();
|
|
|
|
position->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res, result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDate
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_parse( const UDateFormat* format,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate)0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
ParsePosition pp;
|
|
|
|
UDate res;
|
|
|
|
|
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
|
|
|
res = ((DateFormat*)format)->parse(src, pp);
|
|
|
|
|
|
|
|
if(parsePos != 0) {
|
|
|
|
if(pp.getErrorIndex() == -1)
|
|
|
|
*parsePos = pp.getIndex();
|
|
|
|
else {
|
|
|
|
*parsePos = pp.getErrorIndex();
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_PARSE_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_isLenient(const UDateFormat* fmt)
|
|
|
|
{
|
|
|
|
return ((DateFormat*)fmt)->isLenient();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setLenient( UDateFormat* fmt,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isLenient)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
((DateFormat*)fmt)->setLenient(isLenient);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UCalendar*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getCalendar(const UDateFormat* fmt)
|
|
|
|
{
|
|
|
|
return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setCalendar( UDateFormat* fmt,
|
|
|
|
const UCalendar* calendarToSet)
|
|
|
|
{
|
|
|
|
((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UNumberFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getNumberFormat(const UDateFormat* fmt)
|
|
|
|
{
|
|
|
|
return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setNumberFormat( UDateFormat* fmt,
|
|
|
|
const UNumberFormat* numberFormatToSet)
|
|
|
|
{
|
|
|
|
((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const char*
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UDate
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_get2DigitYearStart( const UDateFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate)0;
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((SimpleDateFormat*)fmt)->get2DigitYearStart(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_set2DigitYearStart( UDateFormat *fmt,
|
|
|
|
UDate d,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_toPattern( const UDateFormat *fmt,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool localized,
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString res(result, 0, resultLength);
|
|
|
|
|
|
|
|
if(localized)
|
|
|
|
((SimpleDateFormat*)fmt)->toLocalizedPattern(res, *status);
|
|
|
|
else
|
|
|
|
((SimpleDateFormat*)fmt)->toPattern(res);
|
|
|
|
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res, result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: should this take an UErrorCode?
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_applyPattern( UDateFormat *format,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool localized,
|
1999-08-16 21:50:52 +00:00
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength)
|
|
|
|
{
|
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
const UnicodeString pat((UChar*)pattern, len, len);
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(localized)
|
|
|
|
((SimpleDateFormat*)format)->applyLocalizedPattern(pat, status);
|
|
|
|
else
|
|
|
|
((SimpleDateFormat*)format)->applyPattern(pat);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getSymbols(const UDateFormat *fmt,
|
|
|
|
UDateFormatSymbolType type,
|
|
|
|
int32_t index,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
const DateFormatSymbols *syms =
|
|
|
|
((SimpleDateFormat*)fmt)->getDateFormatSymbols();
|
|
|
|
int32_t count;
|
|
|
|
const UnicodeString *res;
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
res = syms->getEras(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
|
|
|
res = syms->getMonths(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
res = syms->getShortMonths(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
res = syms->getShortWeekdays(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
|
|
|
res = syms->getAmPmStrings(count);
|
|
|
|
if(index < count) {
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(res[index], result, resultLength, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
2001-03-17 23:36:26 +00:00
|
|
|
{
|
|
|
|
UnicodeString res1(result, 0, resultLength);
|
|
|
|
syms->getLocalPatternChars(res1);
|
|
|
|
return uprv_fillOutputString(res1, result, resultLength, status);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-17 23:36:26 +00:00
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countSymbols( const UDateFormat *fmt,
|
|
|
|
UDateFormatSymbolType type)
|
|
|
|
{
|
|
|
|
const DateFormatSymbols *syms =
|
|
|
|
((SimpleDateFormat*)fmt)->getDateFormatSymbols();
|
2000-08-15 18:25:20 +00:00
|
|
|
int32_t count = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
syms->getEras(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
|
|
|
syms->getMonths(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
syms->getShortMonths(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
syms->getShortWeekdays(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
|
|
|
syms->getAmPmStrings(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
|
|
|
count = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setSymbols( UDateFormat *format,
|
|
|
|
UDateFormatSymbolType type,
|
|
|
|
int32_t index,
|
|
|
|
UChar *value,
|
|
|
|
int32_t valueLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t count;
|
|
|
|
int32_t len = (valueLength == -1 ? u_strlen(value) : valueLength);
|
|
|
|
const UnicodeString val((UChar*)value, len, len);
|
|
|
|
const UnicodeString *res;
|
|
|
|
DateFormatSymbols *syms = new DateFormatSymbols(
|
|
|
|
* ((SimpleDateFormat*)format)->getDateFormatSymbols() );
|
|
|
|
UnicodeString *array = 0;
|
|
|
|
|
|
|
|
if(syms == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
res = syms->getEras(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setEras(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
|
|
|
res = syms->getMonths(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setMonths(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
res = syms->getShortMonths(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setShortMonths(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setWeekdays(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
res = syms->getShortWeekdays(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setShortWeekdays(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
|
|
|
res = syms->getAmPmStrings(count);
|
|
|
|
array = new UnicodeString[count];
|
|
|
|
if(array == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(res, array, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
if(index < count)
|
|
|
|
array[index] = val;
|
|
|
|
syms->setAmPmStrings(array, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
|
|
|
syms->setLocalPatternChars(val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
((SimpleDateFormat*)format)->adoptDateFormatSymbols(syms);
|
|
|
|
delete [] array;
|
|
|
|
}
|
2001-08-16 00:55:16 +00:00
|
|
|
|
|
|
|
|