| Index: source/i18n/udat.cpp
|
| diff --git a/source/i18n/udat.cpp b/source/i18n/udat.cpp
|
| index 116eb9b0beac5bf6c67b74a0d43bfc795b94a1f1..ef82796a86ced907f39d72f4155a1ac5ed3fe443 100644
|
| --- a/source/i18n/udat.cpp
|
| +++ b/source/i18n/udat.cpp
|
| @@ -1,6 +1,6 @@
|
| /*
|
| *******************************************************************************
|
| -* Copyright (C) 1996-2014, International Business Machines
|
| +* Copyright (C) 1996-2015, International Business Machines
|
| * Corporation and others. All Rights Reserved.
|
| *******************************************************************************
|
| */
|
| @@ -22,6 +22,7 @@
|
| #include "unicode/dtfmtsym.h"
|
| #include "unicode/ustring.h"
|
| #include "unicode/udisplaycontext.h"
|
| +#include "unicode/ufieldpositer.h"
|
| #include "cpputils.h"
|
| #include "reldtfmt.h"
|
| #include "umutex.h"
|
| @@ -213,10 +214,16 @@ udat_format( const UDateFormat* format,
|
| UFieldPosition* position,
|
| UErrorCode* status)
|
| {
|
| - if(U_FAILURE(*status)) return -1;
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
|
|
| UnicodeString res;
|
| - if(!(result==NULL && resultLength==0)) {
|
| + if (result != NULL) {
|
| // NULL destination for pure preflighting: empty dummy string
|
| // otherwise, alias the destination buffer
|
| res.setTo(result, 0, resultLength);
|
| @@ -237,6 +244,100 @@ udat_format( const UDateFormat* format,
|
| return res.extract(result, resultLength, *status);
|
| }
|
|
|
| +U_CAPI int32_t U_EXPORT2
|
| +udat_formatCalendar(const UDateFormat* format,
|
| + UCalendar* calendar,
|
| + UChar* result,
|
| + int32_t resultLength,
|
| + UFieldPosition* position,
|
| + UErrorCode* status)
|
| +{
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
| +
|
| + UnicodeString res;
|
| + if (result != NULL) {
|
| + // NULL destination for pure preflighting: empty dummy string
|
| + // otherwise, alias the destination buffer
|
| + res.setTo(result, 0, resultLength);
|
| + }
|
| +
|
| + FieldPosition fp;
|
| +
|
| + if(position != 0)
|
| + fp.setField(position->field);
|
| +
|
| + ((DateFormat*)format)->format(*(Calendar*)calendar, res, fp);
|
| +
|
| + if(position != 0) {
|
| + position->beginIndex = fp.getBeginIndex();
|
| + position->endIndex = fp.getEndIndex();
|
| + }
|
| +
|
| + return res.extract(result, resultLength, *status);
|
| +}
|
| +
|
| +U_CAPI int32_t U_EXPORT2
|
| +udat_formatForFields( const UDateFormat* format,
|
| + UDate dateToFormat,
|
| + UChar* result,
|
| + int32_t resultLength,
|
| + UFieldPositionIterator* fpositer,
|
| + UErrorCode* status)
|
| +{
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
| +
|
| + UnicodeString res;
|
| + if (result != NULL) {
|
| + // NULL destination for pure preflighting: empty dummy string
|
| + // otherwise, alias the destination buffer
|
| + res.setTo(result, 0, resultLength);
|
| + }
|
| +
|
| + ((DateFormat*)format)->format(dateToFormat, res, (FieldPositionIterator*)fpositer, *status);
|
| +
|
| + return res.extract(result, resultLength, *status);
|
| +}
|
| +
|
| +U_CAPI int32_t U_EXPORT2
|
| +udat_formatCalendarForFields(const UDateFormat* format,
|
| + UCalendar* calendar,
|
| + UChar* result,
|
| + int32_t resultLength,
|
| + UFieldPositionIterator* fpositer,
|
| + UErrorCode* status)
|
| +{
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
| +
|
| + UnicodeString res;
|
| + if (result != NULL) {
|
| + // NULL destination for pure preflighting: empty dummy string
|
| + // otherwise, alias the destination buffer
|
| + res.setTo(result, 0, resultLength);
|
| + }
|
| +
|
| + ((DateFormat*)format)->format(*(Calendar*)calendar, res, (FieldPositionIterator*)fpositer, *status);
|
| +
|
| + return res.extract(result, resultLength, *status);
|
| +}
|
| +
|
| U_CAPI UDate U_EXPORT2
|
| udat_parse( const UDateFormat* format,
|
| const UChar* text,
|
| @@ -281,19 +382,21 @@ udat_parseCalendar(const UDateFormat* format,
|
|
|
| const UnicodeString src((UBool)(textLength == -1), text, textLength);
|
| ParsePosition pp;
|
| + int32_t stackParsePos = 0;
|
|
|
| - if(parsePos != 0)
|
| - pp.setIndex(*parsePos);
|
| + if(parsePos == NULL) {
|
| + parsePos = &stackParsePos;
|
| + }
|
| +
|
| + 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;
|
| - }
|
| + if(pp.getErrorIndex() == -1)
|
| + *parsePos = pp.getIndex();
|
| + else {
|
| + *parsePos = pp.getErrorIndex();
|
| + *status = U_PARSE_ERROR;
|
| }
|
| }
|
|
|
| @@ -425,10 +528,16 @@ udat_toPattern( const UDateFormat *fmt,
|
| int32_t resultLength,
|
| UErrorCode *status)
|
| {
|
| - if(U_FAILURE(*status)) return -1;
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
|
|
| UnicodeString res;
|
| - if(!(result==NULL && resultLength==0)) {
|
| + if (result != NULL) {
|
| // NULL destination for pure preflighting: empty dummy string
|
| // otherwise, alias the destination buffer
|
| res.setTo(result, 0, resultLength);
|
| @@ -1144,10 +1253,16 @@ udat_toPatternRelativeDate(const UDateFormat *fmt,
|
| UErrorCode *status)
|
| {
|
| verifyIsRelativeDateFormat(fmt, status);
|
| - if(U_FAILURE(*status)) return -1;
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
|
|
| UnicodeString datePattern;
|
| - if(!(result==NULL && resultLength==0)) {
|
| + if (result != NULL) {
|
| // NULL destination for pure preflighting: empty dummy string
|
| // otherwise, alias the destination buffer
|
| datePattern.setTo(result, 0, resultLength);
|
| @@ -1163,10 +1278,16 @@ udat_toPatternRelativeTime(const UDateFormat *fmt,
|
| UErrorCode *status)
|
| {
|
| verifyIsRelativeDateFormat(fmt, status);
|
| - if(U_FAILURE(*status)) return -1;
|
| + if(U_FAILURE(*status)) {
|
| + return -1;
|
| + }
|
| + if (result == NULL ? resultLength != 0 : resultLength < 0) {
|
| + *status = U_ILLEGAL_ARGUMENT_ERROR;
|
| + return -1;
|
| + }
|
|
|
| UnicodeString timePattern;
|
| - if(!(result==NULL && resultLength==0)) {
|
| + if (result != NULL) {
|
| // NULL destination for pure preflighting: empty dummy string
|
| // otherwise, alias the destination buffer
|
| timePattern.setTo(result, 0, resultLength);
|
|
|