}
}
+// this is only overridden to call handleChanged() for fastpath purposes.
+void
+DecimalFormat::setGroupingUsed(UBool newValue) {
+ NumberFormat::setGroupingUsed(newValue);
+ handleChanged();
+}
+
+// this is only overridden to call handleChanged() for fastpath purposes.
+void
+DecimalFormat::setParseIntegerOnly(UBool newValue) {
+ NumberFormat::setParseIntegerOnly(newValue);
+ handleChanged();
+}
+
+// this is only overridden to call handleChanged() for fastpath purposes.
+// setContext doesn't affect the fastPath right now, but this is called for completeness
+void
+DecimalFormat::setContext(UDisplayContext value, UErrorCode& status) {
+ NumberFormat::setContext(value, status);
+ handleChanged();
+}
+
+
DecimalFormat& DecimalFormat::setAttribute( UNumberFormatAttribute attr,
int32_t newValue,
UErrorCode &status) {
/*
********************************************************************************
-* Copyright (C) 1997-2013, International Business Machines
+* Copyright (C) 1997-2014, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
// explicit template instantiation. see digitlst.h
#if defined (_MSC_VER)
template class U_I18N_API EnumSet<UNumberFormatAttribute,
- UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
+ UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
UNUM_LIMIT_BOOLEAN_ATTRIBUTE>;
#endif
kRoundHalfUp, /**< Round towards the nearest integer, or
away from zero if equidistant */
/**
- * Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
- * @stable ICU 4.8
+ * Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
+ * @stable ICU 4.8
*/
kRoundUnnecessary
};
virtual int32_t getAttribute( UNumberFormatAttribute attr,
UErrorCode &status) const;
+
+ /**
+ * Set whether or not grouping will be used in this format.
+ * @param newValue True, grouping will be used in this format.
+ * @see getGroupingUsed
+ * @stable ICU 2.0
+ */
+ virtual void setGroupingUsed(UBool newValue);
+
+ /**
+ * Sets whether or not numbers should be parsed as integers only.
+ * @param value set True, this format will parse numbers as integers
+ * only.
+ * @see isParseIntegerOnly
+ * @stable ICU 2.0
+ */
+ virtual void setParseIntegerOnly(UBool value);
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @draft ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
/**
* Create a DecimalFormat from the given pattern and symbols.
/**
- * Format a decimal number.
+ * Format a decimal number.
* The number is a DigitList wrapper onto a floating point decimal number.
* The default implementation in NumberFormat converts the decimal number
* to a double and formats that.
UErrorCode& status) const;
/**
- * Format a decimal number.
+ * Format a decimal number.
* The number is a DigitList wrapper onto a floating point decimal number.
* The default implementation in NumberFormat converts the decimal number
- * to a double and formats that.
+ * to a double and formats that.
*
* @param number The number, a DigitList format Decimal Floating Point.
* @param appendTo Output parameter to receive result.
virtual ERoundingMode getRoundingMode(void) const;
/**
- * Set the rounding mode.
+ * Set the rounding mode.
* @param roundingMode A rounding mode
* @see #setRoundingIncrement
* @see #getRoundingIncrement
UnicodeString& subformat(UnicodeString& appendTo,
FieldPositionHandler& handler,
DigitList& digits,
- UBool isInteger,
+ UBool isInteger,
UErrorCode &status) const;
ChoiceFormat* fCurrencyChoice;
DigitList * fMultiplier; // NULL for multiplier of one
- int32_t fScale;
+ int32_t fScale;
int32_t fGroupingSize;
int32_t fGroupingSize2;
UBool fDecimalSeparatorAlwaysShown;
UBool fExponentSignAlwaysShown;
EnumSet<UNumberFormatAttribute,
- UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
- UNUM_LIMIT_BOOLEAN_ATTRIBUTE>
+ UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
+ UNUM_LIMIT_BOOLEAN_ATTRIBUTE>
fBoolFlags;
DigitList* fRoundingIncrement; // NULL if no rounding increment specified.
#if UCONFIG_FORMAT_FASTPATHS_49
private:
/**
- * Internal state.
+ * Internal state.
* @internal
*/
uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
/********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2013, International Business Machines Corporation and
+ * COPYRIGHT:
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
{
if (exec) logln((UnicodeString)"TestSuite DecimalFormatAPI");
switch (index) {
- case 0: name = "DecimalFormat API test";
+ case 0: name = "DecimalFormat API test";
if (exec) {
logln((UnicodeString)"DecimalFormat API test---"); logln((UnicodeString)"");
UErrorCode status = U_ZERO_ERROR;
TestFixedDecimal();
}
break;
+ case 6: name = "TestBadFastpath";
+ if(exec) {
+ logln((UnicodeString)"TestBadFastpath ---");
+ TestBadFastpath();
+ }
+ break;
default: name = ""; break;
}
}
UnicodeString res1, res2, res3, res4;
FieldPosition pos1(0), pos2(0), pos3(0), pos4(0);
-
+
res1 = def.format(d, res1, pos1);
logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res1);
if(sn != TRUE) {
errln((UnicodeString)"ERROR: setScientificNotation() failed");
}
-
+
// Added by Ken Liu testing set/getMinimumExponentDigits
int8_t MinimumExponentDigits = 0;
pat.setMinimumExponentDigits(2);
if(U_FAILURE(status)) {
errln((UnicodeString)"ERROR: CurrencyPluralInfo::setLocale");
}
-
+
cpi->setPluralRules("",status);
if(U_FAILURE(status)) {
errln((UnicodeString)"ERROR: CurrencyPluralInfo::setPluralRules");
3.0, -3.0, // kRoundUp 3,
3.0, -3.0, // kRoundHalfEven 4,
3.0, -3.0, // kRoundHalfDown 5,
- 3.0, -3.0 // kRoundHalfUp 6
+ 3.0, -3.0 // kRoundHalfUp 6
};
DecimalFormat pat(status);
if(U_FAILURE(status)) {
return;
}
- // With rounding now being handled by decNumber, we no longer
+ // With rounding now being handled by decNumber, we no longer
// set a rounding increment to enable non-default mode rounding,
// checking of which was the original point of this test.
- // set rounding mode with zero increment. Rounding
+ // set rounding mode with zero increment. Rounding
// increment should not be set by this operation
pat.setRoundingMode((DecimalFormat::ERoundingMode)0);
roundingInc = pat.getRoundingIncrement();
}
pat.setAttribute(UNUM_SCALE,testData[i].inputScale,status);
pat.format(testData[i].inputValue, resultStr);
- message = UnicodeString("Unexpected output for ") + testData[i].inputValue + UnicodeString(" and scale ") +
+ message = UnicodeString("Unexpected output for ") + testData[i].inputValue + UnicodeString(" and scale ") +
testData[i].inputScale + UnicodeString(". Got: ");
exp = testData[i].expectedOutput;
verifyString(message, resultStr, exp);
ASSERT_EQUAL(FALSE, fd.isNegative);
}
-
-#endif /* #if !UCONFIG_NO_FORMATTING */
+
+void IntlTestDecimalFormatAPI::TestBadFastpath() {
+ UErrorCode status = U_ZERO_ERROR;
+
+ LocalPointer<DecimalFormat> df(new DecimalFormat("###", status));
+ TEST_ASSERT_STATUS(status);
+
+ UnicodeString fmt;
+ fmt.remove();
+ assertEquals("Format 1234", "1234", df->format(1234, fmt));
+ df->setGroupingUsed(FALSE);
+ fmt.remove();
+ assertEquals("Format 1234", "1234", df->format(1234, fmt));
+ df->setGroupingUsed(TRUE);
+ fmt.remove();
+ assertEquals("Format 1234 w/ grouping", "1,234", df->format(1234, fmt));
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */x
/********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2013, International Business Machines Corporation and
+ * COPYRIGHT:
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
class IntlTestDecimalFormatAPI: public IntlTest {
- void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
+ void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
public:
/**
void TestCurrencyPluralInfo();
void TestScale();
void TestFixedDecimal();
+ void TestBadFastpath();
private:
/*Helper functions */
void verify(const UnicodeString& message, const UnicodeString& got, double expected);