1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2003-12-19 21:29:27 +00:00
|
|
|
* Copyright (C) 1996-2003, 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
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
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"
|
|
|
|
#include "unicode/parsepos.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/numfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/ustring.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "cpputils.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDateFormat* U_EXPORT2
|
2001-08-16 00:55:16 +00:00
|
|
|
udat_open(UDateFormatStyle timeStyle,
|
|
|
|
UDateFormatStyle dateStyle,
|
|
|
|
const char *locale,
|
2002-04-02 02:55:31 +00:00
|
|
|
const UChar *tzID,
|
|
|
|
int32_t tzIDLength,
|
2001-08-16 00:55:16 +00:00
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
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) {
|
2002-11-16 01:14:40 +00:00
|
|
|
TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
|
2001-08-16 00:55:16 +00:00
|
|
|
if(zone == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
delete fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fmt->adoptTimeZone(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UDateFormat*)fmt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-11-16 01:14:40 +00:00
|
|
|
const UnicodeString pat = UnicodeString((UBool)(patternLength == -1), pattern, patternLength);
|
2001-08-16 00:55:16 +00:00
|
|
|
UDateFormat *retVal = 0;
|
|
|
|
|
|
|
|
if(locale == 0)
|
2002-11-16 01:14:40 +00:00
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(pat, *status);
|
2001-08-16 00:55:16 +00:00
|
|
|
else
|
2002-11-16 01:14:40 +00:00
|
|
|
retVal = (UDateFormat*)new SimpleDateFormat(pat, Locale(locale), *status);
|
2001-08-16 00:55:16 +00:00
|
|
|
|
|
|
|
if(retVal == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_close(UDateFormat* format)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
delete (DateFormat*)format;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDateFormat* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_clone(const UDateFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_format( const UDateFormat* format,
|
|
|
|
UDate dateToFormat,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition* position,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
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-09-05 23:39:38 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_parse( const UDateFormat* format,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate)0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
const UnicodeString src((UBool)(textLength == -1), text, textLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-03-06 20:41:57 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udat_parseCalendar(const UDateFormat* format,
|
|
|
|
UCalendar* calendar,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
const UnicodeString src((UBool)(textLength == -1), text, textLength);
|
2002-03-06 20:41:57 +00:00
|
|
|
ParsePosition pp;
|
|
|
|
|
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
|
|
|
((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
|
|
|
|
|
|
|
|
if(parsePos != 0) {
|
|
|
|
if(pp.getErrorIndex() == -1)
|
|
|
|
*parsePos = pp.getIndex();
|
|
|
|
else {
|
|
|
|
*parsePos = pp.getErrorIndex();
|
|
|
|
*status = U_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_isLenient(const UDateFormat* fmt)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((DateFormat*)fmt)->isLenient();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
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
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
((DateFormat*)fmt)->setLenient(isLenient);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const UCalendar* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getCalendar(const UDateFormat* fmt)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setCalendar( UDateFormat* fmt,
|
|
|
|
const UCalendar* calendarToSet)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const UNumberFormat* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getNumberFormat(const UDateFormat* fmt)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setNumberFormat( UDateFormat* fmt,
|
|
|
|
const UNumberFormat* numberFormatToSet)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countAvailable()
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_get2DigitYearStart( const UDateFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_set2DigitYearStart( UDateFormat *fmt,
|
|
|
|
UDate d,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
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)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(localized)
|
|
|
|
((SimpleDateFormat*)fmt)->toLocalizedPattern(res, *status);
|
|
|
|
else
|
|
|
|
((SimpleDateFormat*)fmt)->toPattern(res);
|
|
|
|
|
2001-09-05 23:39:38 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TBD: should this take an UErrorCode?
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
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)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
|
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);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
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)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
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-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
|
|
|
res = syms->getMonths(count);
|
|
|
|
if(index < count) {
|
2001-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
res = syms->getShortMonths(count);
|
|
|
|
if(index < count) {
|
2001-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count);
|
|
|
|
if(index < count) {
|
2001-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
res = syms->getShortWeekdays(count);
|
|
|
|
if(index < count) {
|
2001-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
|
|
|
res = syms->getAmPmStrings(count);
|
|
|
|
if(index < count) {
|
2001-09-05 23:39:38 +00:00
|
|
|
return res[index].extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
2001-03-17 23:36:26 +00:00
|
|
|
{
|
2002-11-16 01:14:40 +00:00
|
|
|
UnicodeString res1;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res1.setTo(result, 0, resultLength);
|
|
|
|
}
|
2001-03-17 23:36:26 +00:00
|
|
|
syms->getLocalPatternChars(res1);
|
2001-09-05 23:39:38 +00:00
|
|
|
return res1.extract(result, resultLength, *status);
|
2001-03-17 23:36:26 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countSymbols( const UDateFormat *fmt,
|
|
|
|
UDateFormatSymbolType type)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
|
|
|
|
* solely for the purpose of avoiding to clone the array of strings
|
|
|
|
* just to modify one of them and then setting all of them back.
|
|
|
|
* For example, the old code looked like this:
|
|
|
|
* case UDAT_MONTHS:
|
|
|
|
* res = syms->getMonths(count);
|
|
|
|
* array = new UnicodeString[count];
|
|
|
|
* if(array == 0) {
|
|
|
|
* *status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
* uprv_arrayCopy(res, array, count);
|
|
|
|
* if(index < count)
|
|
|
|
* array[index] = val;
|
|
|
|
* syms->setMonths(array, count);
|
|
|
|
* break;
|
|
|
|
*
|
|
|
|
* Even worse, the old code actually cloned the entire DateFormatSymbols object,
|
|
|
|
* cloned one value array, changed one value, and then made the SimpleDateFormat
|
|
|
|
* replace its DateFormatSymbols object with the new one.
|
|
|
|
*
|
|
|
|
* markus 2002-oct-14
|
|
|
|
*/
|
|
|
|
class DateFormatSymbolsSingleSetter /* not : public UObject because all methods are static */ {
|
|
|
|
public:
|
|
|
|
static void
|
|
|
|
setSymbol(UnicodeString *array, int32_t count, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
if(array!=NULL) {
|
|
|
|
if(index>=count) {
|
|
|
|
errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
} else if(value==NULL) {
|
|
|
|
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
} else {
|
|
|
|
array[index].setTo(value, valueLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setEra(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fEras, syms->fErasCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fMonths, syms->fMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setShortMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fShortMonths, syms->fShortMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fWeekdays, syms->fWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setShortWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fShortWeekdays, syms->fShortWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setAmPm(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(syms->fAmPms, syms->fAmPmsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setLocalPatternChars(DateFormatSymbols *syms,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode) {
|
|
|
|
setSymbol(&syms->fLocalPatternChars, 1, 0, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-10-19 00:39:17 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setSymbols( UDateFormat *format,
|
|
|
|
UDateFormatSymbolType type,
|
|
|
|
int32_t index,
|
|
|
|
UChar *value,
|
|
|
|
int32_t valueLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setEra(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setMonth(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setShortMonth(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setWeekday(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setShortWeekday(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setAmPm(syms, index, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
2002-10-15 00:36:11 +00:00
|
|
|
DateFormatSymbolsSingleSetter::setLocalPatternChars(syms, value, valueLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-16 00:55:16 +00:00
|
|
|
|
2003-11-14 21:58:52 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
udat_getLocaleByType(const UDateFormat *fmt,
|
|
|
|
ULocDataLocaleType type,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
if (fmt == NULL) {
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((Format*)fmt)->getLocaleID(type, *status);
|
2003-11-14 21:58:52 +00:00
|
|
|
}
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|