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

Formattable & NumberFormat::parseCurrency ( const UnicodeString text,
Formattable result,
ParsePosition pos 
) const [virtual, inherited]

Parses text from the given string as a currency amount. Unlike the parse() method, this method will attempt to parse a generic currency name, searching for a match of this object's locale's currency display names, or for a 3-letter ISO currency code. This method will fail if this format is not a currency format, that is, if it does not contain the currency pattern symbol (U+00A4) in its prefix or suffix.

text the string to parse
result output parameter to receive result. This will have its currency set to the parsed ISO currency code.
pos input-output position; on input, the position within text to match; must have 0 <= pos.getIndex() < text.length(); on output, the position after the last matched character. If the parse fails, the position in unchanged upon output.
a reference to result

For internal use only.

Reimplemented in DecimalFormat.

Definition at line 589 of file numfmt.cpp.

References Formattable::adoptObject(), NumberFormat::getEffectiveCurrency(), ParsePosition::getIndex(), NULL, NumberFormat::parse(), ParsePosition::setIndex(), U_FAILURE, U_SUCCESS, and U_ZERO_ERROR.

Referenced by CurrencyFormat::parseObject(), and NumberFormatTest::TestAPI().

    // Default implementation only -- subclasses should override
    int32_t start = pos.getIndex();
    parse(text, result, pos);
    if (pos.getIndex() != start) {
        UChar curr[4];
        UErrorCode ec = U_ZERO_ERROR;
        getEffectiveCurrency(curr, ec);
        if (U_SUCCESS(ec)) {
            Formattable n(result);
            CurrencyAmount *tempCurAmnt = new CurrencyAmount(n, curr, ec);  // Use for null testing.
            if (U_FAILURE(ec) || tempCurAmnt == NULL) {
                pos.setIndex(start); // indicate failure
            } else {
    return result;

Generated by  Doxygen 1.6.0   Back to index