#include "unicode/vtzone.h"
#include "unicode/udisplaycontext.h"
#include "unicode/brkiter.h"
+#include "unicode/rbnf.h"
#include "uresimp.h"
#include "olsontz.h"
#include "patternprops.h"
}
}
}
-
if (fastFormatter != nullptr) {
// Can use fast path
number::impl::UFormattedNumberData result;
return;
}
appendTo.append(result.string.toTempUnicodeString());
+ return;
+ }
+
+ // Check for RBNF (no clone necessary)
+ auto* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(currentNumberFormat);
+ if (rbnf != nullptr) {
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ rbnf->format(value, appendTo, pos); // 3rd arg is there to speed up processing
+ return;
+ }
- } else if (currentNumberFormat != nullptr) {
- // Fall back to slow path
+ // Fall back to slow path (clone and mutate the NumberFormat)
+ if (currentNumberFormat != nullptr) {
FieldPosition pos(FieldPosition::DONT_CARE);
LocalPointer<NumberFormat> nf(dynamic_cast<NumberFormat*>(currentNumberFormat->clone()));
nf->setMinimumIntegerDigits(minDigits);
TESTCASE(24, TestLargeNumbers);
TESTCASE(25, TestCompactDecimalFormatStyle);
TESTCASE(26, TestParseFailure);
+ TESTCASE(27, TestMinMaxIntegerDigitsIgnored);
#else
TESTCASE(0, TestRBNFDisabled);
#endif
}
}
+void IntlTestRBNF::TestMinMaxIntegerDigitsIgnored() {
+ IcuTestErrorCode status(*this, "TestMinMaxIntegerDigitsIgnored");
+
+ // NOTE: SimpleDateFormat has an optimization that depends on the fact that min/max integer digits
+ // do not affect RBNF (see SimpleDateFormat#zeroPaddingNumber).
+ RuleBasedNumberFormat rbnf(URBNF_SPELLOUT, "en", status);
+ rbnf.setMinimumIntegerDigits(2);
+ rbnf.setMaximumIntegerDigits(3);
+ UnicodeString result;
+ rbnf.format(3, result.remove(), status);
+ assertEquals("Min integer digits are ignored", u"three", result);
+ rbnf.format(1012, result.remove(), status);
+ assertEquals("Max integer digits are ignored", u"one thousand twelve", result);
+}
+
void
IntlTestRBNF::doTest(RuleBasedNumberFormat* formatter, const char* const testData[][2], UBool testParsing)
{