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

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

Parses the specfied string, beginning at the specified position, according to this formatter's rules. This will match the string against all of the formatter's public rule sets and return the value corresponding to the longest parseable substring. This function's behavior is affected by the lenient parse mode.

text The string to parse
result the result of the parse, either a double or a long.
parsePosition On entry, contains the position of the first character in "text" to examine. On exit, has been updated to contain the position of the first character in "text" that wasn't consumed by the parse.
See also:
setLenient ICU 2.0

Implements NumberFormat.

Definition at line 1150 of file rbnf.cpp.

References Formattable::getDouble(), ParsePosition::getErrorIndex(), ParsePosition::getIndex(), Formattable::getType(), Formattable::kDouble, ParsePosition::setErrorIndex(), ParsePosition::setIndex(), and Formattable::setLong().

    //TODO: We need a real fix.  See #6895 / #6896
    if (noParse) {
        // skip parsing

    if (!ruleSets) {

    UnicodeString workingText(text, parsePosition.getIndex());
    ParsePosition workingPos(0);

    ParsePosition high_pp(0);
    Formattable high_result;

    for (NFRuleSet** p = ruleSets; *p; ++p) {
        NFRuleSet *rp = *p;
        if (rp->isPublic() && rp->isParseable()) {
            ParsePosition working_pp(0);
            Formattable working_result;

            rp->parse(workingText, working_pp, kMaxDouble, working_result);
            if (working_pp.getIndex() > high_pp.getIndex()) {
                high_pp = working_pp;
                high_result = working_result;

                if (high_pp.getIndex() == workingText.length()) {

    int32_t startIndex = parsePosition.getIndex();
    parsePosition.setIndex(startIndex + high_pp.getIndex());
    if (high_pp.getIndex() > 0) {
    } else {
        int32_t errorIndex = (high_pp.getErrorIndex()>0)? high_pp.getErrorIndex(): 0;
        parsePosition.setErrorIndex(startIndex + errorIndex);
    result = high_result;
    if (result.getType() == Formattable::kDouble) {
        int32_t r = (int32_t)result.getDouble();
        if ((double)r == result.getDouble()) {

Generated by  Doxygen 1.6.0   Back to index