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

void ChoiceFormat::parse ( const UnicodeString text,
Formattable result,
ParsePosition parsePosition 
) const [virtual]

Return a long if possible (e.g. within range LONG_MAX, LONG_MAX], and with no decimals), otherwise a double. If IntegerOnly is set, will stop at a decimal point (or equivalent; e.g. for rational numbers "1 2/3", will stop after the 1).

If no object can be parsed, parsePosition is unchanged, and NULL is returned.

text The text to be parsed.
result Formattable to be set to the parse result. If parse fails, return contents are undefined.
parsePosition The position to start parsing at on input. On output, moved to after the last successfully parse character. On parse failure, does not change.
See also:
NumberFormat::isParseIntegerOnly ICU 2.0

Implements NumberFormat.

Definition at line 711 of file choicfmt.cpp.

References UnicodeString::compare(), fChoiceLimits, ParsePosition::getIndex(), UnicodeString::length(), Formattable::setDouble(), ParsePosition::setErrorIndex(), and ParsePosition::setIndex().

Referenced by TestChoiceFormat::TestComplexExample().

    // find the best number (defined as the one with the longest parse)
    int32_t start = status.getIndex();
    int32_t furthest = start;
    double bestNumber = uprv_getNaN();
    double tempNumber = 0.0;
    for (int i = 0; i < fCount; ++i) {
        int32_t len = fChoiceFormats[i].length();
        if (text.compare(start, len, fChoiceFormats[i]) == 0) {
            status.setIndex(start + len);
            tempNumber = fChoiceLimits[i];
            if (status.getIndex() > furthest) {
                furthest = status.getIndex();
                bestNumber = tempNumber;
                if (furthest == text.length()) 
    if (status.getIndex() == start) {

Generated by  Doxygen 1.6.0   Back to index