示例#1
0
void
NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos, UErrorCode& status) const
{
    NFRule *rule = findDoubleRule(number);
    if (rule) { // else error, but can't report it
        NFRuleSet* ncThis = (NFRuleSet*)this;
        if (ncThis->fRecursionCount++ >= RECURSION_LIMIT) {
            // stop recursion
            ncThis->fRecursionCount = 0;
        } else {
            rule->doFormat(number, toAppendTo, pos, status);
            ncThis->fRecursionCount--;
        }
    }
}
/**
 * If this is a >>> substitution, use ruleToUse to fill in
 * the substitution.  Otherwise, just use the superclass function.
 * @param number The number being formatted
 * @toInsertInto The string to insert the result of this substitution
 * into
 * @param pos The position of the rule text in toInsertInto
 */
void
ModulusSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos) const
{
    // if this isn't a >>> substitution, just use the inherited version
    // of this function (which uses either a rule set or a DecimalFormat
    // to format its substitution value)
    if (ruleToUse == NULL) {
        NFSubstitution::doSubstitution(number, toInsertInto, _pos);

        // a >>> substitution goes straight to a particular rule to
        // format the substitution value
    } else {
        int64_t numberToFormat = transformNumber(number);
        ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos());
    }
}