ICU-2370 fix parameter docs/names for format() and related fns

X-SVN-Rev: 10366
This commit is contained in:
Alan Liu 2002-11-25 18:31:23 +00:00
parent f194e6800b
commit 8a4c069318
4 changed files with 124 additions and 118 deletions

View File

@ -92,61 +92,61 @@ DateFormat::operator==(const Format& other) const
UnicodeString&
DateFormat::format(const Formattable& obj,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& fieldPosition,
UErrorCode& status) const
{
if (U_FAILURE(status)) return toAppendTo;
if (U_FAILURE(status)) return appendTo;
// if the type of the Formattable is double or long, treat it as if it were a Date
UDate date = 0;
switch (obj.getType())
{
case Formattable::kDate:
format(obj.getDate(), toAppendTo, fieldPosition);
date = obj.getDate();
break;
case Formattable::kDouble:
format((UDate)obj.getDouble(), toAppendTo, fieldPosition);
date = (UDate)obj.getDouble();
break;
case Formattable::kLong:
format((UDate)obj.getLong(), toAppendTo, fieldPosition);
date = (UDate)obj.getLong();
break;
default:
status = U_ILLEGAL_ARGUMENT_ERROR;
return toAppendTo;
return appendTo;
}
// Is this right?
//if (fieldPosition.getBeginIndex() == fieldPosition.getEndIndex())
// status = U_ILLEGAL_ARGUMENT_ERROR;
return toAppendTo;
return format(date, appendTo, fieldPosition);
}
//----------------------------------------------------------------------
UnicodeString&
DateFormat::format(UDate date, UnicodeString& result, FieldPosition& fieldPosition) const {
DateFormat::format(UDate date, UnicodeString& appendTo, FieldPosition& fieldPosition) const {
if (fCalendar != NULL) {
// Use our calendar instance
UErrorCode ec = U_ZERO_ERROR;
fCalendar->setTime(date, ec);
if (U_SUCCESS(ec)) {
return format(*fCalendar, result, fieldPosition);
return format(*fCalendar, appendTo, fieldPosition);
}
}
return result;
return appendTo;
}
//----------------------------------------------------------------------
UnicodeString&
DateFormat::format(UDate date, UnicodeString& result) const
DateFormat::format(UDate date, UnicodeString& appendTo) const
{
// Note that any error information is just lost. That's okay
// for this convenience method.
FieldPosition fpos(0);
format(date, result, fpos);
return result;
return format(date, appendTo, fpos);
}
//----------------------------------------------------------------------

View File

@ -403,7 +403,7 @@ void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& s
//----------------------------------------------------------------------
UnicodeString&
SimpleDateFormat::format(Calendar& cal, UnicodeString& toAppendTo, FieldPosition& pos) const
SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo, FieldPosition& pos) const
{
UErrorCode status = U_ZERO_ERROR;
pos.setBeginIndex(0);
@ -420,14 +420,14 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& toAppendTo, FieldPosition
// Use subFormat() to format a repeated pattern character
// when a different pattern or non-pattern character is seen
if (ch != prevCh && count > 0) {
subFormat(toAppendTo, prevCh, count, pos, cal, status);
subFormat(appendTo, prevCh, count, pos, cal, status);
count = 0;
}
if (ch == 0x0027 /*'\''*/) {
// Consecutive single quotes are a single quote literal,
// either outside of quotes or between quotes
if ((i+1) < fPattern.length() && fPattern[i+1] == 0x0027 /*'\''*/) {
toAppendTo += (UChar)0x0027 /*'\''*/;
appendTo += (UChar)0x0027 /*'\''*/;
++i;
} else {
inQuote = ! inQuote;
@ -442,13 +442,13 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& toAppendTo, FieldPosition
}
else {
// Append quoted characters and unquoted non-pattern characters
toAppendTo += ch;
appendTo += ch;
}
}
// Format the last item in the pattern, if any
if (count > 0) {
subFormat(toAppendTo, prevCh, count, pos, cal, status);
subFormat(appendTo, prevCh, count, pos, cal, status);
}
// and if something failed (e.g., an invalid format character), reset our FieldPosition
@ -459,12 +459,12 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& toAppendTo, FieldPosition
pos.setEndIndex(0);
}
return toAppendTo;
return appendTo;
}
UnicodeString&
SimpleDateFormat::format(const Formattable& obj,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const
{
@ -472,7 +472,7 @@ SimpleDateFormat::format(const Formattable& obj,
// (the previous format() override would hide the version of
// format() on DateFormat that this function correspond to, so we
// have to redefine it here)
return DateFormat::format(obj, toAppendTo, pos, status);
return DateFormat::format(obj, appendTo, pos, status);
}
//----------------------------------------------------------------------
@ -509,7 +509,7 @@ SimpleDateFormat::fgPatternIndexToDateFormatField[] = {
//----------------------------------------------------------------------
void
SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
SimpleDateFormat::subFormat(UnicodeString &appendTo,
UChar ch,
int32_t count,
FieldPosition& pos,
@ -522,7 +522,7 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
UChar *patternCharPtr = u_strchr(DateFormatSymbols::getPatternUChars(), ch);
EField patternCharIndex;
const int32_t maxIntCount = 10;
int32_t beginOffset = toAppendTo.length();
int32_t beginOffset = appendTo.length();
// if the pattern character is unrecognized, signal an error and dump out
if (patternCharPtr == NULL)
@ -541,16 +541,16 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
// for any "G" symbol, write out the appropriate era string
case kEraField:
toAppendTo += fSymbols->fEras[value];
appendTo += fSymbols->fEras[value];
break;
// for "yyyy", write out the whole year; for "yy", write out the last 2 digits
case kYearField:
case kYearWOYField:
if (count >= 4)
zeroPaddingNumber(toAppendTo, value, 4, maxIntCount);
zeroPaddingNumber(appendTo, value, 4, maxIntCount);
else
zeroPaddingNumber(toAppendTo, value, 2, 2);
zeroPaddingNumber(appendTo, value, 2, 2);
break;
// for "MMMM", write out the whole month name, for "MMM", write out the month
@ -558,19 +558,19 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
// appropriate number of digits
case kMonthField:
if (count >= 4)
toAppendTo += fSymbols->fMonths[value];
appendTo += fSymbols->fMonths[value];
else if (count == 3)
toAppendTo += fSymbols->fShortMonths[value];
appendTo += fSymbols->fShortMonths[value];
else
zeroPaddingNumber(toAppendTo, value + 1, count, maxIntCount);
zeroPaddingNumber(appendTo, value + 1, count, maxIntCount);
break;
// for "k" and "kk", write out the hour, adjusting midnight to appear as "24"
case kHourOfDay1Field:
if (value == 0)
zeroPaddingNumber(toAppendTo, cal.getMaximum(Calendar::HOUR_OF_DAY) + 1, count, maxIntCount);
zeroPaddingNumber(appendTo, cal.getMaximum(Calendar::HOUR_OF_DAY) + 1, count, maxIntCount);
else
zeroPaddingNumber(toAppendTo, value, count, maxIntCount);
zeroPaddingNumber(appendTo, value, count, maxIntCount);
break;
// for "SS" and "S", we want to truncate digits so that you still see the MOST
@ -582,29 +582,29 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
value = value / 10;
else if (count == 1)
value = value / 100;
zeroPaddingNumber(toAppendTo, value, count, maxIntCount);
zeroPaddingNumber(appendTo, value, count, maxIntCount);
break;
// for "EEEE", write out the day-of-the-week name; otherwise, use the abbreviation
case kDayOfWeekField:
if (count >= 4)
toAppendTo += fSymbols->fWeekdays[value];
appendTo += fSymbols->fWeekdays[value];
else
toAppendTo += fSymbols->fShortWeekdays[value];
appendTo += fSymbols->fShortWeekdays[value];
break;
// for and "a" symbol, write out the whole AM/PM string
case kAmPmField:
toAppendTo += fSymbols->fAmPms[value];
appendTo += fSymbols->fAmPms[value];
break;
// for "h" and "hh", write out the hour, adjusting noon and midnight to show up
// as "12"
case kHour1Field:
if (value == 0)
zeroPaddingNumber(toAppendTo, cal.getLeastMaximum(Calendar::HOUR) + 1, count, maxIntCount);
zeroPaddingNumber(appendTo, cal.getLeastMaximum(Calendar::HOUR) + 1, count, maxIntCount);
else
zeroPaddingNumber(toAppendTo, value, count, maxIntCount);
zeroPaddingNumber(appendTo, value, count, maxIntCount);
break;
// for the "z" symbols, we have to check our time zone data first. If we have a
@ -621,27 +621,27 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
cal.get(Calendar::DST_OFFSET, status);
if (value < 0) {
toAppendTo += fgGmtMinus;
appendTo += fgGmtMinus;
value = -value; // suppress the '-' sign for text display.
}
else
toAppendTo += fgGmtPlus;
appendTo += fgGmtPlus;
zeroPaddingNumber(toAppendTo, (int32_t)(value/U_MILLIS_PER_HOUR), 2, 2);
toAppendTo += (UChar)0x003A /*':'*/;
zeroPaddingNumber(toAppendTo, (int32_t)((value%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), 2, 2);
zeroPaddingNumber(appendTo, (int32_t)(value/U_MILLIS_PER_HOUR), 2, 2);
appendTo += (UChar)0x003A /*':'*/;
zeroPaddingNumber(appendTo, (int32_t)((value%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE), 2, 2);
}
else if (cal.get(Calendar::DST_OFFSET, status) != 0) {
if (count >= 4)
toAppendTo += fSymbols->fZoneStrings[zoneIndex][3];
appendTo += fSymbols->fZoneStrings[zoneIndex][3];
else
toAppendTo += fSymbols->fZoneStrings[zoneIndex][4];
appendTo += fSymbols->fZoneStrings[zoneIndex][4];
}
else {
if (count >= 4)
toAppendTo += fSymbols->fZoneStrings[zoneIndex][1];
appendTo += fSymbols->fZoneStrings[zoneIndex][1];
else
toAppendTo += fSymbols->fZoneStrings[zoneIndex][2];
appendTo += fSymbols->fZoneStrings[zoneIndex][2];
}
}
break;
@ -659,7 +659,7 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
// case kWeekOfMonthField:
// case kHour0Field:
// case kDOWLocalField:
zeroPaddingNumber(toAppendTo, value, count, maxIntCount);
zeroPaddingNumber(appendTo, value, count, maxIntCount);
break;
}
@ -668,7 +668,7 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
if (pos.getField() == fgPatternIndexToDateFormatField[patternCharIndex]) {
if (pos.getBeginIndex() == 0 && pos.getEndIndex() == 0) {
pos.setBeginIndex(beginOffset);
pos.setEndIndex(toAppendTo.length());
pos.setEndIndex(appendTo.length());
}
}
}
@ -676,13 +676,13 @@ SimpleDateFormat::subFormat(UnicodeString &toAppendTo,
//----------------------------------------------------------------------
void
SimpleDateFormat::zeroPaddingNumber(UnicodeString &toAppendTo, int32_t value, int32_t minDigits, int32_t maxDigits) const
SimpleDateFormat::zeroPaddingNumber(UnicodeString &appendTo, int32_t value, int32_t minDigits, int32_t maxDigits) const
{
FieldPosition pos(0);
fNumberFormat->setMinimumIntegerDigits(minDigits);
fNumberFormat->setMaximumIntegerDigits(maxDigits);
fNumberFormat->format(value, toAppendTo, pos); // 3rd arg is there to speed up processing
fNumberFormat->format(value, appendTo, pos); // 3rd arg is there to speed up processing
}
//----------------------------------------------------------------------

View File

@ -252,18 +252,17 @@ public:
* objects with a UDate type. If a the Formattable object type is not a Date,
* then it returns a failing UErrorCode.
*
* @param obj The object to format. Must be a Date.
* @param toAppendTo The result of the formatting operation is appended to
* this string.
* @param pos On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* @param status Output param filled with success/failure status.
* @return The value passed in as toAppendTo (this allows chaining,
* as with UnicodeString::append())
* @param obj The object to format. Must be a Date.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param pos On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @stable
*/
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
@ -287,17 +286,17 @@ public:
* fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
* occurence of the timezone pattern character 'z'.
*
* @param cal a Calendar set to the date and time to be formatted
* @param cal Calendar set to the date and time to be formatted
* into a date/time string.
* @param toAppendTo the result of the formatting operation is appended to
* the end of this string.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired (see examples above)
* On output: the offsets of the alignment field (see examples above)
* @return A reference to 'toAppendTo'.
* @return Reference to 'appendTo' parameter.
* @draft ICU 2.1
*/
virtual UnicodeString& format( Calendar& cal,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& fieldPosition) const = 0;
/**
@ -319,16 +318,16 @@ public:
* fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
* occurence of the timezone pattern character 'z'.
*
* @param date a UDate to be formatted into a date/time string.
* @param toAppendTo the result of the formatting operation is appended to
* the end of this string.
* @param date UDate to be formatted into a date/time string.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired (see examples above)
* On output: the offsets of the alignment field (see examples above)
* @return A reference to 'toAppendTo'.
* @return Reference to 'appendTo' parameter.
* @stable
*/
UnicodeString& format( UDate date,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& fieldPosition) const;
/**
@ -337,23 +336,25 @@ public:
* FieldPosition& to detect formatting problems.
*
* @param date The UDate value to be formatted into a string.
* @param result Output param which will receive the formatted date.
* @return A reference to 'result'.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @return Reference to 'appendTo' parameter.
* @stable
*/
UnicodeString& format(UDate date, UnicodeString& result) const;
UnicodeString& format(UDate date, UnicodeString& appendTo) const;
/**
* Redeclared Format method.
*
* @param obj The object to be formatted into a string.
* @param result Output param which will receive the formatted date.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param status Output param filled with success/failure status.
* @return A reference to 'result'.
* @return Reference to 'appendTo' parameter.
* @stable
*/
UnicodeString& format(const Formattable& obj,
UnicodeString& result,
UnicodeString& appendTo,
UErrorCode& status) const;
/**
@ -646,9 +647,9 @@ private:
inline UnicodeString&
DateFormat::format(const Formattable& obj,
UnicodeString& result,
UnicodeString& appendTo,
UErrorCode& status) const {
return Format::format(obj, result, status);
return Format::format(obj, appendTo, status);
}
U_NAMESPACE_END

View File

@ -286,17 +286,17 @@ public:
* Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
* 1996.07.10 AD at 15:08:56 PDT
*
* @param cal a Calendar set to the date and time to be formatted
* into a date/time string.
* @param toAppendTo The result of the formatting operation is appended to this
* string.
* @param pos The formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @return A reference to 'toAppendTo'.
* @param cal Calendar set to the date and time to be formatted
* into a date/time string.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param pos The formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @return Reference to 'appendTo' parameter.
* @draft ICU 2.1
*/
virtual UnicodeString& format( Calendar& cal,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& pos) const;
/**
@ -306,56 +306,59 @@ public:
* Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
* 1996.07.10 AD at 15:08:56 PDT
*
* @param obj A Formattable containing the date-time value to be formatted
* into a date-time string. If the type of the Formattable
* is a numeric type, it is treated as if it were an
* instance of Date.
* @param toAppendTo The result of the formatting operation is appended to this
* string.
* @param pos The formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @param status Output param set to success/faulure code.
* @return A reference to 'toAppendTo'.
* @param obj A Formattable containing the date-time value to be formatted
* into a date-time string. If the type of the Formattable
* is a numeric type, it is treated as if it were an
* instance of Date.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param pos The formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @param status Output param set to success/faulure code.
* @return Reference to 'appendTo' parameter.
* @stable
*/
virtual UnicodeString& format( const Formattable& obj,
UnicodeString& toAppendTo,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
/**
* Redeclared DateFormat method.
* @param date the Date value to be formatted.
* @param result Output param to receive the formatted string.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param fieldPosition The formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @return A reference to 'result'.
* @return Reference to 'appendTo' parameter.
* @draft ICU 2.1
*/
UnicodeString& format(UDate date,
UnicodeString& result,
UnicodeString& appendTo,
FieldPosition& fieldPosition) const;
/**
* Redeclared DateFormat method.
* @param obj the object to be formatted.
* @param result Output param to receive the formatted string.
* @param status Output param set to success/faulure code.
* @return A reference to 'toAppendTo'.
* @param obj Object to be formatted.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param status Input/output success/failure code.
* @return Reference to 'appendTo' parameter.
* @stable
*/
UnicodeString& format(const Formattable& obj,
UnicodeString& result,
UnicodeString& appendTo,
UErrorCode& status) const;
/**
* Redeclared DateFormat method.
* @param date the Date value to be formatted.
* @param result Output param to receive the formatted string.
* @return A reference to 'result'.
* @param date Date value to be formatted.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @return Reference to 'appendTo' parameter.
* @stable
*/
UnicodeString& format(UDate date, UnicodeString& result) const;
UnicodeString& format(UDate date, UnicodeString& appendTo) const;
/**
* Parse a date/time string beginning at the given parse position. For
@ -605,7 +608,8 @@ private:
/**
* Called by format() to format a single field.
*
* @param toAppendTo A string which gets the result appended to it.
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param ch The format character we encountered in the pattern.
* @param count Number of characters in the current pattern symbol (e.g.,
* "yyyy" in the pattern would result in a call to this function
@ -617,7 +621,7 @@ private:
* @param status Receives a status code, which will be U_ZERO_ERROR if the operation
* succeeds.
*/
void subFormat( UnicodeString &toAppendTo,
void subFormat( UnicodeString &appendTo,
UChar ch,
int32_t count,
FieldPosition& pos,
@ -630,12 +634,13 @@ private:
* having a number of digits between "minDigits" and
* "maxDigits". Uses the DateFormat's NumberFormat.
*
* @param toAppendTo A string which gets the formatted number appended to it.
* @param appendTo Output parameter to receive result.
* Formatted number is appended to existing contents.
* @param value Value to format.
* @param minDigits Minimum number of digits the result should have
* @param maxDigits Maximum number of digits the result should have
*/
void zeroPaddingNumber( UnicodeString &toAppendTo,
void zeroPaddingNumber( UnicodeString &appendTo,
int32_t value,
int32_t minDigits,
int32_t maxDigits) const;
@ -833,25 +838,25 @@ SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
inline UnicodeString&
SimpleDateFormat::format(const Formattable& obj,
UnicodeString& result,
UnicodeString& appendTo,
UErrorCode& status) const {
// Don't use Format:: - use immediate base class only,
// in case immediate base modifies behavior later.
return DateFormat::format(obj, result, status);
return DateFormat::format(obj, appendTo, status);
}
inline UnicodeString&
SimpleDateFormat::format(UDate date,
UnicodeString& result,
UnicodeString& appendTo,
FieldPosition& fieldPosition) const {
// Don't use Format:: - use immediate base class only,
// in case immediate base modifies behavior later.
return DateFormat::format(date, result, fieldPosition);
return DateFormat::format(date, appendTo, fieldPosition);
}
inline UnicodeString&
SimpleDateFormat::format(UDate date, UnicodeString& result) const {
return DateFormat::format(date, result);
SimpleDateFormat::format(UDate date, UnicodeString& appendTo) const {
return DateFormat::format(date, appendTo);
}
U_NAMESPACE_END