Logo Search packages:      
Sourcecode: icu version File versions  Download package

UnicodeString & NumberFormat::format ( const Formattable obj,
UnicodeString appendTo,
FieldPositionIterator posIter,
UErrorCode status 
) const [virtual, inherited]

Format an object to produce a string. This method handles Formattable objects with numeric types. If the Formattable object type is not a numeric type, then it returns a failing UErrorCode.

Parameters:
obj The object to format.
appendTo Output parameter to receive result. Result is appended to existing contents.
posIter On return, can be used to iterate over positions of fields generated by this format call. Can be NULL.
status Output param filled with success/failure status.
Returns:
Reference to 'appendTo' parameter. 4.4

Reimplemented from Format.

Definition at line 483 of file numfmt.cpp.

References NumberFormat::format(), Formattable::getDigitList(), Formattable::getDouble(), Formattable::getInt64(), Formattable::getLong(), Formattable::getType(), Formattable::isNumeric(), Formattable::kDouble, Formattable::kInt64, Formattable::kLong, NULL, U_FAILURE, and U_INVALID_FORMAT_ERROR.

{
    if (U_FAILURE(status)) return appendTo;

    ArgExtractor arg(*this, obj, status);
    const Formattable *n = arg.number();

    if (n->isNumeric() && n->getDigitList() != NULL) {
        // Decimal Number
        format(*n->getDigitList(), appendTo, posIter, status);
    } else {
        switch (n->getType()) {
        case Formattable::kDouble:
            format(n->getDouble(), appendTo, posIter, status);
            break;
        case Formattable::kLong:
            format(n->getLong(), appendTo, posIter, status);
            break;
        case Formattable::kInt64:
            format(n->getInt64(), appendTo, posIter, status);
            break;
        default:
            status = U_INVALID_FORMAT_ERROR;
            break;
        }
    }

    return appendTo;
}


Generated by  Doxygen 1.6.0   Back to index