Index: source/i18n/plurfmt.cpp |
diff --git a/source/i18n/plurfmt.cpp b/source/i18n/plurfmt.cpp |
index 7f6cd86e4c8babb4c0ff03250baebe2988624d91..9ff2bffc9d99cae2984adcde81bb7473ae5e332e 100644 |
--- a/source/i18n/plurfmt.cpp |
+++ b/source/i18n/plurfmt.cpp |
@@ -1,6 +1,6 @@ |
/* |
******************************************************************************* |
-* Copyright (C) 2009-2014, International Business Machines Corporation and |
+* Copyright (C) 2009-2015, International Business Machines Corporation and |
* others. All Rights Reserved. |
******************************************************************************* |
* |
@@ -19,6 +19,8 @@ |
#include "plurrule_impl.h" |
#include "uassert.h" |
#include "uhash.h" |
+#include "precision.h" |
+#include "visibledigits.h" |
#if !UCONFIG_NO_FORMATTING |
@@ -259,18 +261,37 @@ PluralFormat::format(const Formattable& numberObject, double number, |
double numberMinusOffset = number - offset; |
UnicodeString numberString; |
FieldPosition ignorePos; |
- FixedDecimal dec(numberMinusOffset); |
+ FixedPrecision fp; |
+ VisibleDigitsWithExponent dec; |
+ fp.initVisibleDigitsWithExponent(numberMinusOffset, dec, status); |
+ if (U_FAILURE(status)) { |
+ return appendTo; |
+ } |
if (offset == 0) { |
- numberFormat->format(numberObject, numberString, ignorePos, status); // could be BigDecimal etc. |
DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat); |
if(decFmt != NULL) { |
- dec = decFmt->getFixedDecimal(numberObject, status); |
+ decFmt->initVisibleDigitsWithExponent( |
+ numberObject, dec, status); |
+ if (U_FAILURE(status)) { |
+ return appendTo; |
+ } |
+ decFmt->format(dec, numberString, ignorePos, status); |
+ } else { |
+ numberFormat->format( |
+ numberObject, numberString, ignorePos, status); // could be BigDecimal etc. |
} |
} else { |
- numberFormat->format(numberMinusOffset, numberString, ignorePos, status); |
DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat); |
if(decFmt != NULL) { |
- dec = decFmt->getFixedDecimal(numberMinusOffset, status); |
+ decFmt->initVisibleDigitsWithExponent( |
+ numberMinusOffset, dec, status); |
+ if (U_FAILURE(status)) { |
+ return appendTo; |
+ } |
+ decFmt->format(dec, numberString, ignorePos, status); |
+ } else { |
+ numberFormat->format( |
+ numberMinusOffset, numberString, ignorePos, status); |
} |
} |
int32_t partIndex = findSubMessage(msgPattern, 0, pluralRulesWrapper, &dec, number, status); |
@@ -533,7 +554,7 @@ void PluralFormat::parseType(const UnicodeString& source, const NFRule *rbnfLeni |
currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg, startingAt, &length); |
} |
else { |
- currMatchIndex = source.indexOf(currArg); |
+ currMatchIndex = source.indexOf(currArg, startingAt); |
} |
if (currMatchIndex >= 0 && currMatchIndex >= matchedIndex && currArg.length() > matchedWord.length()) { |
matchedIndex = currMatchIndex; |
@@ -562,8 +583,7 @@ PluralFormat::PluralSelectorAdapter::~PluralSelectorAdapter() { |
UnicodeString PluralFormat::PluralSelectorAdapter::select(void *context, double number, |
UErrorCode& /*ec*/) const { |
(void)number; // unused except in the assertion |
- FixedDecimal *dec=static_cast<FixedDecimal *>(context); |
- U_ASSERT(dec->source==number); |
+ VisibleDigitsWithExponent *dec=static_cast<VisibleDigitsWithExponent *>(context); |
return pluralRules->select(*dec); |
} |