ICU-13412 Merging #13415 Misc. ICU4C platform support fixes (r40614 + r40624 + r40426 + r40629 + r40631 + r40632 + r40641) to maint-60.

X-SVN-Rev: 40649
This commit is contained in:
Yoshito Umaoka 2017-10-26 23:34:18 +00:00
parent f3ead29e7f
commit 678b6ed5f7
16 changed files with 107 additions and 61 deletions

View file

@ -1383,6 +1383,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
prevCPPos = cpPos;
prevUTextPos = utextPos;
}
(void)prevCPPos; // suppress compiler warnings about unused variable
// inString goes out of scope
// inputMap goes out of scope

View file

@ -207,7 +207,7 @@
* @internal
*/
#ifndef UPRV_INCOMPLETE_CPP11_SUPPORT
# define UPRV_INCOMPLETE_CPP11_SUPPORT (U_PLATFORM == U_PF_AIX || U_PLATFORM == U_PF_OS390)
# define UPRV_INCOMPLETE_CPP11_SUPPORT (U_PLATFORM == U_PF_AIX || U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_SOLARIS )
#endif
/**

View file

@ -49,6 +49,8 @@ struct AffixTag {
// Exported as U_I18N_API because it is a base class for other exported types
class U_I18N_API SymbolProvider {
public:
virtual ~SymbolProvider() = default;
// TODO: Could this be more efficient if it returned by reference?
virtual UnicodeString getSymbol(AffixPatternType type) const = 0;
};

View file

@ -317,6 +317,7 @@ void CompactHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micr
}
// FIXME: Deal with numDigits == 0 (Awaiting a test case)
(void)numDigits;
// We already performed rounding. Do not perform it again.
micros.rounding = Rounder::constructPassThrough();

View file

@ -247,33 +247,33 @@ LocalizedNumberFormatter::~LocalizedNumberFormatter() {
}
FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode &status) const {
if (U_FAILURE(status)) { return FormattedNumber(); }
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
auto results = new NumberFormatterResults();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return FormattedNumber();
return FormattedNumber(status);
}
results->quantity.setToLong(value);
return formatImpl(results, status);
}
FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode &status) const {
if (U_FAILURE(status)) { return FormattedNumber(); }
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
auto results = new NumberFormatterResults();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return FormattedNumber();
return FormattedNumber(status);
}
results->quantity.setToDouble(value);
return formatImpl(results, status);
}
FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErrorCode &status) const {
if (U_FAILURE(status)) { return FormattedNumber(); }
if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
auto results = new NumberFormatterResults();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return FormattedNumber();
return FormattedNumber(status);
}
results->quantity.setToDecNumber(value);
return formatImpl(results, status);
@ -317,28 +317,48 @@ LocalizedNumberFormatter::formatImpl(impl::NumberFormatterResults *results, UErr
NumberFormatterImpl::applyStatic(fMacros, results->quantity, results->string, status);
}
return FormattedNumber(results);
// Do not save the results object if we encountered a failure.
if (U_SUCCESS(status)) {
return FormattedNumber(results);
} else {
delete results;
return FormattedNumber(status);
}
}
UnicodeString FormattedNumber::toString() const {
if (fResults == nullptr) { return {}; }
if (fResults == nullptr) {
// TODO: http://bugs.icu-project.org/trac/ticket/13437
return {};
}
return fResults->string.toUnicodeString();
}
Appendable &FormattedNumber::appendTo(Appendable &appendable) {
if (fResults == nullptr) { return appendable; }
if (fResults == nullptr) {
// TODO: http://bugs.icu-project.org/trac/ticket/13437
return appendable;
}
appendable.appendString(fResults->string.chars(), fResults->string.length());
return appendable;
}
void FormattedNumber::populateFieldPosition(FieldPosition &fieldPosition, UErrorCode &status) {
if (fResults == nullptr) { return; }
if (U_FAILURE(status)) { return; }
if (fResults == nullptr) {
status = fErrorCode;
return;
}
fResults->string.populateFieldPosition(fieldPosition, 0, status);
}
void
FormattedNumber::populateFieldPositionIterator(FieldPositionIterator &iterator, UErrorCode &status) {
if (fResults == nullptr) { return; }
if (U_FAILURE(status)) { return; }
if (fResults == nullptr) {
status = fErrorCode;
return;
}
fResults->string.populateFieldPositionIterator(iterator, status);
}

View file

@ -22,7 +22,7 @@ IntegerWidth IntegerWidth::zeroFillTo(int32_t minInt) {
if (minInt >= 0 && minInt <= kMaxIntFracSig) {
return {static_cast<int8_t>(minInt), -1};
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -31,7 +31,7 @@ IntegerWidth IntegerWidth::truncateAt(int32_t maxInt) {
if (maxInt >= 0 && maxInt <= kMaxIntFracSig) {
return {fUnion.minMaxInt.fMinInt, static_cast<int8_t>(maxInt)};
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}

View file

@ -60,7 +60,7 @@ ScientificNotation::withMinExponentDigits(int32_t minExponentDigits) const {
NotationUnion union_ = {settings};
return {NTN_SCIENTIFIC, union_};
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}

View file

@ -43,7 +43,7 @@ Padder Padder::codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosit
if (targetWidth >= 0) {
return {cp, targetWidth, position};
} else {
return {U_NUMBER_PADDING_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_PADDING_WIDTH_OUTOFBOUNDS_ERROR};
}
}

View file

@ -58,7 +58,7 @@ FractionRounder Rounder::fixedFraction(int32_t minMaxFractionPlaces) {
if (minMaxFractionPlaces >= 0 && minMaxFractionPlaces <= kMaxIntFracSig) {
return constructFraction(minMaxFractionPlaces, minMaxFractionPlaces);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -66,7 +66,7 @@ FractionRounder Rounder::minFraction(int32_t minFractionPlaces) {
if (minFractionPlaces >= 0 && minFractionPlaces <= kMaxIntFracSig) {
return constructFraction(minFractionPlaces, -1);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -74,7 +74,7 @@ FractionRounder Rounder::maxFraction(int32_t maxFractionPlaces) {
if (maxFractionPlaces >= 0 && maxFractionPlaces <= kMaxIntFracSig) {
return constructFraction(0, maxFractionPlaces);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -83,7 +83,7 @@ FractionRounder Rounder::minMaxFraction(int32_t minFractionPlaces, int32_t maxFr
minFractionPlaces <= maxFractionPlaces) {
return constructFraction(minFractionPlaces, maxFractionPlaces);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -91,7 +91,7 @@ Rounder Rounder::fixedDigits(int32_t minMaxSignificantDigits) {
if (minMaxSignificantDigits >= 0 && minMaxSignificantDigits <= kMaxIntFracSig) {
return constructSignificant(minMaxSignificantDigits, minMaxSignificantDigits);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -99,7 +99,7 @@ Rounder Rounder::minDigits(int32_t minSignificantDigits) {
if (minSignificantDigits >= 0 && minSignificantDigits <= kMaxIntFracSig) {
return constructSignificant(minSignificantDigits, -1);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -107,7 +107,7 @@ Rounder Rounder::maxDigits(int32_t maxSignificantDigits) {
if (maxSignificantDigits >= 0 && maxSignificantDigits <= kMaxIntFracSig) {
return constructSignificant(0, maxSignificantDigits);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -116,7 +116,7 @@ Rounder Rounder::minMaxDigits(int32_t minSignificantDigits, int32_t maxSignifica
minSignificantDigits <= maxSignificantDigits) {
return constructSignificant(minSignificantDigits, maxSignificantDigits);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -124,7 +124,7 @@ IncrementRounder Rounder::increment(double roundingIncrement) {
if (roundingIncrement > 0.0) {
return constructIncrement(roundingIncrement, 0);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -142,7 +142,7 @@ Rounder FractionRounder::withMinDigits(int32_t minSignificantDigits) const {
if (minSignificantDigits >= 0 && minSignificantDigits <= kMaxIntFracSig) {
return constructFractionSignificant(*this, minSignificantDigits, -1);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -151,7 +151,7 @@ Rounder FractionRounder::withMaxDigits(int32_t maxSignificantDigits) const {
if (maxSignificantDigits >= 0 && maxSignificantDigits <= kMaxIntFracSig) {
return constructFractionSignificant(*this, -1, maxSignificantDigits);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}
@ -185,7 +185,7 @@ Rounder IncrementRounder::withMinFraction(int32_t minFrac) const {
if (minFrac >= 0 && minFrac <= kMaxIntFracSig) {
return constructIncrement(fUnion.increment.fIncrement, minFrac);
} else {
return {U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR};
return {U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR};
}
}

View file

@ -43,8 +43,8 @@ static constexpr char16_t kFallbackPaddingString[] = u" ";
static constexpr char16_t kDefaultCurrency[] = u"XXX";
// FIXME: New error codes:
static constexpr UErrorCode U_NUMBER_DIGIT_WIDTH_OUT_OF_RANGE_ERROR = U_ILLEGAL_ARGUMENT_ERROR;
static constexpr UErrorCode U_NUMBER_PADDING_WIDTH_OUT_OF_RANGE_ERROR = U_ILLEGAL_ARGUMENT_ERROR;
static constexpr UErrorCode U_NUMBER_DIGIT_WIDTH_OUTOFBOUNDS_ERROR = U_ILLEGAL_ARGUMENT_ERROR;
static constexpr UErrorCode U_NUMBER_PADDING_WIDTH_OUTOFBOUNDS_ERROR = U_ILLEGAL_ARGUMENT_ERROR;
// Forward declarations:

View file

@ -789,7 +789,9 @@ AndConstraint::isFulfilled(const IFixedDecimal &number) {
// An empty AndConstraint, created by a rule with a keyword but no following expression.
return TRUE;
}
double n = number.getPluralOperand(digitsType); // pulls n | i | v | f value for the number.
PluralOperand operand = tokenTypeToPluralOperand(digitsType);
double n = number.getPluralOperand(operand); // pulls n | i | v | f value for the number.
// Will always be positive.
// May be non-integer (n option only)
do {
@ -1405,6 +1407,24 @@ PluralKeywordEnumeration::count(UErrorCode& /*status*/) const {
PluralKeywordEnumeration::~PluralKeywordEnumeration() {
}
PluralOperand tokenTypeToPluralOperand(tokenType tt) {
switch(tt) {
case tVariableN:
return PLURAL_OPERAND_N;
case tVariableI:
return PLURAL_OPERAND_I;
case tVariableF:
return PLURAL_OPERAND_F;
case tVariableV:
return PLURAL_OPERAND_V;
case tVariableT:
return PLURAL_OPERAND_T;
default:
U_ASSERT(FALSE); // unexpected.
return PLURAL_OPERAND_N;
}
}
IFixedDecimal::~IFixedDecimal() = default;
FixedDecimal::FixedDecimal(const VisibleDigits &digits) {

View file

@ -221,6 +221,12 @@ enum PluralOperand {
PLURAL_OPERAND_J
};
/**
* Converts from the tokenType enum to PluralOperand. Asserts that the given
* tokenType can be mapped to a PluralOperand.
*/
PluralOperand tokenTypeToPluralOperand(tokenType tt);
/**
* An interface to FixedDecimal, allowing for other implementations.
* @internal
@ -235,25 +241,6 @@ class U_I18N_API IFixedDecimal {
*/
virtual double getPluralOperand(PluralOperand operand) const = 0;
/** Converts from the tokenType enum to PluralOperand. */
virtual double getPluralOperand(tokenType tt) const {
switch(tt) {
case tVariableN:
return getPluralOperand(PLURAL_OPERAND_N);
case tVariableI:
return getPluralOperand(PLURAL_OPERAND_I);
case tVariableF:
return getPluralOperand(PLURAL_OPERAND_F);
case tVariableV:
return getPluralOperand(PLURAL_OPERAND_V);
case tVariableT:
return getPluralOperand(PLURAL_OPERAND_T);
default:
U_ASSERT(FALSE); // unexpected.
return 0.0;
}
}
virtual bool isNaN() const = 0;
virtual bool isInfinite() const = 0;

View file

@ -1853,8 +1853,8 @@ class U_I18N_API LocalizedNumberFormatter
* <p>
* This function is very hot, being called in every call to the number formatting pipeline.
*
* @param fq
* The quantity to be formatted.
* @param results
* The results object. This method takes ownership.
* @return The formatted number result.
*/
FormattedNumber formatImpl(impl::NumberFormatterResults *results, UErrorCode &status) const;
@ -1941,10 +1941,14 @@ class U_I18N_API FormattedNumber : public UMemory {
// Can't use LocalPointer because NumberFormatterResults is forward-declared
const impl::NumberFormatterResults *fResults;
// Default constructor for error states
FormattedNumber() : fResults(nullptr) {}
// Error code for the terminal methods
UErrorCode fErrorCode;
explicit FormattedNumber(impl::NumberFormatterResults *results) : fResults(results) {}
explicit FormattedNumber(impl::NumberFormatterResults *results)
: fResults(results), fErrorCode(U_ZERO_ERROR) {};
explicit FormattedNumber(UErrorCode errorCode)
: fResults(nullptr), fErrorCode(errorCode) {};
// To give LocalizedNumberFormatter format methods access to this class's constructor:
friend class LocalizedNumberFormatter;

View file

@ -1422,12 +1422,19 @@ void NumberFormatterApiTest::errors() {
-1));
{
UErrorCode status = U_ZERO_ERROR;
lnf.formatInt(1, status);
UErrorCode status1 = U_ZERO_ERROR;
UErrorCode status2 = U_ZERO_ERROR;
FormattedNumber fn = lnf.formatInt(1, status1);
assertEquals(
"Should fail with U_ILLEGAL_ARGUMENT_ERROR since rounder is not legal",
U_ILLEGAL_ARGUMENT_ERROR,
status);
status1);
FieldPosition fp;
fn.populateFieldPosition(fp, status2);
assertEquals(
"Should fail with U_ILLEGAL_ARGUMENT_ERROR on terminal method",
U_ILLEGAL_ARGUMENT_ERROR,
status2);
}
{

View file

@ -425,19 +425,19 @@ UBool NumberFormatTestDataDriven::isParsePass(
return TRUE; // TRUE because failure handling is in the test suite
}
if (tuple.output == "NaN") {
if (!std::isnan(result.getDouble())) {
if (!uprv_isNaN(result.getDouble())) {
appendErrorMessage.append("Expected NaN, but got: " + resultStr);
return FALSE;
}
return TRUE;
} else if (tuple.output == "Inf") {
if (!std::isinf(result.getDouble()) || result.getDouble() < 0) {
if (!uprv_isInfinite(result.getDouble()) || result.getDouble() < 0) {
appendErrorMessage.append("Expected Inf, but got: " + resultStr);
return FALSE;
}
return TRUE;
} else if (tuple.output == "-Inf") {
if (!std::isinf(result.getDouble()) || result.getDouble() > 0) {
if (!uprv_isInfinite(result.getDouble()) || result.getDouble() > 0) {
appendErrorMessage.append("Expected -Inf, but got: " + resultStr);
return FALSE;
}

View file

@ -1003,6 +1003,9 @@ void StringCaseTest::TestCopyMoveEdits() {
assertEquals("b remains: many edits, length delta", 250, b.lengthDelta());
TestUtility::checkEqualEdits(*this, u"c = b", b, c, errorCode);
// std::move trouble on these platforms.
// See https://ssl.icu-project.org/trac/ticket/13393
#if !UPRV_INCOMPLETE_CPP11_SUPPORT && !(U_PLATFORM == U_PF_AIX || U_PLATFORM == U_PF_OS390)
// move constructor empties object with heap array
Edits d(std::move(a));
assertEquals("d: move-constructed many edits, length delta", 250, d.lengthDelta());
@ -1029,6 +1032,7 @@ void StringCaseTest::TestCopyMoveEdits() {
assertSuccess("iter.next()", errorCode);
assertTrue("iter.hasChange()", iter.hasChange());
assertEquals("iter.newLength()", 1, iter.newLength());
#endif
}
void StringCaseTest::TestEditsFindFwdBwd() {