Logo Search packages:      
Sourcecode: icu version File versions

UnicodeString & SimpleDateFormat::_format ( Calendar cal,
UnicodeString appendTo,
FieldPositionHandler handler,
UErrorCode status 
) const [private]

Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)

Definition at line 829 of file smpdtfmt.cpp.

References Calendar::adoptTimeZone(), TimeZone::clone(), FALSE, DateFormat::fCalendar, fPattern, Calendar::getTime(), Calendar::getTimeZone(), Calendar::getType(), UnicodeString::length(), NULL, Calendar::setTime(), Calendar::setTimeZone(), subFormat(), and U_SUCCESS.

Referenced by format().

{
    Calendar *workCal = &cal;
    TimeZone *backupTZ = NULL;
    if (&cal != fCalendar && uprv_strcmp(cal.getType(), fCalendar->getType()) != 0) {
        // Different calendar type
        // We use the time and time zone from the input calendar, but
        // do not use the input calendar for field calculation.
        UDate t = cal.getTime(status);
        fCalendar->setTime(t, status);
        backupTZ = fCalendar->getTimeZone().clone();
        fCalendar->setTimeZone(cal.getTimeZone());
        workCal = fCalendar;
    }

    UBool inQuote = FALSE;
    UChar prevCh = 0;
    int32_t count = 0;

    // loop through the pattern string character by character
    for (int32_t i = 0; i < fPattern.length() && U_SUCCESS(status); ++i) {
        UChar ch = fPattern[i];

        // Use subFormat() to format a repeated pattern character
        // when a different pattern or non-pattern character is seen
        if (ch != prevCh && count > 0) {
            subFormat(appendTo, prevCh, count, handler, *workCal, status);
            count = 0;
        }
        if (ch == QUOTE) {
            // Consecutive single quotes are a single quote literal,
            // either outside of quotes or between quotes
            if ((i+1) < fPattern.length() && fPattern[i+1] == QUOTE) {
                appendTo += (UChar)QUOTE;
                ++i;
            } else {
                inQuote = ! inQuote;
            }
        }
        else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
                    || (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) {
            // ch is a date-time pattern character to be interpreted
            // by subFormat(); count the number of times it is repeated
            prevCh = ch;
            ++count;
        }
        else {
            // Append quoted characters and unquoted non-pattern characters
            appendTo += ch;
        }
    }

    // Format the last item in the pattern, if any
    if (count > 0) {
        subFormat(appendTo, prevCh, count, handler, *workCal, status);
    }

    if (backupTZ != NULL) {
        // Restore the original time zone
        fCalendar->adoptTimeZone(backupTZ);
    }

    return appendTo;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index