ICU-11706 (and #11726) Improve documentation, code cleanup

X-SVN-Rev: 37616
This commit is contained in:
Peter Edberg 2015-06-24 07:59:38 +00:00
parent a1b8a08bf7
commit 656838dbad
3 changed files with 45 additions and 30 deletions

View file

@ -459,10 +459,10 @@ DateIntervalFormat::adoptTimeZone(TimeZone* zone)
// work clones of that calendar (and should not also be given ownership of the
// adopted TimeZone).
if (fFromCalendar) {
fFromCalendar->setTimeZone(*zone);
fFromCalendar->setTimeZone(*zone);
}
if (fToCalendar) {
fToCalendar->setTimeZone(*zone);
fToCalendar->setTimeZone(*zone);
}
}
@ -475,10 +475,10 @@ DateIntervalFormat::setTimeZone(const TimeZone& zone)
// The fDateFormat has the master calendar for the DateIntervalFormat;
// fFromCalendar and fToCalendar are internal work clones of that calendar.
if (fFromCalendar) {
fFromCalendar->setTimeZone(zone);
fFromCalendar->setTimeZone(zone);
}
if (fToCalendar) {
fToCalendar->setTimeZone(zone);
fToCalendar->setTimeZone(zone);
}
}
@ -1386,25 +1386,21 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar,
UnicodeString fallbackRange;
MessageFormat::format(fallbackPattern, fmtArray, 2, fallbackRange, status);
if ( U_SUCCESS(status) && formatDatePlusTimeRange ) {
// fallbackRange has just the time range, need to format the date part and combine that
fDateFormat->applyPattern(*fDatePattern);
UnicodeString* datePortion = new UnicodeString();
otherPos.setBeginIndex(0);
otherPos.setEndIndex(0);
fDateFormat->format(fromCalendar, *datePortion, otherPos);
adjustPosition(*fDateTimeFormat, fallbackRange, pos, *datePortion, otherPos, pos);
fmtArray[0].setString(fallbackRange); // {0} is time range
fmtArray[1].adoptString(datePortion); // {1} is single date portion
fallbackRange.remove();
MessageFormat::format(*fDateTimeFormat, fmtArray, 2, fallbackRange, status);
}
if ( U_SUCCESS(status) ) {
if (!formatDatePlusTimeRange) {
appendTo.append(fallbackRange);
} else {
// fallbackRange has just the time range, need to format the date part and combine that
fDateFormat->applyPattern(*fDatePattern);
UnicodeString* datePortion = new UnicodeString();
otherPos.setBeginIndex(0);
otherPos.setEndIndex(0);
fDateFormat->format(fromCalendar, *datePortion, otherPos);
adjustPosition(*fDateTimeFormat, fallbackRange, pos, *datePortion, otherPos, pos);
fmtArray[0].setString(fallbackRange); // {0} is time range
fmtArray[1].adoptString(datePortion); // {1} is single date portion
fallbackRange.remove();
MessageFormat::format(*fDateTimeFormat, fmtArray, 2, fallbackRange, status);
if ( U_SUCCESS(status) ) {
appendTo.append(fallbackRange);
}
}
appendTo.append(fallbackRange);
}
if (formatDatePlusTimeRange) {
// restore full pattern

View file

@ -389,6 +389,9 @@ public:
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* There may be multiple instances of a given field type
* in an interval format; in this case the fieldPosition
* offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @stable ICU 4.0
@ -408,6 +411,9 @@ public:
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* There may be multiple instances of a given field type
* in an interval format; in this case the fieldPosition
* offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @stable ICU 4.0
@ -432,6 +438,9 @@ public:
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* There may be multiple instances of a given field type
* in an interval format; in this case the fieldPosition
* offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* Caller needs to make sure it is SUCCESS
* at the function entrance
@ -667,12 +676,20 @@ private:
*/
/**
* @param combiningPattern xxx
* @param pat0 xxx
* @param pos0 xxx
* @param pat1 xxx
* @param pos1 xxx
* @param posResult xxx
* Provide an updated FieldPosition posResult based on two formats,
* the FieldPosition values for each of them, and the pattern used
* to combine them. The idea is for posResult to indicate the first
* instance (if any) of the specified field in the combined result,
* with correct offsets.
*
* @param combiningPattern Pattern used to combine pat0 and pat1
* @param pat0 Formatted date/time value to replace {0}
* @param pos0 FieldPosition within pat0
* @param pat1 Formatted date/time value to replace {1}
* @param pos1 FieldPosition within pat1
* @param posResult FieldPosition to be set to the correct
* position of the first field instance when
* pat0 and pat1 are combined using combiningPattern
*/
static void
adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it
@ -681,7 +698,6 @@ private:
FieldPosition& posResult);
/**
* Format 2 Calendars using fall-back interval pattern
*

View file

@ -1,6 +1,6 @@
/*
*****************************************************************************************
* Copyright (C) 2010-2012, International Business Machines
* Copyright (C) 2010-2012,2015 International Business Machines
* Corporation and others. All Rights Reserved.
*****************************************************************************************
*/
@ -160,6 +160,9 @@ U_NAMESPACE_END
* the beginning and ending indices of field number position->field,
* if such a field exists. This parameter may be NULL, in which case
* no field position data is returned.
* There may be multiple instances of a given field type in an
* interval format; in this case the position indices refer to the
* first instance.
* @param status
* A pointer to a UErrorCode to receive any errors.
* @return