]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/decimfmt.cpp
ICU-511.32.tar.gz
[apple/icu.git] / icuSources / i18n / decimfmt.cpp
index 4cceb61027d17233924a8630d6df5b01c7d74081..849a2347a4f5b8e7e7243ad67fdf85a2793bef2a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2006, International Business Machines Corporation and    *
+* Copyright (C) 1997-2013, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 *
 *   02/22/99    stephen     Removed character literals for EBCDIC safety
 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
 *   06/28/99    stephen     Fixed bugs in toPattern().
-*   06/29/99    stephen     Fixed operator= to copy fFormatWidth, fPad, 
+*   06/29/99    stephen     Fixed operator= to copy fFormatWidth, fPad,
 *                             fPadPosition
 ********************************************************************************
 */
+
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_FORMATTING
 
+#include "fphdlimp.h"
 #include "unicode/decimfmt.h"
 #include "unicode/choicfmt.h"
 #include "unicode/ucurr.h"
 #include "unicode/dcfmtsym.h"
 #include "unicode/ures.h"
 #include "unicode/uchar.h"
+#include "unicode/uniset.h"
 #include "unicode/curramt.h"
+#include "unicode/currpinf.h"
+#include "unicode/plurrule.h"
+#include "unicode/utf16.h"
+#include "unicode/numsys.h"
+#include "unicode/localpointer.h"
+#include "uresimp.h"
 #include "ucurrimp.h"
-#include "util.h"
-#include "digitlst.h"
+#include "charstr.h"
 #include "cmemory.h"
+#include "patternprops.h"
+#include "digitlst.h"
 #include "cstring.h"
 #include "umutex.h"
 #include "uassert.h"
 #include "putilimp.h"
+#include <math.h>
+#include "hash.h"
+#include "decfmtst.h"
+#include "dcfmtimp.h"
+
+/*
+ * On certain platforms, round is a macro defined in math.h
+ * This undefine is to avoid conflict between the macro and
+ * the function defined below.
+ */
+#ifdef round
+#undef round
+#endif
 
 U_NAMESPACE_BEGIN
 
-//#define FMT_DEBUG
+
+/* == Fastpath calculation. ==
+ */
+#if UCONFIG_FORMAT_FASTPATHS_49
+inline DecimalFormatInternal& internalData(uint8_t *reserved) {
+  return *reinterpret_cast<DecimalFormatInternal*>(reserved);
+}
+inline const DecimalFormatInternal& internalData(const uint8_t *reserved) {
+  return *reinterpret_cast<const DecimalFormatInternal*>(reserved);
+}
+#else
+#endif
+
+/* For currency parsing purose,
+ * Need to remember all prefix patterns and suffix patterns of
+ * every currency format pattern,
+ * including the pattern of default currecny style
+ * and plural currency style. And the patterns are set through applyPattern.
+ */
+struct AffixPatternsForCurrency : public UMemory {
+       // negative prefix pattern
+       UnicodeString negPrefixPatternForCurrency;
+       // negative suffix pattern
+       UnicodeString negSuffixPatternForCurrency;
+       // positive prefix pattern
+       UnicodeString posPrefixPatternForCurrency;
+       // positive suffix pattern
+       UnicodeString posSuffixPatternForCurrency;
+       int8_t patternType;
+
+       AffixPatternsForCurrency(const UnicodeString& negPrefix,
+                                                        const UnicodeString& negSuffix,
+                                                        const UnicodeString& posPrefix,
+                                                        const UnicodeString& posSuffix,
+                                                        int8_t type) {
+               negPrefixPatternForCurrency = negPrefix;
+               negSuffixPatternForCurrency = negSuffix;
+               posPrefixPatternForCurrency = posPrefix;
+               posSuffixPatternForCurrency = posSuffix;
+               patternType = type;
+       }
+};
+
+/* affix for currency formatting when the currency sign in the pattern
+ * equals to 3, such as the pattern contains 3 currency sign or
+ * the formatter style is currency plural format style.
+ */
+struct AffixesForCurrency : public UMemory {
+       // negative prefix
+       UnicodeString negPrefixForCurrency;
+       // negative suffix
+       UnicodeString negSuffixForCurrency;
+       // positive prefix
+       UnicodeString posPrefixForCurrency;
+       // positive suffix
+       UnicodeString posSuffixForCurrency;
+
+       int32_t formatWidth;
+
+       AffixesForCurrency(const UnicodeString& negPrefix,
+                                          const UnicodeString& negSuffix,
+                                          const UnicodeString& posPrefix,
+                                          const UnicodeString& posSuffix) {
+               negPrefixForCurrency = negPrefix;
+               negSuffixForCurrency = negSuffix;
+               posPrefixForCurrency = posPrefix;
+               posSuffixForCurrency = posSuffix;
+       }
+};
+
+U_CDECL_BEGIN
+
+/**
+ * @internal ICU 4.2
+ */
+static UBool U_CALLCONV decimfmtAffixValueComparator(UHashTok val1, UHashTok val2);
+
+/**
+ * @internal ICU 4.2
+ */
+static UBool U_CALLCONV decimfmtAffixPatternValueComparator(UHashTok val1, UHashTok val2);
+
+
+static UBool
+U_CALLCONV decimfmtAffixValueComparator(UHashTok val1, UHashTok val2) {
+    const AffixesForCurrency* affix_1 =
+        (AffixesForCurrency*)val1.pointer;
+    const AffixesForCurrency* affix_2 =
+        (AffixesForCurrency*)val2.pointer;
+    return affix_1->negPrefixForCurrency == affix_2->negPrefixForCurrency &&
+           affix_1->negSuffixForCurrency == affix_2->negSuffixForCurrency &&
+           affix_1->posPrefixForCurrency == affix_2->posPrefixForCurrency &&
+           affix_1->posSuffixForCurrency == affix_2->posSuffixForCurrency;
+}
+
+
+static UBool
+U_CALLCONV decimfmtAffixPatternValueComparator(UHashTok val1, UHashTok val2) {
+    const AffixPatternsForCurrency* affix_1 =
+        (AffixPatternsForCurrency*)val1.pointer;
+    const AffixPatternsForCurrency* affix_2 =
+        (AffixPatternsForCurrency*)val2.pointer;
+    return affix_1->negPrefixPatternForCurrency ==
+           affix_2->negPrefixPatternForCurrency &&
+           affix_1->negSuffixPatternForCurrency ==
+           affix_2->negSuffixPatternForCurrency &&
+           affix_1->posPrefixPatternForCurrency ==
+           affix_2->posPrefixPatternForCurrency &&
+           affix_1->posSuffixPatternForCurrency ==
+           affix_2->posSuffixPatternForCurrency &&
+           affix_1->patternType == affix_2->patternType;
+}
+
+U_CDECL_END
 
 #ifdef FMT_DEBUG
 #include <stdio.h>
-static void debugout(UnicodeString s) {
+static void _debugout(const char *f, int l, const UnicodeString& s) {
     char buf[2000];
     s.extract((int32_t) 0, s.length(), buf);
-    printf("%s", buf);
+    printf("%s:%d: %s\n", f,l, buf);
 }
-#define debug(x) printf("%s", x);
+#define debugout(x) _debugout(__FILE__,__LINE__,x)
+#define debug(x) printf("%s:%d: %s\n", __FILE__,__LINE__, x);
+static const UnicodeString dbg_null("<NULL>","");
+#define DEREFSTR(x)   ((x!=NULL)?(*x):(dbg_null))
 #else
 #define debugout(x)
 #define debug(x)
 #endif
 
+
+
 // *****************************************************************************
 // class DecimalFormat
 // *****************************************************************************
@@ -114,33 +254,22 @@ const int32_t DecimalFormat::kMaxScientificIntegerDigits = 8;
  * These are the tags we expect to see in normal resource bundle files associated
  * with a locale.
  */
-const char DecimalFormat::fgNumberPatterns[]="NumberPatterns";
+const char DecimalFormat::fgNumberPatterns[]="NumberPatterns"; // Deprecated - not used
+static const char fgNumberElements[]="NumberElements";
+static const char fgLatn[]="latn";
+static const char fgPatterns[]="patterns";
+static const char fgDecimalFormat[]="decimalFormat";
+static const char fgCurrencyFormat[]="currencyFormat";
+static const UChar fgTripleCurrencySign[] = {0xA4, 0xA4, 0xA4, 0};
 
 inline int32_t _min(int32_t a, int32_t b) { return (a<b) ? a : b; }
 inline int32_t _max(int32_t a, int32_t b) { return (a<b) ? b : a; }
 
 //------------------------------------------------------------------------------
 // Constructs a DecimalFormat instance in the default locale.
-DecimalFormat::DecimalFormat(UErrorCode& status)
-: NumberFormat(), 
-  fPosPrefixPattern(0), 
-  fPosSuffixPattern(0), 
-  fNegPrefixPattern(0), 
-  fNegSuffixPattern(0),
-  fCurrencyChoice(0),
-  fMultiplier(0),
-  fGroupingSize(0),
-  fGroupingSize2(0),
-  fSymbols(0),
-  fUseSignificantDigits(FALSE),
-  fMinSignificantDigits(1),
-  fMaxSignificantDigits(6),
-  fMinExponentDigits(0),
-  fRoundingIncrement(0),
-  fPad(0),
-  fFormatWidth(0)
-{
+
+DecimalFormat::DecimalFormat(UErrorCode& status) {
+    init(status);
     UParseError parseError;
     construct(status, parseError);
 }
@@ -150,25 +279,8 @@ DecimalFormat::DecimalFormat(UErrorCode& status)
 // pattern in the default locale.
 
 DecimalFormat::DecimalFormat(const UnicodeString& pattern,
-                             UErrorCode& status)
-: NumberFormat(),
-  fPosPrefixPattern(0), 
-  fPosSuffixPattern(0), 
-  fNegPrefixPattern(0), 
-  fNegSuffixPattern(0),
-  fCurrencyChoice(0),
-  fMultiplier(0),
-  fGroupingSize(0),
-  fGroupingSize2(0),
-  fSymbols(0),
-  fUseSignificantDigits(FALSE),
-  fMinSignificantDigits(1),
-  fMaxSignificantDigits(6),
-  fMinExponentDigits(0),
-  fRoundingIncrement(0),
-  fPad(0),
-  fFormatWidth(0)
-{
+                             UErrorCode& status) {
+    init(status);
     UParseError parseError;
     construct(status, parseError, &pattern);
 }
@@ -180,87 +292,100 @@ DecimalFormat::DecimalFormat(const UnicodeString& pattern,
 
 DecimalFormat::DecimalFormat(const UnicodeString& pattern,
                              DecimalFormatSymbols* symbolsToAdopt,
-                             UErrorCode& status)
-: NumberFormat(),
-  fPosPrefixPattern(0), 
-  fPosSuffixPattern(0), 
-  fNegPrefixPattern(0), 
-  fNegSuffixPattern(0),
-  fCurrencyChoice(0),
-  fMultiplier(0),
-  fGroupingSize(0),
-  fGroupingSize2(0),
-  fSymbols(0),
-  fUseSignificantDigits(FALSE),
-  fMinSignificantDigits(1),
-  fMaxSignificantDigits(6),
-  fMinExponentDigits(0),
-  fRoundingIncrement(0),
-  fPad(0),
-  fFormatWidth(0)
-{
+                             UErrorCode& status) {
+    init(status);
     UParseError parseError;
     if (symbolsToAdopt == NULL)
         status = U_ILLEGAL_ARGUMENT_ERROR;
     construct(status, parseError, &pattern, symbolsToAdopt);
 }
+
 DecimalFormat::DecimalFormat(  const UnicodeString& pattern,
                     DecimalFormatSymbols* symbolsToAdopt,
                     UParseError& parseErr,
-                    UErrorCode& status)
-: NumberFormat(),
-  fPosPrefixPattern(0), 
-  fPosSuffixPattern(0), 
-  fNegPrefixPattern(0), 
-  fNegSuffixPattern(0),
-  fCurrencyChoice(0),
-  fMultiplier(0),
-  fGroupingSize(0),
-  fGroupingSize2(0),
-  fSymbols(0),
-  fUseSignificantDigits(FALSE),
-  fMinSignificantDigits(1),
-  fMaxSignificantDigits(6),
-  fMinExponentDigits(0),
-  fRoundingIncrement(0),
-  fPad(0),
-  fFormatWidth(0)
-{
+                    UErrorCode& status) {
+    init(status);
     if (symbolsToAdopt == NULL)
         status = U_ILLEGAL_ARGUMENT_ERROR;
     construct(status,parseErr, &pattern, symbolsToAdopt);
 }
+
 //------------------------------------------------------------------------------
 // Constructs a DecimalFormat instance with the specified number format
 // pattern and the number format symbols in the default locale.  The
 // created instance owns the clone of the symbols.
+
 DecimalFormat::DecimalFormat(const UnicodeString& pattern,
                              const DecimalFormatSymbols& symbols,
-                             UErrorCode& status)
-: NumberFormat(),
-  fPosPrefixPattern(0), 
-  fPosSuffixPattern(0), 
-  fNegPrefixPattern(0), 
-  fNegSuffixPattern(0),
-  fCurrencyChoice(0),
-  fMultiplier(0),
-  fGroupingSize(0),
-  fGroupingSize2(0),
-  fSymbols(0),
-  fUseSignificantDigits(FALSE),
-  fMinSignificantDigits(1),
-  fMaxSignificantDigits(6),
-  fMinExponentDigits(0),
-  fRoundingIncrement(0),
-  fPad(0),
-  fFormatWidth(0)
-{
+                             UErrorCode& status) {
+    init(status);
     UParseError parseError;
     construct(status, parseError, &pattern, new DecimalFormatSymbols(symbols));
 }
 
+//------------------------------------------------------------------------------
+// Constructs a DecimalFormat instance with the specified number format
+// pattern, the number format symbols, and the number format style.
+// The created instance owns the clone of the symbols.
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern,
+                             DecimalFormatSymbols* symbolsToAdopt,
+                             UNumberFormatStyle style,
+                             UErrorCode& status) {
+    init(status);
+    fStyle = style;
+    UParseError parseError;
+    construct(status, parseError, &pattern, symbolsToAdopt);
+}
+
+//-----------------------------------------------------------------------------
+// Common DecimalFormat initialization.
+//    Put all fields of an uninitialized object into a known state.
+//    Common code, shared by all constructors.
+void
+DecimalFormat::init(UErrorCode &status) {
+    fPosPrefixPattern = 0;
+    fPosSuffixPattern = 0;
+    fNegPrefixPattern = 0;
+    fNegSuffixPattern = 0;
+    fCurrencyChoice = 0;
+    fMultiplier = NULL;
+    fScale = 0;
+    fGroupingSize = 0;
+    fGroupingSize2 = 0;
+    fDecimalSeparatorAlwaysShown = FALSE;
+    fSymbols = NULL;
+    fUseSignificantDigits = FALSE;
+    fMinSignificantDigits = 1;
+    fMaxSignificantDigits = 6;
+    fUseExponentialNotation = FALSE;
+    fMinExponentDigits = 0;
+    fExponentSignAlwaysShown = FALSE;
+    fBoolFlags.clear();
+    fRoundingIncrement = 0;
+    fRoundingMode = kRoundHalfEven;
+    fPad = 0;
+    fFormatWidth = 0;
+    fPadPosition = kPadBeforePrefix;
+    fStyle = UNUM_DECIMAL;
+    fCurrencySignCount = 0;
+    fAffixPatternsForCurrency = NULL;
+    fAffixesForCurrency = NULL;
+    fPluralAffixesForCurrency = NULL;
+    fCurrencyPluralInfo = NULL;
+#if UCONFIG_HAVE_PARSEALLINPUT
+    fParseAllInput = UNUM_MAYBE;
+#endif
+
+#if UCONFIG_FORMAT_FASTPATHS_49
+    DecimalFormatInternal &data = internalData(fReserved);
+    data.fFastFormatStatus=kFastpathUNKNOWN; // don't try to calculate the fastpath until later.
+    data.fFastParseStatus=kFastpathUNKNOWN; // don't try to calculate the fastpath until later.
+#endif
+    // only do this once per obj.
+    DecimalFormatStaticSets::initSets(&status);
+}
+
 //------------------------------------------------------------------------------
 // Constructs a DecimalFormat instance with the specified number format
 // pattern and the number format symbols in the desired locale.  The
@@ -273,9 +398,7 @@ DecimalFormat::construct(UErrorCode&             status,
                          DecimalFormatSymbols*  symbolsToAdopt)
 {
     fSymbols = symbolsToAdopt; // Do this BEFORE aborting on status failure!!!
-//    fDigitList = new DigitList(); // Do this BEFORE aborting on status failure!!!
     fRoundingIncrement = NULL;
-    fRoundingDouble = 0.0;
     fRoundingMode = kRoundHalfEven;
     fPad = kPatternPadEscape;
     fPadPosition = kPadBeforePrefix;
@@ -284,11 +407,10 @@ DecimalFormat::construct(UErrorCode&             status,
 
     fPosPrefixPattern = fPosSuffixPattern = NULL;
     fNegPrefixPattern = fNegSuffixPattern = NULL;
-    fMultiplier = 1;
+    setMultiplier(1);
     fGroupingSize = 3;
     fGroupingSize2 = 0;
     fDecimalSeparatorAlwaysShown = FALSE;
-    fIsCurrencyFormat = FALSE;
     fUseExponentialNotation = FALSE;
     fMinExponentDigits = 0;
 
@@ -301,6 +423,12 @@ DecimalFormat::construct(UErrorCode&             status,
             return;
         }
     }
+    UErrorCode nsStatus = U_ZERO_ERROR;
+    NumberingSystem *ns = NumberingSystem::createInstance(nsStatus);
+    if (U_FAILURE(nsStatus)) {
+        status = nsStatus;
+        return;
+    }
 
     UnicodeString str;
     // Uses the default locale's number format pattern if there isn't
@@ -308,15 +436,27 @@ DecimalFormat::construct(UErrorCode&             status,
     if (pattern == NULL)
     {
         int32_t len = 0;
-        UResourceBundle *resource = ures_open(NULL, Locale::getDefault().getName(), &status);
-
-        resource = ures_getByKey(resource, fgNumberPatterns, resource, &status);
-        const UChar *resStr = ures_getStringByIndex(resource, (int32_t)0, &len, &status);
+        UResourceBundle *top = ures_open(NULL, Locale::getDefault().getName(), &status);
+
+        UResourceBundle *resource = ures_getByKeyWithFallback(top, fgNumberElements, NULL, &status);
+        resource = ures_getByKeyWithFallback(resource, ns->getName(), resource, &status);
+        resource = ures_getByKeyWithFallback(resource, fgPatterns, resource, &status);
+        const UChar *resStr = ures_getStringByKeyWithFallback(resource, fgDecimalFormat, &len, &status);
+        if ( status == U_MISSING_RESOURCE_ERROR && uprv_strcmp(fgLatn,ns->getName())) {
+            status = U_ZERO_ERROR;
+            resource = ures_getByKeyWithFallback(top, fgNumberElements, resource, &status);
+            resource = ures_getByKeyWithFallback(resource, fgLatn, resource, &status);
+            resource = ures_getByKeyWithFallback(resource, fgPatterns, resource, &status);
+            resStr = ures_getStringByKeyWithFallback(resource, fgDecimalFormat, &len, &status);
+        }
         str.setTo(TRUE, resStr, len);
         pattern = &str;
         ures_close(resource);
+        ures_close(top);
     }
 
+    delete ns;
+
     if (U_FAILURE(status))
     {
         return;
@@ -327,62 +467,261 @@ DecimalFormat::construct(UErrorCode&             status,
         // then do the time consuming lookup.
         setCurrencyForSymbols();
     } else {
-        setCurrency(NULL, status);
+        setCurrencyInternally(NULL, status);
+    }
+
+    const UnicodeString* patternUsed;
+    UnicodeString currencyPluralPatternForOther;
+    // apply pattern
+    if (fStyle == UNUM_CURRENCY_PLURAL) {
+        fCurrencyPluralInfo = new CurrencyPluralInfo(fSymbols->getLocale(), status);
+        if (U_FAILURE(status)) {
+            return;
+        }
+
+        // the pattern used in format is not fixed until formatting,
+        // in which, the number is known and
+        // will be used to pick the right pattern based on plural count.
+        // Here, set the pattern as the pattern of plural count == "other".
+        // For most locale, the patterns are probably the same for all
+        // plural count. If not, the right pattern need to be re-applied
+        // during format.
+        fCurrencyPluralInfo->getCurrencyPluralPattern(UNICODE_STRING("other", 5), currencyPluralPatternForOther);
+        patternUsed = &currencyPluralPatternForOther;
+        // TODO: not needed?
+        setCurrencyForSymbols();
+
+    } else {
+        patternUsed = pattern;
+    }
+
+    if (patternUsed->indexOf(kCurrencySign) != -1) {
+        // initialize for currency, not only for plural format,
+        // but also for mix parsing
+        if (fCurrencyPluralInfo == NULL) {
+           fCurrencyPluralInfo = new CurrencyPluralInfo(fSymbols->getLocale(), status);
+           if (U_FAILURE(status)) {
+               return;
+           }
+        }
+        // need it for mix parsing
+        setupCurrencyAffixPatterns(status);
+        // expanded affixes for plural names
+        if (patternUsed->indexOf(fgTripleCurrencySign, 3, 0) != -1) {
+            setupCurrencyAffixes(*patternUsed, TRUE, TRUE, status);
+        }
+    }
+
+    applyPatternWithoutExpandAffix(*patternUsed,FALSE, parseErr, status);
+
+    // expand affixes
+    if (fCurrencySignCount != fgCurrencySignCountInPluralFormat) {
+        expandAffixAdjustWidth(NULL);
     }
 
-    applyPattern(*pattern, FALSE /*not localized*/,parseErr, status);
-    
     // If it was a currency format, apply the appropriate rounding by
     // resetting the currency. NOTE: this copies fCurrency on top of itself.
-    if (fIsCurrencyFormat) {
-        setCurrency(getCurrency(), status);
+    if (fCurrencySignCount > fgCurrencySignCountZero) {
+        setCurrencyInternally(getCurrency(), status);
+    }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    DecimalFormatInternal &data = internalData(fReserved);
+    data.fFastFormatStatus = kFastpathNO; // allow it to be calculated
+    data.fFastParseStatus = kFastpathNO; // allow it to be calculated
+    handleChanged();
+#endif
+}
+
+
+void
+DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
+    if (U_FAILURE(status)) {
+        return;
+    }
+    UParseError parseErr;
+    fAffixPatternsForCurrency = initHashForAffixPattern(status);
+    if (U_FAILURE(status)) {
+        return;
+    }
+
+    NumberingSystem *ns = NumberingSystem::createInstance(fSymbols->getLocale(),status);
+    if (U_FAILURE(status)) {
+        return;
+    }
+
+    // Save the default currency patterns of this locale.
+    // Here, chose onlyApplyPatternWithoutExpandAffix without
+    // expanding the affix patterns into affixes.
+    UnicodeString currencyPattern;
+    UErrorCode error = U_ZERO_ERROR;   
+    
+    UResourceBundle *resource = ures_open(NULL, fSymbols->getLocale().getName(), &error);
+    UResourceBundle *numElements = ures_getByKeyWithFallback(resource, fgNumberElements, NULL, &error);
+    resource = ures_getByKeyWithFallback(numElements, ns->getName(), resource, &error);
+    resource = ures_getByKeyWithFallback(resource, fgPatterns, resource, &error);
+    int32_t patLen = 0;
+    const UChar *patResStr = ures_getStringByKeyWithFallback(resource, fgCurrencyFormat,  &patLen, &error);
+    if ( error == U_MISSING_RESOURCE_ERROR && uprv_strcmp(ns->getName(),fgLatn)) {
+        error = U_ZERO_ERROR;
+        resource = ures_getByKeyWithFallback(numElements, fgLatn, resource, &error);
+        resource = ures_getByKeyWithFallback(resource, fgPatterns, resource, &error);
+        patResStr = ures_getStringByKeyWithFallback(resource, fgCurrencyFormat,  &patLen, &error);
+    }
+    ures_close(numElements);
+    ures_close(resource);
+    delete ns;
+
+    if (U_SUCCESS(error)) {
+        applyPatternWithoutExpandAffix(UnicodeString(patResStr, patLen), false,
+                                       parseErr, status);
+        AffixPatternsForCurrency* affixPtn = new AffixPatternsForCurrency(
+                                                    *fNegPrefixPattern,
+                                                    *fNegSuffixPattern,
+                                                    *fPosPrefixPattern,
+                                                    *fPosSuffixPattern,
+                                                    UCURR_SYMBOL_NAME);
+        fAffixPatternsForCurrency->put(UNICODE_STRING("default", 7), affixPtn, status);
+    }
+
+    // save the unique currency plural patterns of this locale.
+    Hashtable* pluralPtn = fCurrencyPluralInfo->fPluralCountToCurrencyUnitPattern;
+    const UHashElement* element = NULL;
+    int32_t pos = -1;
+    Hashtable pluralPatternSet;
+    while ((element = pluralPtn->nextElement(pos)) != NULL) {
+        const UHashTok valueTok = element->value;
+        const UnicodeString* value = (UnicodeString*)valueTok.pointer;
+        const UHashTok keyTok = element->key;
+        const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+        if (pluralPatternSet.geti(*value) != 1) {
+            pluralPatternSet.puti(*value, 1, status);
+            applyPatternWithoutExpandAffix(*value, false, parseErr, status);
+            AffixPatternsForCurrency* affixPtn = new AffixPatternsForCurrency(
+                                                    *fNegPrefixPattern,
+                                                    *fNegSuffixPattern,
+                                                    *fPosPrefixPattern,
+                                                    *fPosSuffixPattern,
+                                                    UCURR_LONG_NAME);
+            fAffixPatternsForCurrency->put(*key, affixPtn, status);
+        }
     }
 }
 
+
+void
+DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
+                                    UBool setupForCurrentPattern,
+                                    UBool setupForPluralPattern,
+                                    UErrorCode& status) {
+    if (U_FAILURE(status)) {
+        return;
+    }
+    UParseError parseErr;
+    if (setupForCurrentPattern) {
+        if (fAffixesForCurrency) {
+            deleteHashForAffix(fAffixesForCurrency);
+        }
+        fAffixesForCurrency = initHashForAffix(status);
+        if (U_SUCCESS(status)) {
+            applyPatternWithoutExpandAffix(pattern, false, parseErr, status);
+            const PluralRules* pluralRules = fCurrencyPluralInfo->getPluralRules();
+            StringEnumeration* keywords = pluralRules->getKeywords(status);
+            if (U_SUCCESS(status)) {
+                const UnicodeString* pluralCount;
+                while ((pluralCount = keywords->snext(status)) != NULL) {
+                    if ( U_SUCCESS(status) ) {
+                        expandAffixAdjustWidth(pluralCount);
+                        AffixesForCurrency* affix = new AffixesForCurrency(
+                            fNegativePrefix, fNegativeSuffix, fPositivePrefix, fPositiveSuffix);
+                        fAffixesForCurrency->put(*pluralCount, affix, status);
+                    }
+                }
+            }
+            delete keywords;
+        }
+    }
+
+    if (U_FAILURE(status)) {
+        return;
+    }
+
+    if (setupForPluralPattern) {
+        if (fPluralAffixesForCurrency) {
+            deleteHashForAffix(fPluralAffixesForCurrency);
+        }
+        fPluralAffixesForCurrency = initHashForAffix(status);
+        if (U_SUCCESS(status)) {
+            const PluralRules* pluralRules = fCurrencyPluralInfo->getPluralRules();
+            StringEnumeration* keywords = pluralRules->getKeywords(status);
+            if (U_SUCCESS(status)) {
+                const UnicodeString* pluralCount;
+                while ((pluralCount = keywords->snext(status)) != NULL) {
+                    if ( U_SUCCESS(status) ) {
+                        UnicodeString ptn;
+                        fCurrencyPluralInfo->getCurrencyPluralPattern(*pluralCount, ptn);
+                        applyPatternInternally(*pluralCount, ptn, false, parseErr, status);
+                        AffixesForCurrency* affix = new AffixesForCurrency(
+                            fNegativePrefix, fNegativeSuffix, fPositivePrefix, fPositiveSuffix);
+                        fPluralAffixesForCurrency->put(*pluralCount, affix, status);
+                    }
+                }
+            }
+            delete keywords;
+        }
+    }
+}
+
+
 //------------------------------------------------------------------------------
 
 DecimalFormat::~DecimalFormat()
 {
-//    delete fDigitList;
     delete fPosPrefixPattern;
     delete fPosSuffixPattern;
     delete fNegPrefixPattern;
     delete fNegSuffixPattern;
     delete fCurrencyChoice;
+    delete fMultiplier;
     delete fSymbols;
     delete fRoundingIncrement;
+    deleteHashForAffixPattern();
+    deleteHashForAffix(fAffixesForCurrency);
+    deleteHashForAffix(fPluralAffixesForCurrency);
+    delete fCurrencyPluralInfo;
 }
 
 //------------------------------------------------------------------------------
 // copy constructor
 
-DecimalFormat::DecimalFormat(const DecimalFormat &source)
-:   NumberFormat(source),
-//    fDigitList(NULL),
-    fPosPrefixPattern(NULL),
-    fPosSuffixPattern(NULL),
-    fNegPrefixPattern(NULL),
-    fNegSuffixPattern(NULL),
-    fCurrencyChoice(NULL),
-    fSymbols(NULL),
-    fRoundingIncrement(NULL)
-{
+DecimalFormat::DecimalFormat(const DecimalFormat &source) :
+    NumberFormat(source) {
+    UErrorCode status = U_ZERO_ERROR;
+    init(status); // if this fails, 'source' isn't initialized properly either.
     *this = source;
 }
 
 //------------------------------------------------------------------------------
 // assignment operator
-// Note that fDigitList is not considered a significant part of the
-// DecimalFormat because it's used as a buffer to process the numbers.
 
-static void _copy_us_ptr(UnicodeString** pdest, const UnicodeString* source) {
+template <class T>
+static void _copy_ptr(T** pdest, const T* source) {
     if (source == NULL) {
         delete *pdest;
         *pdest = NULL;
     } else if (*pdest == NULL) {
-        *pdest = new UnicodeString(*source);
+        *pdest = new T(*source);
     } else {
-        **pdest  = *source;
+        **pdest = *source;
+    }
+}
+
+template <class T>
+static void _clone_ptr(T** pdest, const T* source) {
+    delete *pdest;
+    if (source == NULL) {
+        *pdest = NULL;
+    } else {
+        *pdest = static_cast<T*>(source->clone());
     }
 }
 
@@ -395,46 +734,26 @@ DecimalFormat::operator=(const DecimalFormat& rhs)
         fPositiveSuffix = rhs.fPositiveSuffix;
         fNegativePrefix = rhs.fNegativePrefix;
         fNegativeSuffix = rhs.fNegativeSuffix;
-        _copy_us_ptr(&fPosPrefixPattern, rhs.fPosPrefixPattern);
-        _copy_us_ptr(&fPosSuffixPattern, rhs.fPosSuffixPattern);
-        _copy_us_ptr(&fNegPrefixPattern, rhs.fNegPrefixPattern);
-        _copy_us_ptr(&fNegSuffixPattern, rhs.fNegSuffixPattern);
-        if (rhs.fCurrencyChoice == 0) {
-            delete fCurrencyChoice;
-            fCurrencyChoice = 0;
-        } else {
-            fCurrencyChoice = (ChoiceFormat*) rhs.fCurrencyChoice->clone();
-        }
-        if(rhs.fRoundingIncrement == NULL) {
-            delete fRoundingIncrement;
-            fRoundingIncrement = NULL;
-        } 
-        else if(fRoundingIncrement == NULL) {
-            fRoundingIncrement = new DigitList(*rhs.fRoundingIncrement);
-        }
-        else {
-            *fRoundingIncrement = *rhs.fRoundingIncrement;
-        }
-        fRoundingDouble = rhs.fRoundingDouble;
+        _copy_ptr(&fPosPrefixPattern, rhs.fPosPrefixPattern);
+        _copy_ptr(&fPosSuffixPattern, rhs.fPosSuffixPattern);
+        _copy_ptr(&fNegPrefixPattern, rhs.fNegPrefixPattern);
+        _copy_ptr(&fNegSuffixPattern, rhs.fNegSuffixPattern);
+        _clone_ptr(&fCurrencyChoice, rhs.fCurrencyChoice);
+        setRoundingIncrement(rhs.getRoundingIncrement());
         fRoundingMode = rhs.fRoundingMode;
-        fMultiplier = rhs.fMultiplier;
+        setMultiplier(rhs.getMultiplier());
         fGroupingSize = rhs.fGroupingSize;
         fGroupingSize2 = rhs.fGroupingSize2;
         fDecimalSeparatorAlwaysShown = rhs.fDecimalSeparatorAlwaysShown;
-        if(fSymbols == NULL) {
-            fSymbols = new DecimalFormatSymbols(*rhs.fSymbols);
-        } else {
-            *fSymbols = *rhs.fSymbols;
-        }
+        _copy_ptr(&fSymbols, rhs.fSymbols);
         fUseExponentialNotation = rhs.fUseExponentialNotation;
         fExponentSignAlwaysShown = rhs.fExponentSignAlwaysShown;
+        fBoolFlags = rhs.fBoolFlags;
         /*Bertrand A. D. Update 98.03.17*/
-        fIsCurrencyFormat = rhs.fIsCurrencyFormat;
+        fCurrencySignCount = rhs.fCurrencySignCount;
         /*end of Update*/
         fMinExponentDigits = rhs.fMinExponentDigits;
-        //    if (fDigitList == NULL)
-        //        fDigitList = new DigitList();
-    
+
         /* sfb 990629 */
         fFormatWidth = rhs.fFormatWidth;
         fPad = rhs.fPad;
@@ -443,7 +762,33 @@ DecimalFormat::operator=(const DecimalFormat& rhs)
         fMinSignificantDigits = rhs.fMinSignificantDigits;
         fMaxSignificantDigits = rhs.fMaxSignificantDigits;
         fUseSignificantDigits = rhs.fUseSignificantDigits;
+        fFormatPattern = rhs.fFormatPattern;
+        fStyle = rhs.fStyle;
+        fCurrencySignCount = rhs.fCurrencySignCount;
+        _clone_ptr(&fCurrencyPluralInfo, rhs.fCurrencyPluralInfo);
+        deleteHashForAffixPattern();
+        if (rhs.fAffixPatternsForCurrency) {
+            UErrorCode status = U_ZERO_ERROR;
+            fAffixPatternsForCurrency = initHashForAffixPattern(status);
+            copyHashForAffixPattern(rhs.fAffixPatternsForCurrency,
+                                    fAffixPatternsForCurrency, status);
+        }
+        deleteHashForAffix(fAffixesForCurrency);
+        if (rhs.fAffixesForCurrency) {
+            UErrorCode status = U_ZERO_ERROR;
+            fAffixesForCurrency = initHashForAffixPattern(status);
+            copyHashForAffix(rhs.fAffixesForCurrency, fAffixesForCurrency, status);
+        }
+        deleteHashForAffix(fPluralAffixesForCurrency);
+        if (rhs.fPluralAffixesForCurrency) {
+            UErrorCode status = U_ZERO_ERROR;
+            fPluralAffixesForCurrency = initHashForAffixPattern(status);
+            copyHashForAffix(rhs.fPluralAffixesForCurrency, fPluralAffixesForCurrency, status);
+        }
     }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
     return *this;
 }
 
@@ -465,7 +810,7 @@ DecimalFormat::operator==(const Format& that) const
     if (!NumberFormat::operator==(that)) {
         if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
         debug("NumberFormat::!=");
-    }
+    } else {
     if (!((fPosPrefixPattern == other->fPosPrefixPattern && // both null
               fPositivePrefix == other->fPositivePrefix)
            || (fPosPrefixPattern != 0 && other->fPosPrefixPattern != 0 &&
@@ -531,9 +876,9 @@ DecimalFormat::operator==(const Format& that) const
         if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
         debug("Rounding Increment !=");
               }
-    if (fMultiplier != other->fMultiplier) {
+    if (getMultiplier() != other->getMultiplier()) {
         if (first) { printf("[ "); first = FALSE; }
-        printf("Multiplier %ld != %ld", fMultiplier, other->fMultiplier);
+        printf("Multiplier %ld != %ld", getMultiplier(), other->getMultiplier());
     }
     if (fGroupingSize != other->fGroupingSize) {
         if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
@@ -561,11 +906,46 @@ DecimalFormat::operator==(const Format& that) const
         debug("Symbols !=");
     }
     // TODO Add debug stuff for significant digits here
+    if (fUseSignificantDigits != other->fUseSignificantDigits) {
+        debug("fUseSignificantDigits !=");
+    }
+    if (fUseSignificantDigits &&
+        fMinSignificantDigits != other->fMinSignificantDigits) {
+        debug("fMinSignificantDigits !=");
+    }
+    if (fUseSignificantDigits &&
+        fMaxSignificantDigits != other->fMaxSignificantDigits) {
+        debug("fMaxSignificantDigits !=");
+    }
+
     if (!first) { printf(" ]"); }
+    if (fCurrencySignCount != other->fCurrencySignCount) {
+        debug("fCurrencySignCount !=");
+    }
+    if (fCurrencyPluralInfo == other->fCurrencyPluralInfo) {
+        debug("fCurrencyPluralInfo == ");
+        if (fCurrencyPluralInfo == NULL) {
+            debug("fCurrencyPluralInfo == NULL");
+        }
+    }
+    if (fCurrencyPluralInfo != NULL && other->fCurrencyPluralInfo != NULL &&
+         *fCurrencyPluralInfo != *(other->fCurrencyPluralInfo)) {
+        debug("fCurrencyPluralInfo !=");
+    }
+    if (fCurrencyPluralInfo != NULL && other->fCurrencyPluralInfo == NULL ||
+        fCurrencyPluralInfo == NULL && other->fCurrencyPluralInfo != NULL) {
+        debug("fCurrencyPluralInfo one NULL, the other not");
+    }
+    if (fCurrencyPluralInfo == NULL && other->fCurrencyPluralInfo == NULL) {
+        debug("fCurrencyPluralInfo == ");
+    }
+    }
 #endif
 
     return (NumberFormat::operator==(that) &&
-            ((fPosPrefixPattern == other->fPosPrefixPattern && // both null
+            ((fCurrencySignCount == fgCurrencySignCountInPluralFormat) ?
+            (fAffixPatternsForCurrency->equals(*other->fAffixPatternsForCurrency)) :
+            (((fPosPrefixPattern == other->fPosPrefixPattern && // both null
               fPositivePrefix == other->fPositivePrefix)
              || (fPosPrefixPattern != 0 && other->fPosPrefixPattern != 0 &&
                  *fPosPrefixPattern  == *other->fPosPrefixPattern)) &&
@@ -580,12 +960,12 @@ DecimalFormat::operator==(const Format& that) const
             ((fNegSuffixPattern == other->fNegSuffixPattern && // both null
               fNegativeSuffix == other->fNegativeSuffix)
              || (fNegSuffixPattern != 0 && other->fNegSuffixPattern != 0 &&
-                 *fNegSuffixPattern  == *other->fNegSuffixPattern)) &&
+                 *fNegSuffixPattern  == *other->fNegSuffixPattern)))) &&
             ((fRoundingIncrement == other->fRoundingIncrement) // both null
              || (fRoundingIncrement != NULL &&
                  other->fRoundingIncrement != NULL &&
                  *fRoundingIncrement == *other->fRoundingIncrement)) &&
-        fMultiplier == other->fMultiplier &&
+        getMultiplier() == other->getMultiplier() &&
         fGroupingSize == other->fGroupingSize &&
         fGroupingSize2 == other->fGroupingSize2 &&
         fDecimalSeparatorAlwaysShown == other->fDecimalSeparatorAlwaysShown &&
@@ -596,7 +976,12 @@ DecimalFormat::operator==(const Format& that) const
         fUseSignificantDigits == other->fUseSignificantDigits &&
         (!fUseSignificantDigits ||
          (fMinSignificantDigits == other->fMinSignificantDigits &&
-          fMaxSignificantDigits == other->fMaxSignificantDigits)));
+          fMaxSignificantDigits == other->fMaxSignificantDigits)) &&
+        fCurrencySignCount == other->fCurrencySignCount &&
+        ((fCurrencyPluralInfo == other->fCurrencyPluralInfo &&
+          fCurrencyPluralInfo == NULL) ||
+         (fCurrencyPluralInfo != NULL && other->fCurrencyPluralInfo != NULL &&
+         *fCurrencyPluralInfo == *(other->fCurrencyPluralInfo))));
 }
 
 //------------------------------------------------------------------------------
@@ -608,7 +993,7 @@ DecimalFormat::clone() const
 }
 
 //------------------------------------------------------------------------------
+
 UnicodeString&
 DecimalFormat::format(int32_t number,
                       UnicodeString& appendTo,
@@ -617,44 +1002,215 @@ DecimalFormat::format(int32_t number,
     return format((int64_t)number, appendTo, fieldPosition);
 }
 
+UnicodeString&
+DecimalFormat::format(int32_t number,
+                      UnicodeString& appendTo,
+                      FieldPosition& fieldPosition,
+                      UErrorCode& status) const
+{
+    return format((int64_t)number, appendTo, fieldPosition, status);
+}
+
+UnicodeString&
+DecimalFormat::format(int32_t number,
+                      UnicodeString& appendTo,
+                      FieldPositionIterator* posIter,
+                      UErrorCode& status) const
+{
+    return format((int64_t)number, appendTo, posIter, status);
+}
+
+
+#if UCONFIG_FORMAT_FASTPATHS_49
+void DecimalFormat::handleChanged() {
+  DecimalFormatInternal &data = internalData(fReserved);
+
+  if(data.fFastFormatStatus == kFastpathUNKNOWN || data.fFastParseStatus == kFastpathUNKNOWN) {
+    return; // still constructing. Wait.
+  }
+
+  data.fFastParseStatus = data.fFastFormatStatus = kFastpathNO;
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+  if(fParseAllInput == UNUM_NO) {
+    debug("No Parse fastpath: fParseAllInput==UNUM_NO");
+  } else 
+#endif
+  if (fFormatWidth!=0) {
+      debug("No Parse fastpath: fFormatWidth");
+  } else if(fPositivePrefix.length()>0) {
+    debug("No Parse fastpath: positive prefix");
+  } else if(fPositiveSuffix.length()>0) {
+    debug("No Parse fastpath: positive suffix");
+  } else if(fNegativePrefix.length()>1 
+            || ((fNegativePrefix.length()==1) && (fNegativePrefix.charAt(0)!=0x002D))) {
+    debug("No Parse fastpath: negative prefix that isn't '-'");
+  } else if(fNegativeSuffix.length()>0) {
+    debug("No Parse fastpath: negative suffix");
+  } else {
+    data.fFastParseStatus = kFastpathYES;
+    debug("parse fastpath: YES");
+  }
+  
+  if (fGroupingSize!=0 && isGroupingUsed()) {
+    debug("No format fastpath: fGroupingSize!=0 and grouping is used");
+#ifdef FMT_DEBUG
+    printf("groupingsize=%d\n", fGroupingSize);
+#endif
+  } else if(fGroupingSize2!=0 && isGroupingUsed()) {
+    debug("No format fastpath: fGroupingSize2!=0");
+  } else if(fUseExponentialNotation) {
+    debug("No format fastpath: fUseExponentialNotation");
+  } else if(fFormatWidth!=0) {
+    debug("No format fastpath: fFormatWidth!=0");
+  } else if(fMinSignificantDigits!=1) {
+    debug("No format fastpath: fMinSignificantDigits!=1");
+  } else if(fMultiplier!=NULL) {
+    debug("No format fastpath: fMultiplier!=NULL");
+  } else if(fScale!=0) {
+    debug("No format fastpath: fScale!=0");
+  } else if(0x0030 != getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0)) {
+    debug("No format fastpath: 0x0030 != getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0)");
+  } else if(fDecimalSeparatorAlwaysShown) {
+    debug("No format fastpath: fDecimalSeparatorAlwaysShown");
+  } else if(getMinimumFractionDigits()>0) {
+    debug("No format fastpath: fMinFractionDigits>0");
+  } else if(fCurrencySignCount > fgCurrencySignCountZero) {
+    debug("No format fastpath: fCurrencySignCount > fgCurrencySignCountZero");
+  } else if(fRoundingIncrement!=0) {
+    debug("No format fastpath: fRoundingIncrement!=0");
+  } else {
+    data.fFastFormatStatus = kFastpathYES;
+    debug("format:kFastpathYES!");
+  }
+
+
+}
+#endif
 //------------------------------------------------------------------------------
+
 UnicodeString&
 DecimalFormat::format(int64_t number,
                       UnicodeString& appendTo,
                       FieldPosition& fieldPosition) const
 {
-    DigitList digits;
+    UErrorCode status = U_ZERO_ERROR; /* ignored */
+    FieldPositionOnlyHandler handler(fieldPosition);
+    return _format(number, appendTo, handler, status);
+}
 
-    // Clears field positions.
-    fieldPosition.setBeginIndex(0);
-    fieldPosition.setEndIndex(0);
-
-    // If we are to do rounding, we need to move into the BigDecimal
-    // domain in order to do divide/multiply correctly.
-    // ||
-    // In general, long values always represent real finite numbers, so
-    // we don't have to check for +/- Infinity or NaN.  However, there
-    // is one case we have to be careful of:  The multiplier can push
-    // a number near MIN_VALUE or MAX_VALUE outside the legal range.  We
-    // check for this before multiplying, and if it happens we use doubles
-    // instead, trading off accuracy for range.
-    if (fRoundingIncrement != NULL
-        || (fMultiplier != 0 && (number > (U_INT64_MAX / fMultiplier)
-                              || number < (U_INT64_MIN / fMultiplier))))
-    {
-        digits.set(((double)number) * fMultiplier,
-                   precision(FALSE),
-                   !fUseExponentialNotation && !areSignificantDigitsUsed());
+UnicodeString&
+DecimalFormat::format(int64_t number,
+                      UnicodeString& appendTo,
+                      FieldPosition& fieldPosition,
+                      UErrorCode& status) const
+{
+    FieldPositionOnlyHandler handler(fieldPosition);
+    return _format(number, appendTo, handler, status);
+}
+
+UnicodeString&
+DecimalFormat::format(int64_t number,
+                      UnicodeString& appendTo,
+                      FieldPositionIterator* posIter,
+                      UErrorCode& status) const
+{
+    FieldPositionIteratorHandler handler(posIter, status);
+    return _format(number, appendTo, handler, status);
+}
+
+UnicodeString&
+DecimalFormat::_format(int64_t number,
+                       UnicodeString& appendTo,
+                       FieldPositionHandler& handler,
+                       UErrorCode &status) const
+{
+    // Bottleneck function for formatting int64_t
+    if (U_FAILURE(status)) {
+        return appendTo;
     }
-    else
-    {
-        digits.set(number * fMultiplier, precision(TRUE));
+
+#if UCONFIG_FORMAT_FASTPATHS_49
+  // const UnicodeString *posPrefix = fPosPrefixPattern;
+  // const UnicodeString *posSuffix = fPosSuffixPattern;
+  // const UnicodeString *negSuffix = fNegSuffixPattern;
+
+  const DecimalFormatInternal &data = internalData(fReserved);
+
+#ifdef FMT_DEBUG
+  data.dump();
+  printf("fastpath? [%d]\n", number);
+#endif
+    
+  if( data.fFastFormatStatus==kFastpathYES) {
+
+#define kZero 0x0030
+    const int32_t MAX_IDX = MAX_DIGITS+2;
+    UChar outputStr[MAX_IDX];
+    int32_t destIdx = MAX_IDX;
+    outputStr[--destIdx] = 0;  // term
+
+    int64_t  n = number;
+    if (number < 1) {
+      // Negative numbers are slightly larger than positive
+      // output the first digit (or the leading zero)
+      outputStr[--destIdx] = (-(n % 10) + kZero);
+      n /= -10;
+    }
+    // get any remaining digits
+    while (n > 0) {
+      outputStr[--destIdx] = (n % 10) + kZero;
+      n /= 10;
+    }
+    
+
+        // Slide the number to the start of the output str
+    U_ASSERT(destIdx >= 0);
+    int32_t length = MAX_IDX - destIdx -1;
+    /*int32_t prefixLen = */ appendAffix(appendTo, number, handler, number<0, TRUE);
+    int32_t maxIntDig = getMaximumIntegerDigits();
+    int32_t destlength = length<=maxIntDig?length:maxIntDig; // dest length pinned to max int digits
+
+    if(length>maxIntDig && fBoolFlags.contains(UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS)) {
+      status = U_ILLEGAL_ARGUMENT_ERROR;
+    }
+
+    int32_t prependZero = getMinimumIntegerDigits() - destlength;
+
+#ifdef FMT_DEBUG
+    printf("prependZero=%d, length=%d, minintdig=%d maxintdig=%d destlength=%d skip=%d\n", prependZero, length, getMinimumIntegerDigits(), maxIntDig, destlength, length-destlength);
+#endif    
+    int32_t intBegin = appendTo.length();
+
+    while((prependZero--)>0) {
+      appendTo.append((UChar)0x0030); // '0'
     }
 
-    return subformat(appendTo, fieldPosition, digits, TRUE);
+    appendTo.append(outputStr+destIdx+
+                    (length-destlength), // skip any leading digits
+                    destlength);
+    handler.addAttribute(kIntegerField, intBegin, appendTo.length());
+
+    /*int32_t suffixLen =*/ appendAffix(appendTo, number, handler, number<0, FALSE);
+
+    //outputStr[length]=0;
+    
+#ifdef FMT_DEBUG
+        printf("Writing [%s] length [%d] max %d for [%d]\n", outputStr+destIdx, length, MAX_IDX, number);
+#endif
+
+#undef kZero
+
+    return appendTo;
+  } // end fastpath
+#endif
+
+  // Else the slow way - via DigitList
+    DigitList digits;
+    digits.set(number);
+    return _format(digits, appendTo, handler, status);
 }
+
 //------------------------------------------------------------------------------
 
 UnicodeString&
@@ -662,120 +1218,278 @@ DecimalFormat::format(  double number,
                         UnicodeString& appendTo,
                         FieldPosition& fieldPosition) const
 {
-    // Clears field positions.
-    fieldPosition.setBeginIndex(0);
-    fieldPosition.setEndIndex(0);
+    UErrorCode status = U_ZERO_ERROR; /* ignored */
+    FieldPositionOnlyHandler handler(fieldPosition);
+    return _format(number, appendTo, handler, status);
+}
+
+UnicodeString&
+DecimalFormat::format(  double number,
+                        UnicodeString& appendTo,
+                        FieldPosition& fieldPosition,
+                        UErrorCode& status) const
+{
+    FieldPositionOnlyHandler handler(fieldPosition);
+    return _format(number, appendTo, handler, status);
+}
+
+UnicodeString&
+DecimalFormat::format(  double number,
+                        UnicodeString& appendTo,
+                        FieldPositionIterator* posIter,
+                        UErrorCode& status) const
+{
+  FieldPositionIteratorHandler handler(posIter, status);
+  return _format(number, appendTo, handler, status);
+}
 
+UnicodeString&
+DecimalFormat::_format( double number,
+                        UnicodeString& appendTo,
+                        FieldPositionHandler& handler,
+                        UErrorCode &status) const
+{
+    if (U_FAILURE(status)) {
+        return appendTo;
+    }
     // Special case for NaN, sets the begin and end index to be the
     // the string length of localized name of NaN.
+    // TODO:  let NaNs go through DigitList.
     if (uprv_isNaN(number))
     {
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setBeginIndex(appendTo.length());
-
+        int begin = appendTo.length();
         appendTo += getConstSymbol(DecimalFormatSymbols::kNaNSymbol);
 
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setEndIndex(appendTo.length());
+        handler.addAttribute(kIntegerField, begin, appendTo.length());
 
-        addPadding(appendTo, fieldPosition, 0, 0);
+        addPadding(appendTo, handler, 0, 0);
         return appendTo;
     }
 
-    /* Detecting whether a double is negative is easy with the exception of
-     * the value -0.0.  This is a double which has a zero mantissa (and
-     * exponent), but a negative sign bit.  It is semantically distinct from
-     * a zero with a positive sign bit, and this distinction is important
-     * to certain kinds of computations.  However, it's a little tricky to
-     * detect, since (-0.0 == 0.0) and !(-0.0 < 0.0).  How then, you may
-     * ask, does it behave distinctly from +0.0?  Well, 1/(-0.0) ==
-     * -Infinity.  Proper detection of -0.0 is needed to deal with the
-     * issues raised by bugs 4106658, 4106667, and 4147706.  Liu 7/6/98.
-     */
-    UBool isNegative = uprv_isNegative(number);
+    DigitList digits;
+    digits.set(number);
+    _format(digits, appendTo, handler, status);
+    // No way to return status from here.
+    return appendTo;
+}
+
+//------------------------------------------------------------------------------
+
+
+UnicodeString&
+DecimalFormat::format(const StringPiece &number,
+                      UnicodeString &toAppendTo,
+                      FieldPositionIterator *posIter,
+                      UErrorCode &status) const
+{
+#if UCONFIG_FORMAT_FASTPATHS_49
+  // don't bother if the int64 path is not optimized
+  int32_t len    = number.length();
+
+  if(len>0&&len<10) { /* 10 or more digits may not be an int64 */
+    const char *data = number.data();
+    int64_t num = 0;
+    UBool neg = FALSE;
+    UBool ok = TRUE;
+    
+    int32_t start  = 0;
+
+    if(data[start]=='+') {
+      start++;
+    } else if(data[start]=='-') {
+      neg=TRUE;
+      start++;
+    }
+
+    int32_t place = 1; /* 1, 10, ... */
+    for(int32_t i=len-1;i>=start;i--) {
+      if(data[i]>='0'&&data[i]<='9') {
+        num+=place*(int64_t)(data[i]-'0');
+      } else {
+        ok=FALSE;
+        break;
+      }
+      place *= 10;
+    }
 
-    // Do this BEFORE checking to see if value is infinite! Sets the
+    if(ok) {
+      if(neg) {
+        num = -num;// add minus bit
+      }
+      // format as int64_t
+      return format(num, toAppendTo, posIter, status);
+    }
+    // else fall through
+  }
+#endif
+
+    DigitList   dnum;
+    dnum.set(number, status);
+    if (U_FAILURE(status)) {
+        return toAppendTo;
+    }
+    FieldPositionIteratorHandler handler(posIter, status);
+    _format(dnum, toAppendTo, handler, status);
+    return toAppendTo;
+}
+
+
+UnicodeString&
+DecimalFormat::format(const DigitList &number,
+                      UnicodeString &appendTo,
+                      FieldPositionIterator *posIter,
+                      UErrorCode &status) const {
+    FieldPositionIteratorHandler handler(posIter, status);
+    _format(number, appendTo, handler, status);
+    return appendTo;
+}
+
+
+
+UnicodeString&
+DecimalFormat::format(const DigitList &number,
+                     UnicodeString& appendTo,
+                     FieldPosition& pos,
+                     UErrorCode &status) const {
+    FieldPositionOnlyHandler handler(pos);
+    _format(number, appendTo, handler, status);
+    return appendTo;
+}
+
+DigitList&
+DecimalFormat::_round(const DigitList &number, DigitList &adjustedNum, UBool& isNegative, UErrorCode &status) const {
+    if (U_FAILURE(status)) {
+        return adjustedNum;
+    }
+    adjustedNum = number;
+    isNegative = false;
+    if (number.isNaN()) {
+        return adjustedNum;
+    }
+
+    // Do this BEFORE checking to see if value is infinite or negative! Sets the
     // begin and end index to be length of the string composed of
     // localized name of Infinite and the positive/negative localized
     // signs.
 
-    number *= fMultiplier;
+    adjustedNum.setRoundingMode(fRoundingMode);
+    if (fMultiplier != NULL) {
+        adjustedNum.mult(*fMultiplier, status);
+        if (U_FAILURE(status)) {
+            return adjustedNum;
+        }
+    }
+
+    if (fScale != 0) {
+        DigitList ten;
+        ten.set(10);
+        if (fScale > 0) {
+            for (int32_t i = fScale ; i > 0 ; i--) {
+                adjustedNum.mult(ten, status);
+                if (U_FAILURE(status)) {
+                    return adjustedNum;
+                }
+            }
+        } else {
+            for (int32_t i = fScale ; i < 0 ; i++) {
+                adjustedNum.div(ten, status);
+                if (U_FAILURE(status)) {
+                    return adjustedNum;
+                }
+            }
+        }
+    }
+
+    /*
+     * Note: sign is important for zero as well as non-zero numbers.
+     * Proper detection of -0.0 is needed to deal with the
+     * issues raised by bugs 4106658, 4106667, and 4147706.  Liu 7/6/98.
+     */
+    isNegative = !adjustedNum.isPositive();
 
     // Apply rounding after multiplier
+
+    adjustedNum.fContext.status &= ~DEC_Inexact;
     if (fRoundingIncrement != NULL) {
-        if (isNegative)     // For rounding in the correct direction
-            number = -number;
-        number = fRoundingDouble
-            * round(number / fRoundingDouble, fRoundingMode, isNegative);
-        if (isNegative)
-            number = -number;
+        adjustedNum.div(*fRoundingIncrement, status);
+        adjustedNum.toIntegralValue();
+        adjustedNum.mult(*fRoundingIncrement, status);
+        adjustedNum.trim();
+        if (U_FAILURE(status)) {
+            return adjustedNum;
+        }
+    }
+    if (fRoundingMode == kRoundUnnecessary && (adjustedNum.fContext.status & DEC_Inexact)) {
+        status = U_FORMAT_INEXACT_ERROR;
+        return adjustedNum;
     }
 
-    // Special case for INFINITE,
-    if (uprv_isInfinite(number))
-    {
-        int32_t prefixLen = appendAffix(appendTo, number, isNegative, TRUE);
+    if (adjustedNum.isInfinite()) {
+        return adjustedNum;
+    }
 
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setBeginIndex(appendTo.length());
+    if (fUseExponentialNotation || areSignificantDigitsUsed()) {
+        int32_t sigDigits = precision();
+        if (sigDigits > 0) {
+            adjustedNum.round(sigDigits);
+        }
+    } else {
+        // Fixed point format.  Round to a set number of fraction digits.
+        int32_t numFractionDigits = precision();
+        adjustedNum.roundFixedPoint(numFractionDigits);
+    }
+    if (fRoundingMode == kRoundUnnecessary && (adjustedNum.fContext.status & DEC_Inexact)) {
+        status = U_FORMAT_INEXACT_ERROR;
+        return adjustedNum;
+    }
+    return adjustedNum;
+}
 
-        appendTo += getConstSymbol(DecimalFormatSymbols::kInfinitySymbol);
+UnicodeString&
+DecimalFormat::_format(const DigitList &number,
+                        UnicodeString& appendTo,
+                        FieldPositionHandler& handler,
+                        UErrorCode &status) const
+{
+    if (U_FAILURE(status)) {
+        return appendTo;
+    }
 
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setEndIndex(appendTo.length());
+    // Special case for NaN, sets the begin and end index to be the
+    // the string length of localized name of NaN.
+    if (number.isNaN())
+    {
+        int begin = appendTo.length();
+        appendTo += getConstSymbol(DecimalFormatSymbols::kNaNSymbol);
 
-        int32_t suffixLen = appendAffix(appendTo, number, isNegative, FALSE);
+        handler.addAttribute(kIntegerField, begin, appendTo.length());
 
-        addPadding(appendTo, fieldPosition, prefixLen, suffixLen);
+        addPadding(appendTo, handler, 0, 0);
         return appendTo;
     }
 
-    DigitList digits;
-
-    // This detects negativity too.
-    if (fRoundingIncrement == NULL) {
-        // If we did not round in binary space, round in decimal space
-        digits.fRoundingMode = fRoundingMode;
+    DigitList adjustedNum;
+    UBool isNegative;
+    _round(number, adjustedNum, isNegative, status);
+    if (U_FAILURE(status)) {
+        return appendTo;
     }
-    digits.set(number, precision(FALSE),
-               !fUseExponentialNotation && !areSignificantDigitsUsed());
 
-    return subformat(appendTo, fieldPosition, digits, FALSE);
-}
-/**
- * Round a double value to the nearest integer according to the
- * given mode.
- * @param a the absolute value of the number to be rounded
- * @param mode a BigDecimal rounding mode
- * @param isNegative true if the number to be rounded is negative
- * @return the absolute value of the rounded result
- */
-double DecimalFormat::round(double a, ERoundingMode mode, UBool isNegative) {
-    switch (mode) {
-    case kRoundCeiling:
-        return isNegative ? uprv_floor(a) : uprv_ceil(a);
-    case kRoundFloor:
-        return isNegative ? uprv_ceil(a) : uprv_floor(a);
-    case kRoundDown:
-        return uprv_floor(a);
-    case kRoundUp:
-        return uprv_ceil(a);
-    case kRoundHalfEven:
-        {
-            double f = uprv_floor(a);
-            if ((a - f) != 0.5) {
-                return uprv_floor(a + 0.5);
-            }
-            double g = f / 2.0;
-            return (g == uprv_floor(g)) ? f : (f + 1.0);
-        }
-    case kRoundHalfDown:
-        return ((a - uprv_floor(a)) <= 0.5) ? uprv_floor(a) : uprv_ceil(a);
-    case kRoundHalfUp:
-        return ((a - uprv_floor(a)) < 0.5) ? uprv_floor(a) : uprv_ceil(a);
+    // Special case for INFINITE,
+    if (adjustedNum.isInfinite()) {
+        int32_t prefixLen = appendAffix(appendTo, adjustedNum.getDouble(), handler, isNegative, TRUE);
+
+        int begin = appendTo.length();
+        appendTo += getConstSymbol(DecimalFormatSymbols::kInfinitySymbol);
+
+        handler.addAttribute(kIntegerField, begin, appendTo.length());
+
+        int32_t suffixLen = appendAffix(appendTo, adjustedNum.getDouble(), handler, isNegative, FALSE);
+
+        addPadding(appendTo, handler, prefixLen, suffixLen);
+        return appendTo;
     }
-    return 1.0;
+    return subformat(appendTo, handler, adjustedNum, FALSE, status);
 }
 
 UnicodeString&
@@ -812,26 +1526,40 @@ UBool DecimalFormat::isGroupingPosition(int32_t pos) const {
 //------------------------------------------------------------------------------
 
 /**
- * Complete the formatting of a finite number.  On entry, the fDigitList must
+ * Complete the formatting of a finite number.  On entry, the DigitList must
  * be filled in with the correct digits.
  */
 UnicodeString&
 DecimalFormat::subformat(UnicodeString& appendTo,
-                         FieldPosition& fieldPosition,
+                         FieldPositionHandler& handler,
                          DigitList&     digits,
-                         UBool         isInteger) const
+                         UBool          isInteger,
+                         UErrorCode& status) const
 {
-    // Gets the localized zero Unicode character.
-    UChar32 zero = getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
-    int32_t zeroDelta = zero - '0'; // '0' is the DigitList representation of zero
+    // char zero = '0'; 
+    // DigitList returns digits as '0' thru '9', so we will need to 
+    // always need to subtract the character 0 to get the numeric value to use for indexing.
+
+    UChar32 localizedDigits[10];
+    localizedDigits[0] = getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
+    localizedDigits[1] = getConstSymbol(DecimalFormatSymbols::kOneDigitSymbol).char32At(0);
+    localizedDigits[2] = getConstSymbol(DecimalFormatSymbols::kTwoDigitSymbol).char32At(0);
+    localizedDigits[3] = getConstSymbol(DecimalFormatSymbols::kThreeDigitSymbol).char32At(0);
+    localizedDigits[4] = getConstSymbol(DecimalFormatSymbols::kFourDigitSymbol).char32At(0);
+    localizedDigits[5] = getConstSymbol(DecimalFormatSymbols::kFiveDigitSymbol).char32At(0);
+    localizedDigits[6] = getConstSymbol(DecimalFormatSymbols::kSixDigitSymbol).char32At(0);
+    localizedDigits[7] = getConstSymbol(DecimalFormatSymbols::kSevenDigitSymbol).char32At(0);
+    localizedDigits[8] = getConstSymbol(DecimalFormatSymbols::kEightDigitSymbol).char32At(0);
+    localizedDigits[9] = getConstSymbol(DecimalFormatSymbols::kNineDigitSymbol).char32At(0);
+
     const UnicodeString *grouping ;
-    if(fIsCurrencyFormat) {
+    if(fCurrencySignCount > fgCurrencySignCountZero) {
         grouping = &getConstSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol);
     }else{
         grouping = &getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
     }
     const UnicodeString *decimal;
-    if(fIsCurrencyFormat) {
+    if(fCurrencySignCount > fgCurrencySignCountZero) {
         decimal = &getConstSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
     } else {
         decimal = &getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
@@ -840,33 +1568,16 @@ DecimalFormat::subformat(UnicodeString& appendTo,
     int32_t maxIntDig = getMaximumIntegerDigits();
     int32_t minIntDig = getMinimumIntegerDigits();
 
-    /* Per bug 4147706, DecimalFormat must respect the sign of numbers which
-     * format as zero.  This allows sensible computations and preserves
-     * relations such as signum(1/x) = signum(x), where x is +Infinity or
-     * -Infinity.  Prior to this fix, we always formatted zero values as if
-     * they were positive.  Liu 7/6/98.
-     */
-    if (digits.isZero())
-    {
-        digits.fDecimalAt = digits.fCount = 0; // Normalize
-    }
-
     // Appends the prefix.
     double doubleValue = digits.getDouble();
-    int32_t prefixLen = appendAffix(appendTo, doubleValue, !digits.fIsPositive, TRUE);
+    int32_t prefixLen = appendAffix(appendTo, doubleValue, handler, !digits.isPositive(), TRUE);
 
     if (fUseExponentialNotation)
     {
-        // Record field information for caller.
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-        {
-            fieldPosition.setBeginIndex(appendTo.length());
-            fieldPosition.setEndIndex(-1);
-        }
-        else if (fieldPosition.getField() == NumberFormat::kFractionField)
-        {
-            fieldPosition.setBeginIndex(-1);
-        }
+        int currentLength = appendTo.length();
+        int intBegin = currentLength;
+        int intEnd = -1;
+        int fracBegin = -1;
 
         int32_t minFracDig = 0;
         if (useSigDig) {
@@ -896,7 +1607,8 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         // If maximum integer digits are defined and are larger than
         // minimum integer digits, then minimum integer digits are
         // ignored.
-        int32_t exponent = digits.fDecimalAt;
+        digits.reduce();   // Removes trailing zero digits.
+        int32_t exponent = digits.getDecimalAt();
         if (maxIntDig > 1 && maxIntDig != minIntDig) {
             // A exponent increment is defined; adjust to it.
             exponent = (exponent > 0) ? (exponent - 1) / maxIntDig
@@ -917,8 +1629,8 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         // The number of integer digits is handled specially if the number
         // is zero, since then there may be no digits.
         int32_t integerDigits = digits.isZero() ? minIntDig :
-            digits.fDecimalAt - exponent;
-        int32_t totalDigits = digits.fCount;
+            digits.getDecimalAt() - exponent;
+        int32_t totalDigits = digits.getCount();
         if (minimumDigits > totalDigits)
             totalDigits = minimumDigits;
         if (integerDigits > totalDigits)
@@ -930,34 +1642,28 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         {
             if (i == integerDigits)
             {
-                // Record field information for caller.
-                if (fieldPosition.getField() == NumberFormat::kIntegerField)
-                    fieldPosition.setEndIndex(appendTo.length());
+                intEnd = appendTo.length();
+                handler.addAttribute(kIntegerField, intBegin, intEnd);
 
                 appendTo += *decimal;
 
-                // Record field information for caller.
-                if (fieldPosition.getField() == NumberFormat::kFractionField)
-                    fieldPosition.setBeginIndex(appendTo.length());
+                fracBegin = appendTo.length();
+                handler.addAttribute(kDecimalSeparatorField, fracBegin - 1, fracBegin);
             }
             // Restores the digit character or pads the buffer with zeros.
-            UChar32 c = (UChar32)((i < digits.fCount) ?
-                          (digits.fDigits[i] + zeroDelta) :
-                          zero);
+            UChar32 c = (UChar32)((i < digits.getCount()) ?
+                          localizedDigits[digits.getDigitValue(i)] :
+                          localizedDigits[0]);
             appendTo += c;
         }
 
-        // Record field information
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-        {
-            if (fieldPosition.getEndIndex() < 0)
-                fieldPosition.setEndIndex(appendTo.length());
+        currentLength = appendTo.length();
+
+        if (intEnd < 0) {
+            handler.addAttribute(kIntegerField, intBegin, currentLength);
         }
-        else if (fieldPosition.getField() == NumberFormat::kFractionField)
-        {
-            if (fieldPosition.getBeginIndex() < 0)
-                fieldPosition.setBeginIndex(appendTo.length());
-            fieldPosition.setEndIndex(appendTo.length());
+        if (fracBegin > 0) {
+            handler.addAttribute(kFractionField, fracBegin, currentLength);
         }
 
         // The exponent is output using the pattern-specified minimum
@@ -966,6 +1672,9 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         // unacceptable inaccuracy.
         appendTo += getConstSymbol(DecimalFormatSymbols::kExponentialSymbol);
 
+        handler.addAttribute(kExponentSymbolField, currentLength, appendTo.length());
+        currentLength = appendTo.length();
+
         // For zero values, we force the exponent to zero.  We
         // must do this here, and not earlier, because the value
         // is used to determine integer digit count above.
@@ -974,10 +1683,14 @@ DecimalFormat::subformat(UnicodeString& appendTo,
 
         if (exponent < 0) {
             appendTo += getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+            handler.addAttribute(kExponentSignField, currentLength, appendTo.length());
         } else if (fExponentSignAlwaysShown) {
             appendTo += getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
+            handler.addAttribute(kExponentSignField, currentLength, appendTo.length());
         }
 
+        currentLength = appendTo.length();
+
         DigitList expDigits;
         expDigits.set(exponent);
         {
@@ -985,21 +1698,23 @@ DecimalFormat::subformat(UnicodeString& appendTo,
             if (fUseExponentialNotation && expDig < 1) {
                 expDig = 1;
             }
-            for (i=expDigits.fDecimalAt; i<expDig; ++i)
-                appendTo += (zero);
+            for (i=expDigits.getDecimalAt(); i<expDig; ++i)
+                appendTo += (localizedDigits[0]);
         }
-        for (i=0; i<expDigits.fDecimalAt; ++i)
+        for (i=0; i<expDigits.getDecimalAt(); ++i)
         {
-            UChar32 c = (UChar32)((i < expDigits.fCount) ?
-                          (expDigits.fDigits[i] + zeroDelta) : zero);
+            UChar32 c = (UChar32)((i < expDigits.getCount()) ?
+                          localizedDigits[expDigits.getDigitValue(i)] : 
+                          localizedDigits[0]);
             appendTo += c;
         }
+
+        handler.addAttribute(kExponentField, currentLength, appendTo.length());
     }
     else  // Not using exponential notation
     {
-        // Record field information for caller.
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setBeginIndex(appendTo.length());
+        int currentLength = appendTo.length();
+        int intBegin = currentLength;
 
         int32_t sigCount = 0;
         int32_t minSigDig = getMinimumSignificantDigits();
@@ -1014,9 +1729,9 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         // leading zeros required to satisfy getMinimumIntegerDigits,
         // and actual digits present in the number.
         int32_t count = useSigDig ?
-            _max(1, digits.fDecimalAt) : minIntDig;
-        if (digits.fDecimalAt > 0 && count < digits.fDecimalAt) {
-            count = digits.fDecimalAt;
+            _max(1, digits.getDecimalAt()) : minIntDig;
+        if (digits.getDecimalAt() > 0 && count < digits.getDecimalAt()) {
+            count = digits.getDecimalAt();
         }
 
         // Handle the case where getMaximumIntegerDigits() is smaller
@@ -1027,7 +1742,10 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         int32_t digitIndex = 0; // Index into digitList.fDigits[]
         if (count > maxIntDig && maxIntDig >= 0) {
             count = maxIntDig;
-            digitIndex = digits.fDecimalAt - count;
+            digitIndex = digits.getDecimalAt() - count;
+            if(fBoolFlags.contains(UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS)) {
+                status = U_ILLEGAL_ARGUMENT_ERROR;
+            }
         }
 
         int32_t sizeBeforeIntegerPart = appendTo.length();
@@ -1035,16 +1753,16 @@ DecimalFormat::subformat(UnicodeString& appendTo,
         int32_t i;
         for (i=count-1; i>=0; --i)
         {
-            if (i < digits.fDecimalAt && digitIndex < digits.fCount &&
+            if (i < digits.getDecimalAt() && digitIndex < digits.getCount() &&
                 sigCount < maxSigDig) {
                 // Output a real digit
-                appendTo += ((UChar32)(digits.fDigits[digitIndex++] + zeroDelta));
+                appendTo += (UChar32)localizedDigits[digits.getDigitValue(digitIndex++)];
                 ++sigCount;
             }
             else
             {
                 // Output a zero (leading or trailing)
-                appendTo += (zero);
+                appendTo += localizedDigits[0];
                 if (sigCount > 0) {
                     ++sigCount;
                 }
@@ -1052,36 +1770,44 @@ DecimalFormat::subformat(UnicodeString& appendTo,
 
             // Output grouping separator if necessary.
             if (isGroupingPosition(i)) {
+                currentLength = appendTo.length();
                 appendTo.append(*grouping);
+                handler.addAttribute(kGroupingSeparatorField, currentLength, appendTo.length());
             }
         }
 
+        // TODO(dlf): this looks like it was a bug, we marked the int field as ending
+        // before the zero was generated.
         // Record field information for caller.
-        if (fieldPosition.getField() == NumberFormat::kIntegerField)
-            fieldPosition.setEndIndex(appendTo.length());
+        // if (fieldPosition.getField() == NumberFormat::kIntegerField)
+        //     fieldPosition.setEndIndex(appendTo.length());
 
         // Determine whether or not there are any printable fractional
         // digits.  If we've used up the digits we know there aren't.
-        UBool fractionPresent = (!isInteger && digitIndex < digits.fCount) ||
+        UBool fractionPresent = (!isInteger && digitIndex < digits.getCount()) ||
             (useSigDig ? (sigCount < minSigDig) : (getMinimumFractionDigits() > 0));
 
         // If there is no fraction present, and we haven't printed any
         // integer digits, then print a zero.  Otherwise we won't print
         // _any_ digits, and we won't be able to parse this string.
         if (!fractionPresent && appendTo.length() == sizeBeforeIntegerPart)
-            appendTo += (zero);
+            appendTo += localizedDigits[0];
+
+        currentLength = appendTo.length();
+        handler.addAttribute(kIntegerField, intBegin, currentLength);
 
         // Output the decimal separator if we always do so.
-        if (fDecimalSeparatorAlwaysShown || fractionPresent)
+        if (fDecimalSeparatorAlwaysShown || fractionPresent) {
             appendTo += *decimal;
+            handler.addAttribute(kDecimalSeparatorField, currentLength, appendTo.length());
+            currentLength = appendTo.length();
+        }
 
-        // Record field information for caller.
-        if (fieldPosition.getField() == NumberFormat::kFractionField)
-            fieldPosition.setBeginIndex(appendTo.length());
+        int fracBegin = currentLength;
 
         count = useSigDig ? INT32_MAX : getMaximumFractionDigits();
         if (useSigDig && (sigCount == maxSigDig ||
-                          (sigCount >= minSigDig && digitIndex == digits.fCount))) {
+                          (sigCount >= minSigDig && digitIndex == digits.getCount()))) {
             count = 0;
         }
 
@@ -1094,7 +1820,7 @@ DecimalFormat::subformat(UnicodeString& appendTo,
             // fractional stuff to display, or we're out of
             // significant digits.
             if (!useSigDig && i >= getMinimumFractionDigits() &&
-                (isInteger || digitIndex >= digits.fCount)) {
+                (isInteger || digitIndex >= digits.getCount())) {
                 break;
             }
 
@@ -1102,17 +1828,17 @@ DecimalFormat::subformat(UnicodeString& appendTo,
             // that come after the decimal but before any
             // significant digits.  These are only output if
             // abs(number being formatted) < 1.0.
-            if (-1-i > (digits.fDecimalAt-1)) {
-                appendTo += zero;
+            if (-1-i > (digits.getDecimalAt()-1)) {
+                appendTo += localizedDigits[0];
                 continue;
             }
 
             // Output a digit, if we have any precision left, or a
             // zero if we don't.  We don't want to output noise digits.
-            if (!isInteger && digitIndex < digits.fCount) {
-                appendTo += ((UChar32)(digits.fDigits[digitIndex++] + zeroDelta));
+            if (!isInteger && digitIndex < digits.getCount()) {
+                appendTo += (UChar32)localizedDigits[digits.getDigitValue(digitIndex++)];
             } else {
-                appendTo += zero;
+                appendTo += localizedDigits[0];
             }
 
             // If we reach the maximum number of significant
@@ -1121,19 +1847,17 @@ DecimalFormat::subformat(UnicodeString& appendTo,
             ++sigCount;
             if (useSigDig &&
                 (sigCount == maxSigDig ||
-                 (digitIndex == digits.fCount && sigCount >= minSigDig))) {
+                 (digitIndex == digits.getCount() && sigCount >= minSigDig))) {
                 break;
             }
         }
 
-        // Record field information for caller.
-        if (fieldPosition.getField() == NumberFormat::kFractionField)
-            fieldPosition.setEndIndex(appendTo.length());
+        handler.addAttribute(kFractionField, fracBegin, appendTo.length());
     }
 
-    int32_t suffixLen = appendAffix(appendTo, doubleValue, !digits.fIsPositive, FALSE);
+    int32_t suffixLen = appendAffix(appendTo, doubleValue, handler, !digits.isPositive(), FALSE);
 
-    addPadding(appendTo, fieldPosition, prefixLen, suffixLen);
+    addPadding(appendTo, handler, prefixLen, suffixLen);
     return appendTo;
 }
 
@@ -1142,7 +1866,7 @@ DecimalFormat::subformat(UnicodeString& appendTo,
  * @param result the string to be padded
  */
 void DecimalFormat::addPadding(UnicodeString& appendTo,
-                               FieldPosition& fieldPosition,
+                               FieldPositionHandler& handler,
                                int32_t prefixLen,
                                int32_t suffixLen) const
 {
@@ -1167,17 +1891,15 @@ void DecimalFormat::addPadding(UnicodeString& appendTo,
                 appendTo += padding;
                 break;
             }
-            if (fPadPosition == kPadBeforePrefix ||
-                fPadPosition == kPadAfterPrefix) {
-                fieldPosition.setBeginIndex(len + fieldPosition.getBeginIndex());
-                fieldPosition.setEndIndex(len + fieldPosition.getEndIndex());
+            if (fPadPosition == kPadBeforePrefix || fPadPosition == kPadAfterPrefix) {
+                handler.shiftLast(len);
             }
         }
     }
 }
 
 //------------------------------------------------------------------------------
+
 void
 DecimalFormat::parse(const UnicodeString& text,
                      Formattable& result,
@@ -1190,42 +1912,65 @@ void
 DecimalFormat::parse(const UnicodeString& text,
                      Formattable& result,
                      ParsePosition& parsePosition) const {
-    parse(text, result, parsePosition, FALSE);
+    parse(text, result, parsePosition, NULL);
 }
 
-Formattable& DecimalFormat::parseCurrency(const UnicodeString& text,
-                                          Formattable& result,
-                                          ParsePosition& pos) const {
-    parse(text, result, pos, TRUE);
-    return result;
+CurrencyAmount* DecimalFormat::parseCurrency(const UnicodeString& text,
+                                             ParsePosition& pos) const {
+    Formattable parseResult;
+    int32_t start = pos.getIndex();
+    UChar curbuf[4] = {};
+    parse(text, parseResult, pos, curbuf);
+    if (pos.getIndex() != start) {
+        UErrorCode ec = U_ZERO_ERROR;
+        LocalPointer<CurrencyAmount> currAmt(new CurrencyAmount(parseResult, curbuf, ec));
+        if (U_FAILURE(ec)) {
+            pos.setIndex(start); // indicate failure
+        } else {
+            return currAmt.orphan();
+        }
+    }
+    return NULL;
 }
 
 /**
- * Parses the given text as either a number or a currency amount.
+ * Parses the given text as a number, optionally providing a currency amount.
  * @param text the string to parse
- * @param result output parameter for the result
+ * @param result output parameter for the numeric result.
  * @param parsePosition input-output position; on input, the
  * position within text to match; must have 0 <= pos.getIndex() <
  * text.length(); on output, the position after the last matched
  * character. If the parse fails, the position in unchanged upon
  * output.
- * @param parseCurrency if true, a currency amount is parsed;
- * otherwise a Number is parsed
+ * @param currency if non-NULL, it should point to a 4-UChar buffer.
+ * In this case the text is parsed as a currency format, and the
+ * ISO 4217 code for the parsed currency is put into the buffer.
+ * Otherwise the text is parsed as a non-currency format.
  */
 void DecimalFormat::parse(const UnicodeString& text,
                           Formattable& result,
                           ParsePosition& parsePosition,
-                          UBool parseCurrency) const {
-    int32_t backup;
-    int32_t i = backup = parsePosition.getIndex();
+                          UChar* currency) const {
+    int32_t startIdx, backup;
+    int32_t i = startIdx = backup = parsePosition.getIndex();
+
+    // clear any old contents in the result.  In particular, clears any DigitList
+    //   that it may be holding.
+    result.setLong(0);
 
     // Handle NaN as a special case:
-    
+
     // Skip padding characters, if around prefix
     if (fFormatWidth > 0 && (fPadPosition == kPadBeforePrefix ||
                              fPadPosition == kPadAfterPrefix)) {
         i = skipPadding(text, i);
     }
+
+    if (isLenient()) {
+        // skip any leading whitespace
+        i = backup = skipUWhiteSpace(text, i);
+    }
+
     // If the text is composed of the representation of NaN, returns NaN.length
     const UnicodeString *nan = &getConstSymbol(DecimalFormatSymbols::kNaNSymbol);
     int32_t nanLen = (text.compare(i, nan->length(), *nan)
@@ -1240,89 +1985,205 @@ void DecimalFormat::parse(const UnicodeString& text,
         result.setDouble(uprv_getNaN());
         return;
     }
-    
+
     // NaN parse failed; start over
     i = backup;
+    parsePosition.setIndex(i);
 
     // status is used to record whether a number is infinite.
     UBool status[fgStatusLength];
-    UChar curbuf[4];
-    UChar* currency = parseCurrency ? curbuf : NULL;
-    DigitList digits;
 
-    if (!subparse(text, parsePosition, digits, status, currency)) {
-        parsePosition.setIndex(backup);
-        return;
+    DigitList *digits = result.getInternalDigitList(); // get one from the stack buffer
+    if (digits == NULL) {
+        return;    // no way to report error from here.
+    }
+
+    if (fCurrencySignCount > fgCurrencySignCountZero) {
+        if (!parseForCurrency(text, parsePosition, *digits,
+                              status, currency)) {
+          return;
+        }
+    } else {
+        if (!subparse(text,
+                      fNegPrefixPattern, fNegSuffixPattern,
+                      fPosPrefixPattern, fPosSuffixPattern,
+                      FALSE, UCURR_SYMBOL_NAME,
+                      parsePosition, *digits, status, currency)) {
+            debug("!subparse(...) - rewind");
+            parsePosition.setIndex(startIdx);
+            return;
+        }
     }
 
     // Handle infinity
     if (status[fgStatusInfinite]) {
         double inf = uprv_getInfinity();
-        result.setDouble(digits.fIsPositive ? inf : -inf);
+        result.setDouble(digits->isPositive() ? inf : -inf);
+        // TODO:  set the dl to infinity, and let it fall into the code below.
     }
 
     else {
-        // Do as much of the multiplier conversion as possible without
-        // losing accuracy.
-        int32_t mult = fMultiplier; // Don't modify this.multiplier
-        while (mult % 10 == 0) {
-            mult /= 10;
-            --digits.fDecimalAt;
+
+        if (fMultiplier != NULL) {
+            UErrorCode ec = U_ZERO_ERROR;
+            digits->div(*fMultiplier, ec);
         }
 
-        // Handle integral values.  We want to return the most
-        // parsimonious type that will accommodate all of the result's
-        // precision.  We therefore only return a long if the result fits
-        // entirely within a long (taking into account the multiplier) --
-        // otherwise we fall through and return a double.  When more
-        // numeric types are supported by Formattable (e.g., 64-bit
-        // integers, bignums) we will extend this logic to include them.
-        if (digits.fitsIntoLong(isParseIntegerOnly())) {
-            int32_t n = digits.getLong();
-            if (n % mult == 0) {
-                result.setLong(n / mult);
-            }
-            else {  // else handle the remainder
-                result.setDouble(((double)n) / mult);
+        if (fScale != 0) {
+            DigitList ten;
+            ten.set(10);
+            if (fScale > 0) {
+                for (int32_t i = fScale; i > 0; i--) {
+                    UErrorCode ec = U_ZERO_ERROR;
+                    digits->div(ten,ec);
+                }
+            } else {
+                for (int32_t i = fScale; i < 0; i++) {
+                    UErrorCode ec = U_ZERO_ERROR;
+                    digits->mult(ten,ec);
+                }
             }
         }
-        else if (digits.fitsIntoInt64(isParseIntegerOnly())) {
-            int64_t n = digits.getInt64();
-            if (n % mult == 0) {
-                result.setInt64(n / mult);
+
+        // Negative zero special case:
+        //    if parsing integerOnly, change to +0, which goes into an int32 in a Formattable.
+        //    if not parsing integerOnly, leave as -0, which a double can represent.
+        if (digits->isZero() && !digits->isPositive() && isParseIntegerOnly()) {
+            digits->setPositive(TRUE);
+        }
+        result.adoptDigitList(digits);
+    }
+}
+
+
+
+UBool
+DecimalFormat::parseForCurrency(const UnicodeString& text,
+                                ParsePosition& parsePosition,
+                                DigitList& digits,
+                                UBool* status,
+                                UChar* currency) const {
+    int origPos = parsePosition.getIndex();
+    int maxPosIndex = origPos;
+    int maxErrorPos = -1;
+    // First, parse against current pattern.
+    // Since current pattern could be set by applyPattern(),
+    // it could be an arbitrary pattern, and it may not be the one
+    // defined in current locale.
+    UBool tmpStatus[fgStatusLength];
+    ParsePosition tmpPos(origPos);
+    DigitList tmpDigitList;
+    UBool found;
+    if (fStyle == UNUM_CURRENCY_PLURAL) {
+        found = subparse(text,
+                         fNegPrefixPattern, fNegSuffixPattern,
+                         fPosPrefixPattern, fPosSuffixPattern,
+                         TRUE, UCURR_LONG_NAME,
+                         tmpPos, tmpDigitList, tmpStatus, currency);
+    } else {
+        found = subparse(text,
+                         fNegPrefixPattern, fNegSuffixPattern,
+                         fPosPrefixPattern, fPosSuffixPattern,
+                         TRUE, UCURR_SYMBOL_NAME,
+                         tmpPos, tmpDigitList, tmpStatus, currency);
+    }
+    if (found) {
+        if (tmpPos.getIndex() > maxPosIndex) {
+            maxPosIndex = tmpPos.getIndex();
+            for (int32_t i = 0; i < fgStatusLength; ++i) {
+                status[i] = tmpStatus[i];
             }
-            else {  // else handle the remainder
-                result.setDouble(((double)n) / mult);
+            digits = tmpDigitList;
+        }
+    } else {
+        maxErrorPos = tmpPos.getErrorIndex();
+    }
+    // Then, parse against affix patterns.
+    // Those are currency patterns and currency plural patterns.
+    int32_t pos = -1;
+    const UHashElement* element = NULL;
+    while ( (element = fAffixPatternsForCurrency->nextElement(pos)) != NULL ) {
+        const UHashTok valueTok = element->value;
+        const AffixPatternsForCurrency* affixPtn = (AffixPatternsForCurrency*)valueTok.pointer;
+        UBool tmpStatus[fgStatusLength];
+        ParsePosition tmpPos(origPos);
+        DigitList tmpDigitList;
+        UBool result = subparse(text,
+                                &affixPtn->negPrefixPatternForCurrency,
+                                &affixPtn->negSuffixPatternForCurrency,
+                                &affixPtn->posPrefixPatternForCurrency,
+                                &affixPtn->posSuffixPatternForCurrency,
+                                TRUE, affixPtn->patternType,
+                                tmpPos, tmpDigitList, tmpStatus, currency);
+        if (result) {
+            found = true;
+            if (tmpPos.getIndex() > maxPosIndex) {
+                maxPosIndex = tmpPos.getIndex();
+                for (int32_t i = 0; i < fgStatusLength; ++i) {
+                    status[i] = tmpStatus[i];
+                }
+                digits = tmpDigitList;
             }
+        } else {
+            maxErrorPos = (tmpPos.getErrorIndex() > maxErrorPos) ?
+                          tmpPos.getErrorIndex() : maxErrorPos;
         }
-        else {
-            // Handle non-integral or very large values
-            // Dividing by one is okay and not that costly.
-            result.setDouble(digits.getDouble() / mult);
+    }
+    // Finally, parse against simple affix to find the match.
+    // For example, in TestMonster suite,
+    // if the to-be-parsed text is "-\u00A40,00".
+    // complexAffixCompare will not find match,
+    // since there is no ISO code matches "\u00A4",
+    // and the parse stops at "\u00A4".
+    // We will just use simple affix comparison (look for exact match)
+    // to pass it.
+    UBool tmpStatus_2[fgStatusLength];
+    ParsePosition tmpPos_2(origPos);
+    DigitList tmpDigitList_2;
+    // set currencySignCount to 0 so that compareAffix function will
+    // fall to compareSimpleAffix path, not compareComplexAffix path.
+    // ?? TODO: is it right? need "false"?
+    UBool result = subparse(text,
+                            &fNegativePrefix, &fNegativeSuffix,
+                            &fPositivePrefix, &fPositiveSuffix,
+                            FALSE, UCURR_SYMBOL_NAME,
+                            tmpPos_2, tmpDigitList_2, tmpStatus_2,
+                            currency);
+    if (result) {
+        if (tmpPos_2.getIndex() > maxPosIndex) {
+            maxPosIndex = tmpPos_2.getIndex();
+            for (int32_t i = 0; i < fgStatusLength; ++i) {
+                status[i] = tmpStatus_2[i];
+            }
+            digits = tmpDigitList_2;
         }
+        found = true;
+    } else {
+            maxErrorPos = (tmpPos_2.getErrorIndex() > maxErrorPos) ?
+                          tmpPos_2.getErrorIndex() : maxErrorPos;
     }
 
-    if (parseCurrency) {
-        UErrorCode ec = U_ZERO_ERROR;
-        Formattable n(result);
-        result.adoptObject(new CurrencyAmount(n, curbuf, ec));
-        U_ASSERT(U_SUCCESS(ec)); // should always succeed
+    if (!found) {
+        //parsePosition.setIndex(origPos);
+        parsePosition.setErrorIndex(maxErrorPos);
+    } else {
+        parsePosition.setIndex(maxPosIndex);
+        parsePosition.setErrorIndex(-1);
     }
+    return found;
 }
 
 
-/*
-This is an old implimentation that was preparing for 64-bit numbers in ICU.
-It is very slow, and 64-bit numbers are not ANSI-C compatible. This code
-is here if we change our minds.
-
-^^^ what is this referring to? remove? ^^^ [alan]
-*/
-
 /**
  * Parse the given text into a number.  The text is parsed beginning at
  * parsePosition, until an unparseable character is seen.
  * @param text the string to parse.
+ * @param negPrefix negative prefix.
+ * @param negSuffix negative suffix.
+ * @param posPrefix positive prefix.
+ * @param posSuffix positive suffix.
+ * @param currencyParsing whether it is currency parsing or not.
+ * @param type the currency type to parse against, LONG_NAME only or not.
  * @param parsePosition The position at which to being parsing.  Upon
  * return, the first unparsed character.
  * @param digits the DigitList to set to the parsed value.
@@ -1333,35 +2194,191 @@ is here if we change our minds.
  * currency parsing mode, any currency is parsed, not just the
  * currency that this formatter is set to.
  */
-UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePosition,
+UBool DecimalFormat::subparse(const UnicodeString& text,
+                              const UnicodeString* negPrefix,
+                              const UnicodeString* negSuffix,
+                              const UnicodeString* posPrefix,
+                              const UnicodeString* posSuffix,
+                              UBool currencyParsing,
+                              int8_t type,
+                              ParsePosition& parsePosition,
                               DigitList& digits, UBool* status,
                               UChar* currency) const
 {
+    //  The parsing process builds up the number as char string, in the neutral format that
+    //  will be acceptable to the decNumber library, then at the end passes that string
+    //  off for conversion to a decNumber.
+    UErrorCode err = U_ZERO_ERROR;
+    CharString parsedNum;
+    digits.setToZero();
+
     int32_t position = parsePosition.getIndex();
     int32_t oldStart = position;
+    int32_t textLength = text.length(); // One less pointer to follow
+    UBool strictParse = !isLenient();
+    UChar32 zero = getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
+    const UnicodeString *groupingString = &getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
+    UChar32 groupingChar = groupingString->char32At(0);
+    int32_t groupingStringLength = groupingString->length();
+    int32_t groupingCharLength   = U16_LENGTH(groupingChar);
+    UBool   groupingUsed = isGroupingUsed();
+#ifdef FMT_DEBUG
+    UChar dbgbuf[300];
+    UnicodeString s(dbgbuf,0,300);;
+    s.append((UnicodeString)"PARSE \"").append(text.tempSubString(position)).append((UnicodeString)"\" " );
+#define DBGAPPD(x) if(x) { s.append(UnicodeString(#x "="));  if(x->isEmpty()) { s.append(UnicodeString("<empty>")); } else { s.append(*x); } s.append(UnicodeString(" ")); } else { s.append(UnicodeString(#x "=NULL ")); }
+    DBGAPPD(negPrefix);
+    DBGAPPD(negSuffix);
+    DBGAPPD(posPrefix);
+    DBGAPPD(posSuffix);
+    debugout(s);
+    printf("currencyParsing=%d, fFormatWidth=%d, isParseIntegerOnly=%c text.length=%d negPrefLen=%d\n", currencyParsing, fFormatWidth, (isParseIntegerOnly())?'Y':'N', text.length(),  negPrefix!=NULL?negPrefix->length():-1);
+#endif
 
+    UBool fastParseOk = false; /* TRUE iff fast parse is OK */
+    // UBool fastParseHadDecimal = FALSE; /* true if fast parse saw a decimal point. */
+    const DecimalFormatInternal &data = internalData(fReserved);
+    if((data.fFastParseStatus==kFastpathYES) &&
+       !currencyParsing &&
+       //       (negPrefix!=NULL&&negPrefix->isEmpty()) ||
+       text.length()>0 &&
+       text.length()<32 &&
+       (posPrefix==NULL||posPrefix->isEmpty()) &&
+       (posSuffix==NULL||posSuffix->isEmpty()) &&
+       //            (negPrefix==NULL||negPrefix->isEmpty()) &&
+       //            (negSuffix==NULL||(negSuffix->isEmpty()) ) &&
+       TRUE) {  // optimized path
+      int j=position;
+      int l=text.length();
+      int digitCount=0;
+      UChar32 ch = text.char32At(j);
+      const UnicodeString *decimalString = &getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
+      UChar32 decimalChar = 0;
+      UBool intOnly = FALSE;
+      UChar32 lookForGroup = (groupingUsed&&intOnly&&strictParse)?groupingChar:0;
+
+      int32_t decimalCount = decimalString->countChar32(0,3);
+      if(isParseIntegerOnly()) {
+        decimalChar = 0; // not allowed
+        intOnly = TRUE; // Don't look for decimals.
+      } else if(decimalCount==1) {
+        decimalChar = decimalString->char32At(0); // Look for this decimal
+      } else if(decimalCount==0) {
+        decimalChar=0; // NO decimal set
+      } else {
+        j=l+1;//Set counter to end of line, so that we break. Unknown decimal situation.
+      }
+
+#ifdef FMT_DEBUG
+      printf("Preparing to do fastpath parse: decimalChar=U+%04X, groupingChar=U+%04X, first ch=U+%04X intOnly=%c strictParse=%c\n",
+        decimalChar, groupingChar, ch,
+        (intOnly)?'y':'n',
+        (strictParse)?'y':'n');
+#endif
+      if(ch==0x002D) { // '-'
+        j=l+1;//=break - negative number.
+        
+        /*
+          parsedNum.append('-',err); 
+          j+=U16_LENGTH(ch);
+          if(j<l) ch = text.char32At(j);
+        */
+      } else {
+        parsedNum.append('+',err);
+      }
+      while(j<l) {
+        int32_t digit = ch - zero;
+        if(digit >=0 && digit <= 9) {
+          parsedNum.append((char)(digit + '0'), err);
+          if((digitCount>0) || digit!=0 || j==(l-1)) {
+            digitCount++;
+          }
+        } else if(ch == 0) { // break out
+          digitCount=-1;
+          break;
+        } else if(ch == decimalChar) {
+          parsedNum.append((char)('.'), err);
+          decimalChar=0; // no more decimals.
+          // fastParseHadDecimal=TRUE;
+        } else if(ch == lookForGroup) {
+          // ignore grouping char. No decimals, so it has to be an ignorable grouping sep
+        } else if(intOnly && (lookForGroup!=0) && !u_isdigit(ch)) {
+          // parsing integer only and can fall through
+        } else {
+          digitCount=-1; // fail - fall through to slow parse
+          break;
+        }
+        j+=U16_LENGTH(ch);
+        ch = text.char32At(j); // for next  
+      }
+      if(
+         ((j==l)||intOnly) // end OR only parsing integer
+         && (digitCount>0)) { // and have at least one digit
+#ifdef FMT_DEBUG
+        printf("PP -> %d, good = [%s]  digitcount=%d, fGroupingSize=%d fGroupingSize2=%d!\n", j, parsedNum.data(), digitCount, fGroupingSize, fGroupingSize2);
+#endif
+        fastParseOk=true; // Fast parse OK!
+
+#ifdef SKIP_OPT
+        debug("SKIP_OPT");
+        /* for testing, try it the slow way. also */
+        fastParseOk=false;
+        parsedNum.clear();
+#else
+        parsePosition.setIndex(position=j);
+        status[fgStatusInfinite]=false;
+#endif
+      } else {
+        // was not OK. reset, retry
+#ifdef FMT_DEBUG
+        printf("Fall through: j=%d, l=%d, digitCount=%d\n", j, l, digitCount);
+#endif
+        parsedNum.clear();
+      }
+    } else {
+#ifdef FMT_DEBUG
+      printf("Could not fastpath parse. ");
+      printf("fFormatWidth=%d ", fFormatWidth);
+      printf("text.length()=%d ", text.length());
+      printf("posPrefix=%p posSuffix=%p ", posPrefix, posSuffix);
+
+      printf("\n");
+#endif
+    }
+
+  if(!fastParseOk 
+#if UCONFIG_HAVE_PARSEALLINPUT
+     && fParseAllInput!=UNUM_YES
+#endif
+     ) 
+  {
     // Match padding before prefix
     if (fFormatWidth > 0 && fPadPosition == kPadBeforePrefix) {
         position = skipPadding(text, position);
     }
 
     // Match positive and negative prefixes; prefer longest match.
-    int32_t posMatch = compareAffix(text, position, FALSE, TRUE, currency);
-    int32_t negMatch = compareAffix(text, position, TRUE, TRUE, currency);
+    int32_t posMatch = compareAffix(text, position, FALSE, TRUE, posPrefix, currencyParsing, type, currency);
+    int32_t negMatch = compareAffix(text, position, TRUE,  TRUE, negPrefix, currencyParsing, type, currency);
     if (posMatch >= 0 && negMatch >= 0) {
         if (posMatch > negMatch) {
             negMatch = -1;
         } else if (negMatch > posMatch) {
             posMatch = -1;
-        }  
+        }
     }
     if (posMatch >= 0) {
         position += posMatch;
+        parsedNum.append('+', err);
     } else if (negMatch >= 0) {
         position += negMatch;
-    } else {
+        parsedNum.append('-', err);
+    } else if (strictParse){
         parsePosition.setErrorIndex(position);
         return FALSE;
+    } else {
+        // Temporary set positive. This might be changed after checking suffix
+        parsedNum.append('+', err);
     }
 
     // Match padding before prefix
@@ -1369,14 +2386,20 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
         position = skipPadding(text, position);
     }
 
+    if (! strictParse) {
+        position = skipUWhiteSpace(text, position);
+    }
+
     // process digits or Inf, find decimal position
     const UnicodeString *inf = &getConstSymbol(DecimalFormatSymbols::kInfinitySymbol);
     int32_t infLen = (text.compare(position, inf->length(), *inf)
         ? 0 : inf->length());
     position += infLen; // infLen is non-zero when it does equal to infinity
-    status[fgStatusInfinite] = (UBool)infLen;
-    if (!infLen)
-    {
+    status[fgStatusInfinite] = infLen != 0;
+
+    if (infLen != 0) {
+        parsedNum.append("Infinity", err);
+    } else {
         // We now have a string of digits, possibly with grouping symbols,
         // and decimal points.  We want to process these into a DigitList.
         // We don't want to put a bunch of leading zeros into the DigitList
@@ -1384,27 +2407,54 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
         // put only significant digits into the DigitList, and adjust the
         // exponent as needed.
 
-        digits.fDecimalAt = digits.fCount = 0;
-        UChar32 zero = getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
 
-        const UnicodeString *decimal;
-        if(fIsCurrencyFormat) {
-            decimal = &getConstSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
+        UBool strictFail = FALSE; // did we exit with a strict parse failure?
+        int32_t lastGroup = -1; // where did we last see a grouping separator?
+        int32_t digitStart = position;
+        int32_t gs2 = fGroupingSize2 == 0 ? fGroupingSize : fGroupingSize2;
+
+        const UnicodeString *decimalString;
+        if (fCurrencySignCount > fgCurrencySignCountZero) {
+            decimalString = &getConstSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
         } else {
-            decimal = &getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
+            decimalString = &getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
         }
-        const UnicodeString *grouping = &getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
+        UChar32 decimalChar = decimalString->char32At(0);
+        int32_t decimalStringLength = decimalString->length();
+        int32_t decimalCharLength   = U16_LENGTH(decimalChar);
+
         UBool sawDecimal = FALSE;
+        UChar32 sawDecimalChar = 0xFFFF;
+        UBool sawGrouping = FALSE;
+        UChar32 sawGroupingChar = 0xFFFF;
         UBool sawDigit = FALSE;
         int32_t backup = -1;
         int32_t digit;
-        int32_t textLength = text.length(); // One less pointer to follow
-        int32_t groupingLen = grouping->length();
-        int32_t decimalLen = decimal->length();
+
+        // equivalent grouping and decimal support
+        const UnicodeSet *decimalSet = NULL;
+        const UnicodeSet *groupingSet = NULL;
+
+        if (decimalCharLength == decimalStringLength) {
+            decimalSet = DecimalFormatStaticSets::getSimilarDecimals(decimalChar, strictParse);
+        }
+
+        if (groupingCharLength == groupingStringLength) {
+            if (strictParse) {
+                groupingSet = DecimalFormatStaticSets::gStaticSets->fStrictDefaultGroupingSeparators;
+            } else {
+                groupingSet = DecimalFormatStaticSets::gStaticSets->fDefaultGroupingSeparators;
+            }
+        }
+
+        // We need to test groupingChar and decimalChar separately from groupingSet and decimalSet, if the sets are even initialized.
+        // If sawDecimal is TRUE, only consider sawDecimalChar and NOT decimalSet
+        // If a character matches decimalSet, don't consider it to be a member of the groupingSet.
 
         // We have to track digitCount ourselves, because digits.fCount will
         // pin when the maximum allowable digits is reached.
         int32_t digitCount = 0;
+        int32_t integerDigitCount = 0;
 
         for (; position < textLength; )
         {
@@ -1418,7 +2468,7 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
              * from 0 to 9 in 'digit'.  First try using the locale digit,
              * which may or MAY NOT be a standard Unicode digit range.  If
              * this fails, try using the standard Unicode digit ranges by
-             * calling Character.digit().  If this also fails, digit will
+             * calling Character.digit().  If this also fails, digit will 
              * have a value outside the range 0..9.
              */
             digit = ch - zero;
@@ -1426,110 +2476,177 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
             {
                 digit = u_charDigitValue(ch);
             }
+            
+            // As a last resort, look through the localized digits if the zero digit
+            // is not a "standard" Unicode digit.
+            if ( (digit < 0 || digit > 9) && u_charDigitValue(zero) != 0) {
+                digit = 0;
+                // Already check above (digit = ch - zero) for ch==zero; the only check we need to do here is:
+                // if \u3007 is treated as 0 for parsing, \u96F6 should be too. Otherwise check for nonzero digits.
+                if ( zero!=0x3007 || ch!=0x96F6 ) {
+                    for (digit = 1 ; digit < 10 ; digit++ ) {
+                        if ( getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol)(DecimalFormatSymbols::kOneDigitSymbol+digit-1)).char32At(0) == ch ) {
+                            break;
+                        }
+                    }
+                }
+            }
 
-            if (digit > 0 && digit <= 9)
+            if (digit >= 0 && digit <= 9)
             {
+                if (strictParse && backup != -1) {
+                    // comma followed by digit, so group before comma is a
+                    // secondary group.  If there was a group separator
+                    // before that, the group must == the secondary group
+                    // length, else it can be <= the the secondary group
+                    // length.
+                    if ((lastGroup != -1 && backup - lastGroup - 1 != gs2) ||
+                        (lastGroup == -1 && position - digitStart - 1 > gs2)) {
+                        strictFail = TRUE;
+                        break;
+                    }
+                    
+                    lastGroup = backup;
+                }
+                
                 // Cancel out backup setting (see grouping handler below)
                 backup = -1;
-
                 sawDigit = TRUE;
-                // output a regular non-zero digit.
-                ++digitCount;
-                digits.append((char)(digit + '0'));
+                
+                // Note: this will append leading zeros
+                parsedNum.append((char)(digit + '0'), err);
+
+                // count any digit that's not a leading zero
+                if (digit > 0 || digitCount > 0 || sawDecimal) {
+                    digitCount += 1;
+                    
+                    // count any integer digit that's not a leading zero
+                    if (! sawDecimal) {
+                        integerDigitCount += 1;
+                    }
+                }
+                    
                 position += U16_LENGTH(ch);
             }
-            else if (digit == 0)
+            else if (groupingStringLength > 0 && 
+                matchGrouping(groupingChar, sawGrouping, sawGroupingChar, groupingSet, 
+                            decimalChar, decimalSet,
+                            ch) && groupingUsed)
             {
-                // Cancel out backup setting (see grouping handler below)
-                backup = -1;
-                sawDigit = TRUE;
-
-                // Check for leading zeros
-                if (digits.fCount != 0)
-                {
-                    // output a regular zero digit.
-                    ++digitCount;
-                    digits.append((char)(digit + '0'));
+                if (sawDecimal) {
+                    break;
                 }
-                else if (sawDecimal)
-                {
-                    // If we have seen the decimal, but no significant digits yet,
-                    // then we account for leading zeros by decrementing the
-                    // digits.fDecimalAt into negative values.
-                    --digits.fDecimalAt;
+
+                if (strictParse) {
+                    if ( (!sawDigit && groupingSet!=NULL && u_isWhitespace(ch)) || backup != -1 ) {
+                       // We differ from the ICU4J code by allowing a leading group sep in strict mode (for
+                       // backward compatibility) as long as it is not one of the breaking whitespace characters
+                       // that is only treated as a group separator because of the equivalence set. If we get
+                       // here it is because the leading sep was such a breaking space, or there were multiple
+                       // group separators in a row. Note that the DecimalFormat documentation says
+                       // "During parsing, grouping separators are ignored" and that was for strict parsing,
+                       // so we may need to further revisit this strictParse restriction to ensure compatibility.
+                       // Also note: u_isWhitespace is true for all Zs/Zl/Zp except the no-break ones: 00A0,2007,202F.
+                       // In CLDR, all locales that have space as a group separator use 00A0 (NBSP).
+                        strictFail = TRUE;
+                        break;
+                    }
                 }
-                // else ignore leading zeros in integer part of number.
-                position += U16_LENGTH(ch);
-            }
-            else if (!text.compare(position, groupingLen, *grouping) && isGroupingUsed())
-            {
+
                 // Ignore grouping characters, if we are using them, but require
                 // that they be followed by a digit.  Otherwise we backup and
                 // reprocess them.
                 backup = position;
-                position += groupingLen;
+                position += groupingStringLength;
+                sawGrouping=TRUE;
+                // Once we see a grouping character, we only accept that grouping character from then on.
+                sawGroupingChar=ch;
             }
-            else if (!text.compare(position, decimalLen, *decimal) && !isParseIntegerOnly() && !sawDecimal)
+            else if (matchDecimal(decimalChar,sawDecimal,sawDecimalChar, decimalSet, ch))
             {
+                if (strictParse) {
+                    if (backup != -1 ||
+                        (lastGroup != -1 && position - lastGroup != fGroupingSize + 1)) {
+                        strictFail = TRUE;
+                        break;
+                    }
+                }
+
                 // If we're only parsing integers, or if we ALREADY saw the
                 // decimal, then don't parse this one.
+                if (isParseIntegerOnly() || sawDecimal) {
+                    break;
+                }
 
-                digits.fDecimalAt = digitCount; // Not digits.fCount!
+                parsedNum.append('.', err);
+                position += decimalStringLength;
                 sawDecimal = TRUE;
-                position += decimalLen;
+                // Once we see a decimal character, we only accept that decimal character from then on.
+                sawDecimalChar=ch;
+                // decimalSet is considered to consist of (ch,ch)
             }
             else {
-                const UnicodeString *tmp;
-                tmp = &getConstSymbol(DecimalFormatSymbols::kExponentialSymbol);
-                if (!text.caseCompare(position, tmp->length(), *tmp, U_FOLD_CASE_DEFAULT))    // error code is set below if !sawDigit
-                {
-                    // Parse sign, if present
-                    int32_t pos = position + tmp->length();
-                    DigitList exponentDigits;
 
-                    if (pos < textLength)
+                if(!fBoolFlags.contains(UNUM_PARSE_NO_EXPONENT) || // don't parse if this is set unless..
+                    fUseExponentialNotation /* should be:  isScientificNotation() but it is not const (?!) see bug #9619 */) { // .. it's an exponent format - ignore setting and parse anyways
+                    const UnicodeString *tmp;
+                    tmp = &getConstSymbol(DecimalFormatSymbols::kExponentialSymbol);
+                    // TODO: CASE
+                    if (!text.caseCompare(position, tmp->length(), *tmp, U_FOLD_CASE_DEFAULT))    // error code is set below if !sawDigit 
                     {
-                        tmp = &getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
-                        if (!text.compare(pos, tmp->length(), *tmp))
+                        // Parse sign, if present
+                        int32_t pos = position + tmp->length();
+                        char exponentSign = '+';
+
+                        if (pos < textLength)
                         {
-                            pos += tmp->length();
-                        }
-                        else {
-                            tmp = &getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+                            tmp = &getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
                             if (!text.compare(pos, tmp->length(), *tmp))
                             {
                                 pos += tmp->length();
-                                exponentDigits.fIsPositive = FALSE;
+                            }
+                            else {
+                                tmp = &getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+                                if (!text.compare(pos, tmp->length(), *tmp))
+                                {
+                                    exponentSign = '-';
+                                    pos += tmp->length();
+                                }
                             }
                         }
-                    }
 
-                    while (pos < textLength) {
-                        ch = text[(int32_t)pos];
-                        digit = ch - zero;
+                        UBool sawExponentDigit = FALSE;
+                        while (pos < textLength) {
+                            ch = text[(int32_t)pos];
+                            digit = ch - zero;
 
-                        if (digit < 0 || digit > 9) {
-                            digit = u_charDigitValue(ch);
+                            if (digit < 0 || digit > 9) {
+                                digit = u_charDigitValue(ch);
+                            }
+                            if (0 <= digit && digit <= 9) {
+                                if (!sawExponentDigit) {
+                                    parsedNum.append('E', err);
+                                    parsedNum.append(exponentSign, err);
+                                    sawExponentDigit = TRUE;
+                                }
+                                ++pos;
+                                parsedNum.append((char)(digit + '0'), err);
+                            } else {
+                                break;
+                            }
                         }
-                        if (0 <= digit && digit <= 9) {
-                            ++pos;
-                            exponentDigits.append((char)(digit + '0'));
-                        } else {
-                            break;
+
+                        if (sawExponentDigit) {
+                            position = pos; // Advance past the exponent
                         }
-                    }
 
-                    if (exponentDigits.fCount > 0) {
-                        exponentDigits.fDecimalAt = exponentDigits.fCount;
-                        digits.fDecimalAt += exponentDigits.getLong();
-                        position = pos; // Advance past the exponent
+                        break; // Whether we fail or succeed, we exit this loop
+                    } else {
+                        break;
                     }
-
-                    break; // Whether we fail or succeed, we exit this loop
-                }
-                else {
+                } else { // not parsing exponent
                     break;
-                }
+              }
             }
         }
 
@@ -1538,17 +2655,32 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
             position = backup;
         }
 
-        // If there was no decimal point we have an integer
-        if (!sawDecimal)
-        {
-            digits.fDecimalAt += digitCount; // Not digits.fCount!
+        if (strictParse && !sawDecimal) {
+            if (lastGroup != -1 && position - lastGroup != fGroupingSize + 1) {
+                strictFail = TRUE;
+            }
+        }
+
+        if (strictFail) {
+            // only set with strictParse and a grouping separator error
+
+            parsePosition.setIndex(oldStart);
+            parsePosition.setErrorIndex(position);
+            debug("strictFail!");
+            return FALSE;
         }
 
+        // If there was no decimal point we have an integer
+
         // If none of the text string was recognized.  For example, parse
         // "x" with pattern "#0.00" (return index and error index both 0)
         // parse "$" with pattern "$#0.00". (return index 0 and error index
         // 1).
         if (!sawDigit && digitCount == 0) {
+#ifdef FMT_DEBUG
+            debug("none of text rec");
+            printf("position=%d\n",position);
+#endif
             parsePosition.setIndex(oldStart);
             parsePosition.setErrorIndex(oldStart);
             return FALSE;
@@ -1560,28 +2692,31 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
         position = skipPadding(text, position);
     }
 
+    int32_t posSuffixMatch = -1, negSuffixMatch = -1;
+
     // Match positive and negative suffixes; prefer longest match.
-    if (posMatch >= 0) {
-        posMatch = compareAffix(text, position, FALSE, FALSE, currency);
+    if (posMatch >= 0 || (!strictParse && negMatch < 0)) {
+        posSuffixMatch = compareAffix(text, position, FALSE, FALSE, posSuffix, currencyParsing, type, currency);
     }
     if (negMatch >= 0) {
-        negMatch = compareAffix(text, position, TRUE, FALSE, currency);
+        negSuffixMatch = compareAffix(text, position, TRUE, FALSE, negSuffix, currencyParsing, type, currency);
     }
-    if (posMatch >= 0 && negMatch >= 0) {
-        if (posMatch > negMatch) {
-            negMatch = -1;
-        } else if (negMatch > posMatch) {
-            posMatch = -1;
-        }  
+    if (posSuffixMatch >= 0 && negSuffixMatch >= 0) {
+        if (posSuffixMatch > negSuffixMatch) {
+            negSuffixMatch = -1;
+        } else if (negSuffixMatch > posSuffixMatch) {
+            posSuffixMatch = -1;
+        }
     }
 
     // Fail if neither or both
-    if ((posMatch >= 0) == (negMatch >= 0)) {
+    if (strictParse && ((posSuffixMatch >= 0) == (negSuffixMatch >= 0))) {
         parsePosition.setErrorIndex(position);
+        debug("neither or both");
         return FALSE;
     }
 
-    position += (posMatch>=0 ? posMatch : negMatch);
+    position += (posSuffixMatch >= 0 ? posSuffixMatch : (negSuffixMatch >= 0 ? negSuffixMatch : 0));
 
     // Match padding before suffix
     if (fFormatWidth > 0 && fPadPosition == kPadAfterSuffix) {
@@ -1590,10 +2725,41 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
 
     parsePosition.setIndex(position);
 
-    digits.fIsPositive = (posMatch >= 0);
-
-    if(parsePosition.getIndex() == oldStart)
+    parsedNum.data()[0] = (posSuffixMatch >= 0 || (!strictParse && negMatch < 0 && negSuffixMatch < 0)) ? '+' : '-';
+#ifdef FMT_DEBUG
+printf("PP -> %d, SLOW = [%s]!    pp=%d, os=%d, err=%s\n", position, parsedNum.data(), parsePosition.getIndex(),oldStart,u_errorName(err));
+#endif
+  } /* end SLOW parse */
+  if(parsePosition.getIndex() == oldStart)
+    {
+#ifdef FMT_DEBUG
+      printf(" PP didnt move, err\n");
+#endif
+        parsePosition.setErrorIndex(position);
+        return FALSE;
+    }
+#if UCONFIG_HAVE_PARSEALLINPUT
+  else if (fParseAllInput==UNUM_YES&&parsePosition.getIndex()!=textLength)
     {
+#ifdef FMT_DEBUG
+      printf(" PP didnt consume all (UNUM_YES), err\n");
+#endif
+        parsePosition.setErrorIndex(position);
+        return FALSE;
+    }
+#endif
+    // uint32_t bits = (fastParseOk?kFastpathOk:0) |
+    //   (fastParseHadDecimal?0:kNoDecimal);
+    //printf("FPOK=%d, FPHD=%d, bits=%08X\n", fastParseOk, fastParseHadDecimal, bits);
+    digits.set(parsedNum.toStringPiece(),
+               err,
+               0//bits
+               );
+
+    if (U_FAILURE(err)) {
+#ifdef FMT_DEBUG
+      printf(" err setting %s\n", u_errorName(err));
+#endif
         parsePosition.setErrorIndex(position);
         return FALSE;
     }
@@ -1623,6 +2789,9 @@ int32_t DecimalFormat::skipPadding(const UnicodeString& text, int32_t position)
  * @param pos offset into input at which to begin matching
  * @param isNegative
  * @param isPrefix
+ * @param affixPat affix pattern used for currency affix comparison.
+ * @param currencyParsing whether it is currency parsing or not
+ * @param type the currency type to parse against, LONG_NAME only or not.
  * @param currency return value for parsed currency, for generic
  * currency parsing mode, or null for normal parsing. In generic
  * currency parsing mode, any currency is parsed, not just the
@@ -1633,24 +2802,37 @@ int32_t DecimalFormat::compareAffix(const UnicodeString& text,
                                     int32_t pos,
                                     UBool isNegative,
                                     UBool isPrefix,
-                                    UChar* currency) const {
-    if (fCurrencyChoice != NULL || currency != NULL) {
+                                    const UnicodeString* affixPat,
+                                    UBool currencyParsing,
+                                    int8_t type,
+                                    UChar* currency) const
+{
+    const UnicodeString *patternToCompare;
+    if (fCurrencyChoice != NULL || currency != NULL ||
+        (fCurrencySignCount > fgCurrencySignCountZero && currencyParsing)) {
+
+        if (affixPat != NULL) {
+            return compareComplexAffix(*affixPat, text, pos, type, currency);
+        }
+    }
+
+    if (isNegative) {
         if (isPrefix) {
-            return compareComplexAffix(isNegative ? *fNegPrefixPattern : *fPosPrefixPattern,
-                                       text, pos, currency);
-        } else {
-            return compareComplexAffix(isNegative ? *fNegSuffixPattern : *fPosSuffixPattern,
-                                       text, pos, currency);
+            patternToCompare = &fNegativePrefix;
+        }
+        else {
+            patternToCompare = &fNegativeSuffix;
         }
     }
-    
-    if (isPrefix) {
-        return compareSimpleAffix(isNegative ? fNegativePrefix : fPositivePrefix,
-                                  text, pos);
-    } else {
-        return compareSimpleAffix(isNegative ? fNegativeSuffix : fPositiveSuffix,
-                                  text, pos);
+    else {
+        if (isPrefix) {
+            patternToCompare = &fPositivePrefix;
+        }
+        else {
+            patternToCompare = &fPositiveSuffix;
+        }
     }
+    return compareSimpleAffix(*patternToCompare, text, pos, isLenient());
 }
 
 /**
@@ -1665,71 +2847,131 @@ int32_t DecimalFormat::compareAffix(const UnicodeString& text,
  */
 int32_t DecimalFormat::compareSimpleAffix(const UnicodeString& affix,
                                           const UnicodeString& input,
-                                          int32_t pos) {
+                                          int32_t pos,
+                                          UBool lenient) {
     int32_t start = pos;
-    for (int32_t i=0; i<affix.length(); ) {
-        UChar32 c = affix.char32At(i);
-        int32_t len = U16_LENGTH(c);
-        if (uprv_isRuleWhiteSpace(c)) {
-            // We may have a pattern like: \u200F \u0020
-            //        and input text like: \u200F \u0020
-            // Note that U+200F and U+0020 are RuleWhiteSpace but only
-            // U+0020 is UWhiteSpace.  So we have to first do a direct
-            // match of the run of RULE whitespace in the pattern,
-            // then match any extra characters.
-            UBool literalMatch = FALSE;
-            while (pos < input.length() &&
-                   input.char32At(pos) == c) {
-                literalMatch = TRUE;
-                i += len;
-                pos += len;
-                if (i == affix.length()) {
-                    break;
+    UChar32 affixChar = affix.char32At(0);
+    int32_t affixLength = affix.length();
+    int32_t inputLength = input.length();
+    int32_t affixCharLength = U16_LENGTH(affixChar);
+    UnicodeSet *affixSet;
+
+    if (!lenient) {
+        affixSet = DecimalFormatStaticSets::gStaticSets->fStrictDashEquivalents;
+        
+        // If the affix is exactly one character long and that character
+        // is in the dash set and the very next input character is also
+        // in the dash set, return a match.
+        if (affixCharLength == affixLength && affixSet->contains(affixChar))  {
+            if (affixSet->contains(input.char32At(pos))) {
+                return 1;
+            }
+        }
+
+        for (int32_t i = 0; i < affixLength; ) {
+            UChar32 c = affix.char32At(i);
+            int32_t len = U16_LENGTH(c);
+            if (PatternProps::isWhiteSpace(c)) {
+                // We may have a pattern like: \u200F \u0020
+                //        and input text like: \u200F \u0020
+                // Note that U+200F and U+0020 are Pattern_White_Space but only
+                // U+0020 is UWhiteSpace.  So we have to first do a direct
+                // match of the run of Pattern_White_Space in the pattern,
+                // then match any extra characters.
+                UBool literalMatch = FALSE;
+                while (pos < inputLength &&
+                       input.char32At(pos) == c) {
+                    literalMatch = TRUE;
+                    i += len;
+                    pos += len;
+                    if (i == affixLength) {
+                        break;
+                    }
+                    c = affix.char32At(i);
+                    len = U16_LENGTH(c);
+                    if (!PatternProps::isWhiteSpace(c)) {
+                        break;
+                    }
                 }
-                c = affix.char32At(i);
-                len = U16_LENGTH(c);
-                if (!uprv_isRuleWhiteSpace(c)) {
-                    break;
+
+                // Advance over run in pattern
+                i = skipPatternWhiteSpace(affix, i);
+                
+                UBool patternWhitespaceWasJustMark = (i == 1 && (c == 0x200E || c == 0x200F));
+
+                // Advance over run in input text
+                // Must see at least one white space char in input,
+                // unless we've already matched some characters literally,
+                // or unless the pattern whitespace was just LRM/RLM
+                int32_t s = pos;
+                pos = skipUWhiteSpace(input, pos);
+                if (pos == s && !literalMatch && !patternWhitespaceWasJustMark) {
+                    return -1;
+                }
+
+                // If we skip UWhiteSpace in the input text, we need to skip it in the pattern.
+                // Otherwise, the previous lines may have skipped over text (such as U+00A0) that
+                // is also in the affix.
+                i = skipUWhiteSpace(affix, i);
+            } else {
+                if (pos < inputLength &&
+                    input.char32At(pos) == c) {
+                    i += len;
+                    pos += len;
+                } else {
+                    return -1;
                 }
             }
+        }
+    } else {
+        UBool match = FALSE;
+        
+        affixSet = DecimalFormatStaticSets::gStaticSets->fDashEquivalents;
 
-            // Advance over run in pattern
-            i = skipRuleWhiteSpace(affix, i);
+        if (affixCharLength == affixLength && affixSet->contains(affixChar))  {
+            pos = skipUWhiteSpace(input, pos);
+            
+            if (affixSet->contains(input.char32At(pos))) {
+                return pos - start + 1;
+            }
+        }
 
-            // Advance over run in input text
-            // Must see at least one white space char in input,
-            // unless we've already matched some characters literally.
-            int32_t s = pos;
+        for (int32_t i = 0; i < affixLength; )
+        {
+            //i = skipRuleWhiteSpace(affix, i);
+            i = skipUWhiteSpace(affix, i);
             pos = skipUWhiteSpace(input, pos);
-            if (pos == s && !literalMatch) {
-                return -1;
+
+            if (i >= affixLength || pos >= inputLength) {
+                break;
             }
-        } else {
-            if (pos < input.length() &&
-                input.char32At(pos) == c) {
-                i += len;
-                pos += len;
-            } else {
+
+            UChar32 c = affix.char32At(i);
+            int32_t len = U16_LENGTH(c);
+
+            if (input.char32At(pos) != c) {
                 return -1;
             }
+
+            match = TRUE;
+            i += len;
+            pos += len;
+        }
+
+        if (affixLength > 0 && ! match) {
+            return -1;
         }
     }
     return pos - start;
 }
 
 /**
- * Skip over a run of zero or more isRuleWhiteSpace() characters at
+ * Skip over a run of zero or more Pattern_White_Space characters at
  * pos in text.
  */
-int32_t DecimalFormat::skipRuleWhiteSpace(const UnicodeString& text, int32_t pos) {
-    while (pos < text.length()) {
-        UChar32 c = text.char32At(pos);
-        if (!uprv_isRuleWhiteSpace(c)) {
-            break;
-        }
-        pos += U16_LENGTH(c);
-    }
-    return pos;
+int32_t DecimalFormat::skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) {
+    const UChar* s = text.getBuffer();
+    return (int32_t)(PatternProps::skipWhiteSpace(s + pos, text.length() - pos) - s);
 }
 
 /**
@@ -1739,7 +2981,7 @@ int32_t DecimalFormat::skipRuleWhiteSpace(const UnicodeString& text, int32_t pos
 int32_t DecimalFormat::skipUWhiteSpace(const UnicodeString& text, int32_t pos) {
     while (pos < text.length()) {
         UChar32 c = text.char32At(pos);
-        if (!u_isUWhiteSpace(c)) {
+        if (!u_isUWhiteSpace(c) && c!=0x200E && c!=0x200F) { // u_isUWhiteSpace does not include LRM,RLM
             break;
         }
         pos += U16_LENGTH(c);
@@ -1752,6 +2994,7 @@ int32_t DecimalFormat::skipUWhiteSpace(const UnicodeString& text, int32_t pos) {
  * @param affixPat pattern string
  * @param input input text
  * @param pos offset into input at which to begin matching
+ * @param type the currency type to parse against, LONG_NAME only or not.
  * @param currency return value for parsed currency, for generic
  * currency parsing mode, or null for normal parsing. In generic
  * currency parsing mode, any currency is parsed, not just the
@@ -1761,13 +3004,16 @@ int32_t DecimalFormat::skipUWhiteSpace(const UnicodeString& text, int32_t pos) {
 int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
                                            const UnicodeString& text,
                                            int32_t pos,
+                                           int8_t type,
                                            UChar* currency) const
 {
     int32_t start = pos;
     U_ASSERT(currency != NULL ||
-             (fCurrencyChoice != NULL && *getCurrency() != 0));
+             (fCurrencyChoice != NULL && *getCurrency() != 0) ||
+             fCurrencySignCount > fgCurrencySignCountZero);
 
-    for (int32_t i=0; i<affixPat.length() && pos >= 0; ) {
+    for (int32_t i=0;
+         i<affixPat.length() && pos >= 0; ) {
         UChar32 c = affixPat.char32At(i);
         i += U16_LENGTH(c);
 
@@ -1780,44 +3026,51 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
 
             switch (c) {
             case kCurrencySign: {
-                // If currency != null, then perform generic currency matching.
-                // Otherwise, do currency choice parsing.
+                // since the currency names in choice format is saved
+                // the same way as other currency names,
+                // do not need to do currency choice parsing here.
+                // the general currency parsing parse against all names,
+                // including names in choice format.
                 UBool intl = i<affixPat.length() &&
                     affixPat.char32At(i) == kCurrencySign;
-                // Parse generic currency -- anything for which we
-                // have a display name, or any 3-letter ISO code.
-                if (currency != NULL) {
-                    // Try to parse display name for our locale; first
-                    // determine our locale.
-                    UErrorCode ec = U_ZERO_ERROR;
-                    const char* loc = getLocaleID(ULOC_VALID_LOCALE, ec);
-                    if (U_FAILURE(ec) || loc == NULL || *loc == 0) {
-                        // applyPattern has been called; use the symbols
-                        loc = fSymbols->getLocale().getName();
-                        ec = U_ZERO_ERROR;
-                    }
-                    // Delegate parse of display name => ISO code to Currency
-                    ParsePosition ppos(pos);
-                    UChar curr[4];
-                    uprv_parseCurrency(loc, text, ppos, curr, ec);
-
-                    // If parse succeeds, populate currency[0]
-                    if (U_SUCCESS(ec) && ppos.getIndex() != pos) {
-                        u_strcpy(currency, curr);
-                        pos = ppos.getIndex();
-                    } else {
-                        pos = -1;
-                    }
-                } else {
-                    if (intl) {
-                        ++i;
-                        pos = match(text, pos, getCurrency());
+                if (intl) {
+                    ++i;
+                }
+                UBool plural = i<affixPat.length() &&
+                    affixPat.char32At(i) == kCurrencySign;
+                if (plural) {
+                    ++i;
+                    intl = FALSE;
+                }
+                // Parse generic currency -- anything for which we
+                // have a display name, or any 3-letter ISO code.
+                // Try to parse display name for our locale; first
+                // determine our locale.
+                const char* loc = fCurrencyPluralInfo->getLocale().getName();
+                ParsePosition ppos(pos);
+                UChar curr[4];
+                UErrorCode ec = U_ZERO_ERROR;
+                // Delegate parse of display name => ISO code to Currency
+                uprv_parseCurrency(loc, text, ppos, type, curr, ec);
+
+                // If parse succeeds, populate currency[0]
+                if (U_SUCCESS(ec) && ppos.getIndex() != pos) {
+                    if (currency) {
+                        u_strcpy(currency, curr);
                     } else {
-                        ParsePosition ppos(pos);
-                        Formattable result;
-                        fCurrencyChoice->parse(text, result, ppos);
-                        pos = (ppos.getIndex() == pos) ? -1 : ppos.getIndex();
+                        // The formatter is currency-style but the client has not requested
+                        // the value of the parsed currency. In this case, if that value does
+                        // not match the formatter's current value, then the parse fails.
+                        UChar effectiveCurr[4];
+                        getEffectiveCurrency(effectiveCurr, ec);
+                        if ( U_FAILURE(ec) || u_strncmp(curr,effectiveCurr,4) != 0 ) {
+                               pos = -1;
+                               continue;
+                        }
                     }
+                    pos = ppos.getIndex();
+                } else if (!isLenient()){
+                    pos = -1;
                 }
                 continue;
             }
@@ -1845,8 +3098,8 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
         }
 
         pos = match(text, pos, c);
-        if (uprv_isRuleWhiteSpace(c)) {
-            i = skipRuleWhiteSpace(affixPat, i);
+        if (PatternProps::isWhiteSpace(c)) {
+            i = skipPatternWhiteSpace(affixPat, i);
         }
     }
     return pos - start;
@@ -1855,14 +3108,14 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
 /**
  * Match a single character at text[pos] and return the index of the
  * next character upon success.  Return -1 on failure.  If
- * isRuleWhiteSpace(ch) then match a run of white space in text.
+ * ch is a Pattern_White_Space then match a run of white space in text.
  */
 int32_t DecimalFormat::match(const UnicodeString& text, int32_t pos, UChar32 ch) {
-    if (uprv_isRuleWhiteSpace(ch)) {
+    if (PatternProps::isWhiteSpace(ch)) {
         // Advance over run of white space in input text
         // Must see at least one white space char in input
         int32_t s = pos;
-        pos = skipUWhiteSpace(text, pos);
+        pos = skipPatternWhiteSpace(text, pos);
         if (pos == s) {
             return -1;
         }
@@ -1881,14 +3134,57 @@ int32_t DecimalFormat::match(const UnicodeString& text, int32_t pos, const Unico
     for (int32_t i=0; i<str.length() && pos >= 0; ) {
         UChar32 ch = str.char32At(i);
         i += U16_LENGTH(ch);
-        if (uprv_isRuleWhiteSpace(ch)) {
-            i = skipRuleWhiteSpace(str, i);
+        if (PatternProps::isWhiteSpace(ch)) {
+            i = skipPatternWhiteSpace(str, i);
         }
         pos = match(text, pos, ch);
     }
     return pos;
 }
 
+UBool DecimalFormat::matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
+                         UnicodeSet *sset, UChar32 schar)
+{
+    if (sset != NULL) {
+        return sset->contains(schar);
+    }
+
+    return text.compare(position, length, symbol) == 0;
+}
+
+UBool DecimalFormat::matchDecimal(UChar32 symbolChar,
+                            UBool sawDecimal,  UChar32 sawDecimalChar,
+                             const UnicodeSet *sset, UChar32 schar) {
+   if(sawDecimal) {
+       return schar==sawDecimalChar;
+   } else if(schar==symbolChar) {
+       return TRUE;
+   } else if(sset!=NULL) {
+        return sset->contains(schar);
+   } else {
+       return FALSE;
+   }
+}
+
+UBool DecimalFormat::matchGrouping(UChar32 groupingChar,
+                            UBool sawGrouping, UChar32 sawGroupingChar,
+                             const UnicodeSet *sset,
+                             UChar32 /*decimalChar*/, const UnicodeSet *decimalSet,
+                             UChar32 schar) {
+    if(sawGrouping) {
+        return schar==sawGroupingChar;  // previously found
+    } else if(schar==groupingChar) {
+        return TRUE; // char from symbols
+    } else if(sset!=NULL) {
+        return sset->contains(schar) &&  // in groupingSet but...
+           ((decimalSet==NULL) || !decimalSet->contains(schar)); // Exclude decimalSet from groupingSet
+    } else {
+        return FALSE;
+    }
+}
+
+
+
 //------------------------------------------------------------------------------
 // Gets the pointer to the localized decimal format symbols
 
@@ -1922,7 +3218,10 @@ DecimalFormat::adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt)
         // If the currency symbols are the same, there is no need to recalculate.
         setCurrencyForSymbols();
     }
-    expandAffixes();
+    expandAffixes(NULL);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 //------------------------------------------------------------------------------
 // Setting the symbols is equlivalent to adopting a newly created localized
@@ -1932,8 +3231,53 @@ void
 DecimalFormat::setDecimalFormatSymbols(const DecimalFormatSymbols& symbols)
 {
     adoptDecimalFormatSymbols(new DecimalFormatSymbols(symbols));
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
+}
+
+
+const CurrencyPluralInfo*
+DecimalFormat::getCurrencyPluralInfo(void) const
+{
+    return fCurrencyPluralInfo;
+}
+
+
+void
+DecimalFormat::adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt)
+{
+    if (toAdopt != NULL) {
+        delete fCurrencyPluralInfo;
+        fCurrencyPluralInfo = toAdopt;
+        // re-set currency affix patterns and currency affixes.
+        if (fCurrencySignCount > fgCurrencySignCountZero) {
+            UErrorCode status = U_ZERO_ERROR;
+            if (fAffixPatternsForCurrency) {
+                deleteHashForAffixPattern();
+            }
+            setupCurrencyAffixPatterns(status);
+            if (fCurrencySignCount == fgCurrencySignCountInPluralFormat) {
+                // only setup the affixes of the plural pattern.
+                setupCurrencyAffixes(fFormatPattern, FALSE, TRUE, status);
+            }
+        }
+    }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
+}
+
+void
+DecimalFormat::setCurrencyPluralInfo(const CurrencyPluralInfo& info)
+{
+    adoptCurrencyPluralInfo(info.clone());
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
+
+
 /**
  * Update the currency object to match the symbols.  This method
  * is used only when the caller has passed in a symbols object
@@ -1956,43 +3300,49 @@ DecimalFormat::setCurrencyForSymbols() {
     UErrorCode ec = U_ZERO_ERROR;
     const UChar* c = NULL;
     const char* loc = fSymbols->getLocale().getName();
-    UChar intlCurrencySymbol[4]; 
+    UChar intlCurrencySymbol[4];
     ucurr_forLocale(loc, intlCurrencySymbol, 4, &ec);
     UnicodeString currencySymbol;
 
     uprv_getStaticCurrencyName(intlCurrencySymbol, loc, currencySymbol, ec);
     if (U_SUCCESS(ec)
         && getConstSymbol(DecimalFormatSymbols::kCurrencySymbol) == currencySymbol
-        && getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == intlCurrencySymbol)
+        && getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == UnicodeString(intlCurrencySymbol))
     {
         // Trap an error in mapping locale to currency.  If we can't
         // map, then don't fail and set the currency to "".
         c = intlCurrencySymbol;
     }
     ec = U_ZERO_ERROR; // reset local error code!
-    setCurrency(c, ec);
+    setCurrencyInternally(c, ec);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 
 //------------------------------------------------------------------------------
 // Gets the positive prefix of the number pattern.
+
 UnicodeString&
 DecimalFormat::getPositivePrefix(UnicodeString& result) const
 {
     result = fPositivePrefix;
     return result;
 }
+
 //------------------------------------------------------------------------------
 // Sets the positive prefix of the number pattern.
+
 void
 DecimalFormat::setPositivePrefix(const UnicodeString& newValue)
 {
     fPositivePrefix = newValue;
     delete fPosPrefixPattern;
     fPosPrefixPattern = 0;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2014,6 +3364,9 @@ DecimalFormat::setNegativePrefix(const UnicodeString& newValue)
     fNegativePrefix = newValue;
     delete fNegPrefixPattern;
     fNegPrefixPattern = 0;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2035,6 +3388,9 @@ DecimalFormat::setPositiveSuffix(const UnicodeString& newValue)
     fPositiveSuffix = newValue;
     delete fPosSuffixPattern;
     fPosSuffixPattern = 0;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2056,14 +3412,25 @@ DecimalFormat::setNegativeSuffix(const UnicodeString& newValue)
     fNegativeSuffix = newValue;
     delete fNegSuffixPattern;
     fNegSuffixPattern = 0;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
 // Gets the multiplier of the number pattern.
+//   Multipliers are stored as decimal numbers (DigitLists) because that
+//      is the most convenient for muliplying or dividing the numbers to be formatted.
+//   A NULL multiplier implies one, and the scaling operations are skipped.
 
-int32_t DecimalFormat::getMultiplier() const
+int32_t 
+DecimalFormat::getMultiplier() const
 {
-    return fMultiplier;
+    if (fMultiplier == NULL) {
+        return 1;
+    } else {
+        return fMultiplier->getLong();
+    }
 }
 
 //------------------------------------------------------------------------------
@@ -2071,10 +3438,26 @@ int32_t DecimalFormat::getMultiplier() const
 void
 DecimalFormat::setMultiplier(int32_t newValue)
 {
-    // This shouldn't be set to 0.
-    // Due to compatibility with ICU4J we cannot set an error code and refuse 0.
-    // So the rest of the code should ignore fMultiplier when it's 0. [grhoten]
-    fMultiplier = newValue;
+//  if (newValue == 0) {
+//      throw new IllegalArgumentException("Bad multiplier: " + newValue);
+//  }
+    if (newValue == 0) {
+        newValue = 1;     // one being the benign default value for a multiplier.
+    }
+    if (newValue == 1) {
+        delete fMultiplier;
+        fMultiplier = NULL;
+    } else {
+        if (fMultiplier == NULL) {
+            fMultiplier = new DigitList;
+        }
+        if (fMultiplier != NULL) {
+            fMultiplier->set(newValue);
+        }
+    }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2086,7 +3469,11 @@ DecimalFormat::setMultiplier(int32_t newValue)
  * @see #setRoundingMode
  */
 double DecimalFormat::getRoundingIncrement() const {
-    return fRoundingDouble;
+    if (fRoundingIncrement == NULL) {
+        return 0.0;
+    } else {
+        return fRoundingIncrement->getDouble();
+    }
 }
 
 /**
@@ -2103,13 +3490,18 @@ void DecimalFormat::setRoundingIncrement(double newValue) {
         if (fRoundingIncrement == NULL) {
             fRoundingIncrement = new DigitList();
         }
-        fRoundingIncrement->set((int32_t)newValue);
-        fRoundingDouble = newValue;
-    } else {
-        delete fRoundingIncrement;
-        fRoundingIncrement = NULL;
-        fRoundingDouble = 0.0;
+        if (fRoundingIncrement != NULL) {
+            fRoundingIncrement->set(newValue);
+            return;
+        }
     }
+    // These statements are executed if newValue is less than 0.0
+    // or fRoundingIncrement could not be created.
+    delete fRoundingIncrement;
+    fRoundingIncrement = NULL;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2133,6 +3525,9 @@ DecimalFormat::ERoundingMode DecimalFormat::getRoundingMode() const {
  */
 void DecimalFormat::setRoundingMode(ERoundingMode roundingMode) {
     fRoundingMode = roundingMode;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2162,10 +3557,13 @@ int32_t DecimalFormat::getFormatWidth() const {
  */
 void DecimalFormat::setFormatWidth(int32_t width) {
     fFormatWidth = (width > 0) ? width : 0;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 UnicodeString DecimalFormat::getPadCharacterString() const {
-    return fPad;
+    return UnicodeString(fPad);
 }
 
 void DecimalFormat::setPadCharacter(const UnicodeString &padChar) {
@@ -2175,6 +3573,9 @@ void DecimalFormat::setPadCharacter(const UnicodeString &padChar) {
     else {
         fPad = kDefaultPad;
     }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2219,6 +3620,9 @@ DecimalFormat::EPadPosition DecimalFormat::getPadPosition() const {
  */
 void DecimalFormat::setPadPosition(EPadPosition padPos) {
     fPadPosition = padPos;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2246,6 +3650,9 @@ UBool DecimalFormat::isScientificNotation() {
  */
 void DecimalFormat::setScientificNotation(UBool useScientific) {
     fUseExponentialNotation = useScientific;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2274,6 +3681,9 @@ int8_t DecimalFormat::getMinimumExponentDigits() const {
  */
 void DecimalFormat::setMinimumExponentDigits(int8_t minExpDig) {
     fMinExponentDigits = (int8_t)((minExpDig > 0) ? minExpDig : 1);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -2305,25 +3715,31 @@ UBool DecimalFormat::isExponentSignAlwaysShown() {
  */
 void DecimalFormat::setExponentSignAlwaysShown(UBool expSignAlways) {
     fExponentSignAlwaysShown = expSignAlways;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
 // Gets the grouping size of the number pattern.  For example, thousand or 10
 // thousand groupings.
+
 int32_t
 DecimalFormat::getGroupingSize() const
 {
     return fGroupingSize;
 }
+
 //------------------------------------------------------------------------------
 // Gets the grouping size of the number pattern.
+
 void
 DecimalFormat::setGroupingSize(int32_t newValue)
 {
     fGroupingSize = newValue;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2340,6 +3756,9 @@ void
 DecimalFormat::setSecondaryGroupingSize(int32_t newValue)
 {
     fGroupingSize2 = newValue;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2358,6 +3777,9 @@ void
 DecimalFormat::setDecimalSeparatorAlwaysShown(UBool newValue)
 {
     fDecimalSeparatorAlwaysShown = newValue;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 //------------------------------------------------------------------------------
@@ -2384,29 +3806,37 @@ DecimalFormat::toLocalizedPattern(UnicodeString& result) const
  * affix pattern string is null, do not expand it.  This method should be
  * called any time the symbols or the affix patterns change in order to keep
  * the expanded affix strings up to date.
+ * This method also will be called before formatting if format currency
+ * plural names, since the plural name is not a static one, it is
+ * based on the currency plural count, the affix will be known only
+ * after the currency plural count is know.
+ * In which case, the parameter
+ * 'pluralCount' will be a non-null currency plural count.
+ * In all other cases, the 'pluralCount' is null, which means it is not needed.
  */
-void DecimalFormat::expandAffixes() {
+void DecimalFormat::expandAffixes(const UnicodeString* pluralCount) {
+    FieldPositionHandler none;
     if (fPosPrefixPattern != 0) {
-        expandAffix(*fPosPrefixPattern, fPositivePrefix, 0, FALSE);
+      expandAffix(*fPosPrefixPattern, fPositivePrefix, 0, none, FALSE, pluralCount);
     }
     if (fPosSuffixPattern != 0) {
-        expandAffix(*fPosSuffixPattern, fPositiveSuffix, 0, FALSE);
+      expandAffix(*fPosSuffixPattern, fPositiveSuffix, 0, none, FALSE, pluralCount);
     }
     if (fNegPrefixPattern != 0) {
-        expandAffix(*fNegPrefixPattern, fNegativePrefix, 0, FALSE);
+      expandAffix(*fNegPrefixPattern, fNegativePrefix, 0, none, FALSE, pluralCount);
     }
     if (fNegSuffixPattern != 0) {
-        expandAffix(*fNegSuffixPattern, fNegativeSuffix, 0, FALSE);
+      expandAffix(*fNegSuffixPattern, fNegativeSuffix, 0, none, FALSE, pluralCount);
     }
 #ifdef FMT_DEBUG
     UnicodeString s;
-    s.append("[")
-        .append(*fPosPrefixPattern).append("|").append(*fPosSuffixPattern)
-        .append(";") .append(*fNegPrefixPattern).append("|").append(*fNegSuffixPattern)
-        .append("]->[")
-        .append(fPositivePrefix).append("|").append(fPositiveSuffix)
-        .append(";") .append(fNegativePrefix).append("|").append(fNegativeSuffix)
-        .append("]\n");
+    s.append(UnicodeString("["))
+      .append(DEREFSTR(fPosPrefixPattern)).append((UnicodeString)"|").append(DEREFSTR(fPosSuffixPattern))
+      .append((UnicodeString)";") .append(DEREFSTR(fNegPrefixPattern)).append((UnicodeString)"|").append(DEREFSTR(fNegSuffixPattern))
+        .append((UnicodeString)"]->[")
+        .append(fPositivePrefix).append((UnicodeString)"|").append(fPositiveSuffix)
+        .append((UnicodeString)";") .append(fNegativePrefix).append((UnicodeString)"|").append(fNegativeSuffix)
+        .append((UnicodeString)"]\n");
     debugout(s);
 #endif
 }
@@ -2417,7 +3847,9 @@ void DecimalFormat::expandAffixes() {
  * after kQuote are recognized: PATTERN_PERCENT, PATTERN_PER_MILLE,
  * PATTERN_MINUS, and kCurrencySign.  If kCurrencySign is doubled (kQuote +
  * kCurrencySign + kCurrencySign), it is interpreted as an international
- * currency sign.  Any other character after a kQuote represents itself.
+ * currency sign. If CURRENCY_SIGN is tripled, it is interpreted as
+ * currency plural long names, such as "US Dollars".
+ * Any other character after a kQuote represents itself.
  * kQuote must be followed by another character; kQuote may not occur by
  * itself at the end of the pattern.
  *
@@ -2441,11 +3873,19 @@ void DecimalFormat::expandAffixes() {
  * currencyChoice member variable will be initialized if it is null.  If
  * doFormat is true, then it is assumed that the currencyChoice has been
  * created, and it will be used to format the value in digitList.
+ * @param pluralCount the plural count. It is only used for currency
+ *                    plural format. In which case, it is the plural
+ *                    count of the currency amount. For example,
+ *                    in en_US, it is the singular "one", or the plural
+ *                    "other". For all other cases, it is null, and
+ *                    is not being used.
  */
 void DecimalFormat::expandAffix(const UnicodeString& pattern,
                                 UnicodeString& affix,
                                 double number,
-                                UBool doFormat) const {
+                                FieldPositionHandler& handler,
+                                UBool doFormat,
+                                const UnicodeString* pluralCount) const {
     affix.remove();
     for (int i=0; i<pattern.length(); ) {
         UChar32 c = pattern.char32At(i);
@@ -2453,6 +3893,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
         if (c == kQuote) {
             c = pattern.char32At(i);
             i += U16_LENGTH(c);
+            int beginIdx = affix.length();
             switch (c) {
             case kCurrencySign: {
                 // As of ICU 2.2 we use the currency object, and
@@ -2462,19 +3903,44 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                 // sets a custom DFS.
                 UBool intl = i<pattern.length() &&
                     pattern.char32At(i) == kCurrencySign;
+                UBool plural = FALSE;
                 if (intl) {
                     ++i;
+                    plural = i<pattern.length() &&
+                        pattern.char32At(i) == kCurrencySign;
+                    if (plural) {
+                        intl = FALSE;
+                        ++i;
+                    }
                 }
                 const UChar* currencyUChars = getCurrency();
                 if (currencyUChars[0] != 0) {
                     UErrorCode ec = U_ZERO_ERROR;
-                    if(intl) {
-                        affix += currencyUChars;
+                    if (plural && pluralCount != NULL) {
+                        // plural name is only needed when pluralCount != null,
+                        // which means when formatting currency plural names.
+                        // For other cases, pluralCount == null,
+                        // and plural names are not needed.
+                        int32_t len;
+                        CharString pluralCountChar;
+                        pluralCountChar.appendInvariantChars(*pluralCount, ec);
+                        UBool isChoiceFormat;
+                        const UChar* s = ucurr_getPluralName(currencyUChars,
+                            fSymbols != NULL ? fSymbols->getLocale().getName() :
+                            Locale::getDefault().getName(), &isChoiceFormat,
+                            pluralCountChar.data(), &len, &ec);
+                        affix += UnicodeString(s, len);
+                        handler.addAttribute(kCurrencyField, beginIdx, affix.length());
+                    } else if(intl) {
+                        affix.append(currencyUChars, -1);
+                        handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                     } else {
                         int32_t len;
                         UBool isChoiceFormat;
-                        const UChar* s = ucurr_getName(currencyUChars, fSymbols->getLocale().getName(),
-                                                       UCURR_SYMBOL_NAME, &isChoiceFormat, &len, &ec);
+                        // If fSymbols is NULL, use default locale
+                        const UChar* s = ucurr_getName(currencyUChars,
+                            fSymbols != NULL ? fSymbols->getLocale().getName() : Locale::getDefault().getName(),
+                            UCURR_SYMBOL_NAME, &isChoiceFormat, &len, &ec);
                         if (isChoiceFormat) {
                             // Two modes here: If doFormat is false, we set up
                             // currencyChoice.  If doFormat is true, we use the
@@ -2487,7 +3953,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                                 // return.
                                 if (fCurrencyChoice == NULL) {
                                     // TODO Replace double-check with proper thread-safe code
-                                    ChoiceFormat* fmt = new ChoiceFormat(s, ec);
+                                    ChoiceFormat* fmt = new ChoiceFormat(UnicodeString(s), ec);
                                     if (U_SUCCESS(ec)) {
                                         umtx_lock(NULL);
                                         if (fCurrencyChoice == NULL) {
@@ -2517,12 +3983,14 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                                 } else {
                                     // We only arrive here if the currency choice
                                     // format in the locale data is INVALID.
-                                    affix += currencyUChars;
+                                    affix.append(currencyUChars, -1);
+                                    handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                                 }
                             }
                             continue;
                         }
                         affix += UnicodeString(s, len);
+                        handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                     }
                 } else {
                     if(intl) {
@@ -2530,20 +3998,25 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
                     } else {
                         affix += getConstSymbol(DecimalFormatSymbols::kCurrencySymbol);
                     }
+                    handler.addAttribute(kCurrencyField, beginIdx, affix.length());
                 }
                 break;
             }
             case kPatternPercent:
                 affix += getConstSymbol(DecimalFormatSymbols::kPercentSymbol);
+                handler.addAttribute(kPercentField, beginIdx, affix.length());
                 break;
             case kPatternPerMill:
                 affix += getConstSymbol(DecimalFormatSymbols::kPerMillSymbol);
+                handler.addAttribute(kPermillField, beginIdx, affix.length());
                 break;
             case kPatternPlus:
                 affix += getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
+                handler.addAttribute(kSignField, beginIdx, affix.length());
                 break;
             case kPatternMinus:
                 affix += getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+                handler.addAttribute(kSignField, beginIdx, affix.length());
                 break;
             default:
                 affix.append(c);
@@ -2563,27 +4036,85 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
  * @param isPrefix
  */
 int32_t DecimalFormat::appendAffix(UnicodeString& buf, double number,
+                                   FieldPositionHandler& handler,
                                    UBool isNegative, UBool isPrefix) const {
-    if (fCurrencyChoice != 0) {
-        const UnicodeString* affixPat = 0;
+    // plural format precedes choice format
+    if (fCurrencyChoice != 0 &&
+        fCurrencySignCount != fgCurrencySignCountInPluralFormat) {
+        const UnicodeString* affixPat;
         if (isPrefix) {
             affixPat = isNegative ? fNegPrefixPattern : fPosPrefixPattern;
         } else {
             affixPat = isNegative ? fNegSuffixPattern : fPosSuffixPattern;
         }
-        UnicodeString affixBuf;
-        expandAffix(*affixPat, affixBuf, number, TRUE);
-        buf.append(affixBuf);
-        return affixBuf.length();
+        if (affixPat) {
+            UnicodeString affixBuf;
+            expandAffix(*affixPat, affixBuf, number, handler, TRUE, NULL);
+            buf.append(affixBuf);
+            return affixBuf.length();
+        }
+        // else someone called a function that reset the pattern.
     }
-    
-    const UnicodeString* affix = NULL;
-    if (isPrefix) {
-        affix = isNegative ? &fNegativePrefix : &fPositivePrefix;
+
+    const UnicodeString* affix;
+    if (fCurrencySignCount == fgCurrencySignCountInPluralFormat) {
+        UnicodeString pluralCount = fCurrencyPluralInfo->getPluralRules()->select(number);
+        AffixesForCurrency* oneSet;
+        if (fStyle == UNUM_CURRENCY_PLURAL) {
+            oneSet = (AffixesForCurrency*)fPluralAffixesForCurrency->get(pluralCount);
+        } else {
+            oneSet = (AffixesForCurrency*)fAffixesForCurrency->get(pluralCount);
+        }
+        if (isPrefix) {
+            affix = isNegative ? &oneSet->negPrefixForCurrency :
+                                 &oneSet->posPrefixForCurrency;
+        } else {
+            affix = isNegative ? &oneSet->negSuffixForCurrency :
+                                 &oneSet->posSuffixForCurrency;
+        }
     } else {
-        affix = isNegative ? &fNegativeSuffix : &fPositiveSuffix;
+        if (isPrefix) {
+            affix = isNegative ? &fNegativePrefix : &fPositivePrefix;
+        } else {
+            affix = isNegative ? &fNegativeSuffix : &fPositiveSuffix;
+        }
     }
+
+    int32_t begin = (int) buf.length();
+
     buf.append(*affix);
+
+    if (handler.isRecording()) {
+      int32_t offset = (int) (*affix).indexOf(getConstSymbol(DecimalFormatSymbols::kCurrencySymbol));
+      if (offset > -1) {
+        UnicodeString aff = getConstSymbol(DecimalFormatSymbols::kCurrencySymbol);
+        handler.addAttribute(kCurrencyField, begin + offset, begin + offset + aff.length());
+      }
+
+      offset = (int) (*affix).indexOf(getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
+      if (offset > -1) {
+        UnicodeString aff = getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);
+        handler.addAttribute(kCurrencyField, begin + offset, begin + offset + aff.length());
+      }
+
+      offset = (int) (*affix).indexOf(getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol));
+      if (offset > -1) {
+        UnicodeString aff = getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+        handler.addAttribute(kSignField, begin + offset, begin + offset + aff.length());
+      }
+
+      offset = (int) (*affix).indexOf(getConstSymbol(DecimalFormatSymbols::kPercentSymbol));
+      if (offset > -1) {
+        UnicodeString aff = getConstSymbol(DecimalFormatSymbols::kPercentSymbol);
+        handler.addAttribute(kPercentField, begin + offset, begin + offset + aff.length());
+      }
+
+      offset = (int) (*affix).indexOf(getConstSymbol(DecimalFormatSymbols::kPerMillSymbol));
+      if (offset > -1) {
+        UnicodeString aff = getConstSymbol(DecimalFormatSymbols::kPerMillSymbol);
+        handler.addAttribute(kPermillField, begin + offset, begin + offset + aff.length());
+      }
+    }
     return affix->length();
 }
 
@@ -2714,6 +4245,16 @@ DecimalFormat::appendAffixPattern(UnicodeString& appendTo,
 UnicodeString&
 DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
 {
+    if (fStyle == UNUM_CURRENCY_PLURAL) {
+        // the prefix or suffix pattern might not be defined yet,
+        // so they can not be synthesized,
+        // instead, get them directly.
+        // but it might not be the actual pattern used in formatting.
+        // the actual pattern used in formatting depends on the
+        // formatted number's plural count.
+        result = fFormatPattern;
+        return result;
+    }
     result.remove();
     UChar32 zero, sigDigit = kPatternSignificantDigit;
     UnicodeString digit, group;
@@ -2747,10 +4288,10 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
         padSpec.append(fPad);
     }
     if (fRoundingIncrement != NULL) {
-        for(i=0; i<fRoundingIncrement->fCount; ++i) {
-            roundingDigits.append((UChar)fRoundingIncrement->fDigits[i]);
+        for(i=0; i<fRoundingIncrement->getCount(); ++i) {
+          roundingDigits.append(zero+(fRoundingIncrement->getDigitValue(i))); // Convert to Unicode digit
         }
-        roundingDecimalPos = fRoundingIncrement->fDecimalAt;
+        roundingDecimalPos = fRoundingIncrement->getDecimalAt();
     }
     for (int32_t part=0; part<2; ++part) {
         if (padPos == kPadBeforePrefix) {
@@ -2878,7 +4419,7 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
                 // end up with ",###".
                 if (add>1 && isGroupingPosition(maxDig)) {
                     result.insert(sub0Start, group);
-                    --add;                        
+                    --add;
                 }
             }
         }
@@ -2947,7 +4488,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern, UErrorCode& status)
 
 void
 DecimalFormat::applyPattern(const UnicodeString& pattern,
-                            UParseError& parseError, 
+                            UParseError& parseError,
                             UErrorCode& status)
 {
     applyPattern(pattern, FALSE, parseError, status);
@@ -2974,10 +4515,10 @@ DecimalFormat::applyLocalizedPattern(const UnicodeString& pattern,
 //------------------------------------------------------------------------------
 
 void
-DecimalFormat::applyPattern(const UnicodeString& pattern,
-                            UBool localized,
-                            UParseError& parseError,
-                            UErrorCode& status)
+DecimalFormat::applyPatternWithoutExpandAffix(const UnicodeString& pattern,
+                                              UBool localized,
+                                              UParseError& parseError,
+                                              UErrorCode& status)
 {
     if (U_FAILURE(status))
     {
@@ -3051,11 +4592,10 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
         DigitList roundingInc;
         int8_t expDigits = -1;
         UBool expSignAlways = FALSE;
-        UBool isCurrency = FALSE;
-        
+
         // The affix is either the prefix or the suffix.
         UnicodeString* affix = &prefix;
-        
+
         int32_t start = pos;
         UBool isPartDone = FALSE;
         UChar32 ch;
@@ -3096,13 +4636,13 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
                     if (ch == sigDigit) {
                         ++sigDigitCount;
                     } else {
-                        ++zeroDigitCount;
                         if (ch != zeroDigit && roundingPos < 0) {
                             roundingPos = digitLeftCount + zeroDigitCount;
                         }
                         if (roundingPos >= 0) {
                             roundingInc.append((char)(ch - zeroDigit + '0'));
                         }
+                        ++zeroDigitCount;
                     }
                     if (groupingCount >= 0 && decimalPos < 0) {
                         ++groupingCount;
@@ -3216,8 +4756,17 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
                     if ((pos+1) < pattern.length() && pattern[pos+1] == kCurrencySign) {
                         affix->append(kCurrencySign);
                         ++pos; // Skip over the doubled character
+                        if ((pos+1) < pattern.length() &&
+                            pattern[pos+1] == kCurrencySign) {
+                            affix->append(kCurrencySign);
+                            ++pos; // Skip over the doubled character
+                            fCurrencySignCount = fgCurrencySignCountInPluralFormat;
+                        } else {
+                            fCurrencySignCount = fgCurrencySignCountInISOFormat;
+                        }
+                    } else {
+                        fCurrencySignCount = fgCurrencySignCountInSymbolFormat;
                     }
-                    isCurrency = TRUE;
                     // Fall through to append(ch)
                 } else if (ch == kQuote) {
                     // A quote outside quotes indicates either the opening
@@ -3418,7 +4967,6 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
                 fMinExponentDigits = expDigits;
             }
             fExponentSignAlwaysShown = expSignAlways;
-            fIsCurrencyFormat = isCurrency;
             int32_t digitTotalCount = digitLeftCount + zeroDigitCount + digitRightCount;
             // The effectiveDecimalPos is the position the decimal is at or
             // would be at if there is no decimal.  Note that if
@@ -3445,7 +4993,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
             fGroupingSize = (groupingCount > 0) ? groupingCount : 0;
             fGroupingSize2 = (groupingCount2 > 0 && groupingCount2 != groupingCount)
                 ? groupingCount2 : 0;
-            fMultiplier = multiplier;
+            setMultiplier(multiplier);
             setDecimalSeparatorAlwaysShown(decimalPos == 0
                     || decimalPos == digitTotalCount);
             if (padPos >= 0) {
@@ -3461,20 +5009,19 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
                 fFormatWidth = 0;
             }
             if (roundingPos >= 0) {
-                roundingInc.fDecimalAt = effectiveDecimalPos - roundingPos;
+                roundingInc.setDecimalAt(effectiveDecimalPos - roundingPos);
                 if (fRoundingIncrement != NULL) {
                     *fRoundingIncrement = roundingInc;
                 } else {
                     fRoundingIncrement = new DigitList(roundingInc);
                     /* test for NULL */
-                    if (fRoundingIncrement == 0) {
+                    if (fRoundingIncrement == NULL) {
                         status = U_MEMORY_ALLOCATION_ERROR;
                         delete fPosPrefixPattern;
                         delete fPosSuffixPattern;
                         return;
                     }
                 }
-                fRoundingDouble = fRoundingIncrement->getDouble();
                 fRoundingMode = kRoundHalfEven;
             } else {
                 setRoundingIncrement(0.0);
@@ -3529,11 +5076,11 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
         setMaximumFractionDigits(kDoubleFractionDigits);
 
         fUseExponentialNotation = FALSE;
-        fIsCurrencyFormat = FALSE;
+        fCurrencySignCount = 0;
         setGroupingUsed(FALSE);
         fGroupingSize = 0;
         fGroupingSize2 = 0;
-        fMultiplier = 1;
+        setMultiplier(1);
         setDecimalSeparatorAlwaysShown(FALSE);
         fFormatWidth = 0;
         setRoundingIncrement(0.0);
@@ -3545,7 +5092,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
     if (fNegPrefixPattern == NULL ||
         (*fNegPrefixPattern == *fPosPrefixPattern
          && *fNegSuffixPattern == *fPosSuffixPattern)) {
-        _copy_us_ptr(&fNegSuffixPattern, fPosSuffixPattern);
+        _copy_ptr(&fNegSuffixPattern, fPosSuffixPattern);
         if (fNegPrefixPattern == NULL) {
             fNegPrefixPattern = new UnicodeString();
             /* test for NULL */
@@ -3561,16 +5108,70 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
     }
 #ifdef FMT_DEBUG
     UnicodeString s;
-    s.append("\"").append(pattern).append("\"->");
+    s.append((UnicodeString)"\"").append(pattern).append((UnicodeString)"\"->");
     debugout(s);
 #endif
-    expandAffixes();
+
+    // save the pattern
+    fFormatPattern = pattern;
+}
+
+
+void
+DecimalFormat::expandAffixAdjustWidth(const UnicodeString* pluralCount) {
+    expandAffixes(pluralCount);
     if (fFormatWidth > 0) {
         // Finish computing format width (see above)
-        fFormatWidth += fPositivePrefix.length() + fPositiveSuffix.length();
+            // TODO: how to handle fFormatWidth,
+            // need to save in f(Plural)AffixesForCurrecy?
+            fFormatWidth += fPositivePrefix.length() + fPositiveSuffix.length();
+    }
+}
+
+
+void
+DecimalFormat::applyPattern(const UnicodeString& pattern,
+                            UBool localized,
+                            UParseError& parseError,
+                            UErrorCode& status)
+{
+    // do the following re-set first. since they change private data by
+    // apply pattern again.
+    if (pattern.indexOf(kCurrencySign) != -1) {
+        if (fCurrencyPluralInfo == NULL) {
+            // initialize currencyPluralInfo if needed
+            fCurrencyPluralInfo = new CurrencyPluralInfo(fSymbols->getLocale(), status);
+        }
+        if (fAffixPatternsForCurrency == NULL) {
+            setupCurrencyAffixPatterns(status);
+        }
+        if (pattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
+            // only setup the affixes of the current pattern.
+            setupCurrencyAffixes(pattern, TRUE, FALSE, status);
+        }
     }
+    applyPatternWithoutExpandAffix(pattern, localized, parseError, status);
+    expandAffixAdjustWidth(NULL);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
+}
+
+
+void
+DecimalFormat::applyPatternInternally(const UnicodeString& pluralCount,
+                                      const UnicodeString& pattern,
+                                      UBool localized,
+                                      UParseError& parseError,
+                                      UErrorCode& status) {
+    applyPatternWithoutExpandAffix(pattern, localized, parseError, status);
+    expandAffixAdjustWidth(&pluralCount);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
+
 /**
  * Sets the maximum number of digits allowed in the integer portion of a
  * number. This override limits the integer digit count to 309.
@@ -3578,6 +5179,9 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
  */
 void DecimalFormat::setMaximumIntegerDigits(int32_t newValue) {
     NumberFormat::setMaximumIntegerDigits(_min(newValue, kDoubleIntegerDigits));
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -3587,6 +5191,9 @@ void DecimalFormat::setMaximumIntegerDigits(int32_t newValue) {
  */
 void DecimalFormat::setMinimumIntegerDigits(int32_t newValue) {
     NumberFormat::setMinimumIntegerDigits(_min(newValue, kDoubleIntegerDigits));
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -3596,6 +5203,9 @@ void DecimalFormat::setMinimumIntegerDigits(int32_t newValue) {
  */
 void DecimalFormat::setMaximumFractionDigits(int32_t newValue) {
     NumberFormat::setMaximumFractionDigits(_min(newValue, kDoubleFractionDigits));
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 /**
@@ -3605,6 +5215,9 @@ void DecimalFormat::setMaximumFractionDigits(int32_t newValue) {
  */
 void DecimalFormat::setMinimumFractionDigits(int32_t newValue) {
     NumberFormat::setMinimumFractionDigits(_min(newValue, kDoubleFractionDigits));
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 int32_t DecimalFormat::getMinimumSignificantDigits() const {
@@ -3617,12 +5230,15 @@ int32_t DecimalFormat::getMaximumSignificantDigits() const {
 
 void DecimalFormat::setMinimumSignificantDigits(int32_t min) {
     if (min < 1) {
-        min = 1;   
+        min = 1;
     }
     // pin max sig dig to >= min
     int32_t max = _max(fMaxSignificantDigits, min);
     fMinSignificantDigits = min;
     fMaxSignificantDigits = max;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 void DecimalFormat::setMaximumSignificantDigits(int32_t max) {
@@ -3634,6 +5250,9 @@ void DecimalFormat::setMaximumSignificantDigits(int32_t max) {
     int32_t min = _min(fMinSignificantDigits, max);
     fMinSignificantDigits = min;
     fMaxSignificantDigits = max;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 UBool DecimalFormat::areSignificantDigitsUsed() const {
@@ -3642,9 +5261,13 @@ UBool DecimalFormat::areSignificantDigitsUsed() const {
 
 void DecimalFormat::setSignificantDigitsUsed(UBool useSignificantDigits) {
     fUseSignificantDigits = useSignificantDigits;
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
-void DecimalFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
+void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
+                                          UErrorCode& ec) {
     // If we are a currency format, then modify our affixes to
     // encode the currency symbol for the given currency in our
     // locale, and adjust the decimal digits and rounding for the
@@ -3652,38 +5275,65 @@ void DecimalFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
 
     // Note: The code is ordered so that this object is *not changed*
     // until we are sure we are going to succeed.
-    
+
     // NULL or empty currency is *legal* and indicates no currency.
     UBool isCurr = (theCurrency && *theCurrency);
 
     double rounding = 0.0;
     int32_t frac = 0;
-    if (fIsCurrencyFormat && isCurr) {
+    if (fCurrencySignCount > fgCurrencySignCountZero && isCurr) {
         rounding = ucurr_getRoundingIncrement(theCurrency, &ec);
         frac = ucurr_getDefaultFractionDigits(theCurrency, &ec);
     }
-     
+
     NumberFormat::setCurrency(theCurrency, ec);
     if (U_FAILURE(ec)) return;
 
-    if (fIsCurrencyFormat) {
+    if (fCurrencySignCount > fgCurrencySignCountZero) {
         // NULL or empty currency is *legal* and indicates no currency.
         if (isCurr) {
             setRoundingIncrement(rounding);
             setMinimumFractionDigits(frac);
             setMaximumFractionDigits(frac);
         }
-        expandAffixes();
+        expandAffixes(NULL);
+    }
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
+}
+
+void DecimalFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
+    // set the currency before compute affixes to get the right currency names
+    NumberFormat::setCurrency(theCurrency, ec);
+    if (fFormatPattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
+        UnicodeString savedPtn = fFormatPattern;
+        setupCurrencyAffixes(fFormatPattern, TRUE, TRUE, ec);
+        UParseError parseErr;
+        applyPattern(savedPtn, FALSE, parseErr, ec);
     }
+    // set the currency after apply pattern to get the correct rounding/fraction
+    setCurrencyInternally(theCurrency, ec);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
 // Deprecated variant with no UErrorCode parameter
 void DecimalFormat::setCurrency(const UChar* theCurrency) {
     UErrorCode ec = U_ZERO_ERROR;
     setCurrency(theCurrency, ec);
+#if UCONFIG_FORMAT_FASTPATHS_49
+    handleChanged();
+#endif
 }
 
-void DecimalFormat::getEffectiveCurrency(UChar* result, UErrorCode& /*ec*/) const {
+void DecimalFormat::getEffectiveCurrency(UChar* result, UErrorCode& ec) const {
+    if (fSymbols == NULL) {
+        ec = U_MEMORY_ALLOCATION_ERROR;
+        return;
+    }
+    ec = U_ZERO_ERROR;
     const UChar* c = getCurrency();
     if (*c == 0) {
         const UnicodeString &intl =
@@ -3700,13 +5350,346 @@ void DecimalFormat::getEffectiveCurrency(UChar* result, UErrorCode& /*ec*/) cons
  * formats.
  */
 int32_t
-DecimalFormat::precision(UBool isIntegral) const {
+DecimalFormat::precision() const {
     if (areSignificantDigitsUsed()) {
         return getMaximumSignificantDigits();
     } else if (fUseExponentialNotation) {
         return getMinimumIntegerDigits() + getMaximumFractionDigits();
     } else {
-        return isIntegral ? 0 : getMaximumFractionDigits();
+        return getMaximumFractionDigits();
+    }
+}
+
+
+// TODO: template algorithm
+Hashtable*
+DecimalFormat::initHashForAffix(UErrorCode& status) {
+    if ( U_FAILURE(status) ) {
+        return NULL;
+    }
+    Hashtable* hTable;
+    if ( (hTable = new Hashtable(TRUE, status)) == NULL ) {
+        status = U_MEMORY_ALLOCATION_ERROR;
+        return NULL;
+    }
+    if ( U_FAILURE(status) ) {
+        delete hTable; 
+        return NULL;
+    }
+    hTable->setValueComparator(decimfmtAffixValueComparator);
+    return hTable;
+}
+
+Hashtable*
+DecimalFormat::initHashForAffixPattern(UErrorCode& status) {
+    if ( U_FAILURE(status) ) {
+        return NULL;
+    }
+    Hashtable* hTable;
+    if ( (hTable = new Hashtable(TRUE, status)) == NULL ) {
+        status = U_MEMORY_ALLOCATION_ERROR;
+        return NULL;
+    }
+    if ( U_FAILURE(status) ) {
+        delete hTable; 
+        return NULL;
+    }
+    hTable->setValueComparator(decimfmtAffixPatternValueComparator);
+    return hTable;
+}
+
+void
+DecimalFormat::deleteHashForAffix(Hashtable*& table)
+{
+    if ( table == NULL ) {
+        return;
+    }
+    int32_t pos = -1;
+    const UHashElement* element = NULL;
+    while ( (element = table->nextElement(pos)) != NULL ) {
+        const UHashTok valueTok = element->value;
+        const AffixesForCurrency* value = (AffixesForCurrency*)valueTok.pointer;
+        delete value;
+    }
+    delete table;
+    table = NULL;
+}
+
+
+
+void
+DecimalFormat::deleteHashForAffixPattern()
+{
+    if ( fAffixPatternsForCurrency == NULL ) {
+        return;
+    }
+    int32_t pos = -1;
+    const UHashElement* element = NULL;
+    while ( (element = fAffixPatternsForCurrency->nextElement(pos)) != NULL ) {
+        const UHashTok valueTok = element->value;
+        const AffixPatternsForCurrency* value = (AffixPatternsForCurrency*)valueTok.pointer;
+        delete value;
+    }
+    delete fAffixPatternsForCurrency;
+    fAffixPatternsForCurrency = NULL;
+}
+
+
+void
+DecimalFormat::copyHashForAffixPattern(const Hashtable* source,
+                                       Hashtable* target,
+                                       UErrorCode& status) {
+    if ( U_FAILURE(status) ) {
+        return;
+    }
+    int32_t pos = -1;
+    const UHashElement* element = NULL;
+    if ( source ) {
+        while ( (element = source->nextElement(pos)) != NULL ) {
+            const UHashTok keyTok = element->key;
+            const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+            const UHashTok valueTok = element->value;
+            const AffixPatternsForCurrency* value = (AffixPatternsForCurrency*)valueTok.pointer;
+            AffixPatternsForCurrency* copy = new AffixPatternsForCurrency(
+                value->negPrefixPatternForCurrency,
+                value->negSuffixPatternForCurrency,
+                value->posPrefixPatternForCurrency,
+                value->posSuffixPatternForCurrency,
+                value->patternType);
+            target->put(UnicodeString(*key), copy, status);
+            if ( U_FAILURE(status) ) {
+                return;
+            }
+        }
+    }
+}
+
+DecimalFormat& DecimalFormat::setAttribute( UNumberFormatAttribute attr,
+                                            int32_t newValue,
+                                            UErrorCode &status) {
+  if(U_FAILURE(status)) return *this;
+
+  switch(attr) {
+  case UNUM_LENIENT_PARSE:
+    setLenient(newValue!=0);
+    break;
+
+    case UNUM_PARSE_INT_ONLY:
+      setParseIntegerOnly(newValue!=0);
+      break;
+      
+    case UNUM_GROUPING_USED:
+      setGroupingUsed(newValue!=0);
+      break;
+        
+    case UNUM_DECIMAL_ALWAYS_SHOWN:
+      setDecimalSeparatorAlwaysShown(newValue!=0);
+        break;
+        
+    case UNUM_MAX_INTEGER_DIGITS:
+      setMaximumIntegerDigits(newValue);
+        break;
+        
+    case UNUM_MIN_INTEGER_DIGITS:
+      setMinimumIntegerDigits(newValue);
+        break;
+        
+    case UNUM_INTEGER_DIGITS:
+      setMinimumIntegerDigits(newValue);
+      setMaximumIntegerDigits(newValue);
+        break;
+        
+    case UNUM_MAX_FRACTION_DIGITS:
+      setMaximumFractionDigits(newValue);
+        break;
+        
+    case UNUM_MIN_FRACTION_DIGITS:
+      setMinimumFractionDigits(newValue);
+        break;
+        
+    case UNUM_FRACTION_DIGITS:
+      setMinimumFractionDigits(newValue);
+      setMaximumFractionDigits(newValue);
+      break;
+        
+    case UNUM_SIGNIFICANT_DIGITS_USED:
+      setSignificantDigitsUsed(newValue!=0);
+        break;
+
+    case UNUM_MAX_SIGNIFICANT_DIGITS:
+      setMaximumSignificantDigits(newValue);
+        break;
+        
+    case UNUM_MIN_SIGNIFICANT_DIGITS:
+      setMinimumSignificantDigits(newValue);
+        break;
+        
+    case UNUM_MULTIPLIER:
+      setMultiplier(newValue);    
+       break;
+        
+    case UNUM_GROUPING_SIZE:
+      setGroupingSize(newValue);    
+        break;
+        
+    case UNUM_ROUNDING_MODE:
+      setRoundingMode((DecimalFormat::ERoundingMode)newValue);
+        break;
+        
+    case UNUM_FORMAT_WIDTH:
+      setFormatWidth(newValue);
+        break;
+        
+    case UNUM_PADDING_POSITION:
+        /** The position at which padding will take place. */
+      setPadPosition((DecimalFormat::EPadPosition)newValue);
+        break;
+        
+    case UNUM_SECONDARY_GROUPING_SIZE:
+      setSecondaryGroupingSize(newValue);
+        break;
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+    case UNUM_PARSE_ALL_INPUT:
+      setParseAllInput((UNumberFormatAttributeValue)newValue);
+        break;
+#endif
+
+    /* These are stored in fBoolFlags */
+    case UNUM_PARSE_NO_EXPONENT:
+    case UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS:
+      if(!fBoolFlags.isValidValue(newValue)) {
+          status = U_ILLEGAL_ARGUMENT_ERROR;
+      } else {
+          fBoolFlags.set(attr, newValue);
+      }
+      break;
+
+    case UNUM_SCALE:
+        fScale = newValue;
+        break;
+
+    default:
+      status = U_UNSUPPORTED_ERROR;
+      break;
+  }
+  return *this;
+}
+
+int32_t DecimalFormat::getAttribute( UNumberFormatAttribute attr, 
+                                     UErrorCode &status ) const {
+  if(U_FAILURE(status)) return -1;
+  switch(attr) {
+    case UNUM_LENIENT_PARSE: 
+        return isLenient();
+
+    case UNUM_PARSE_INT_ONLY:
+        return isParseIntegerOnly();
+        
+    case UNUM_GROUPING_USED:
+        return isGroupingUsed();
+        
+    case UNUM_DECIMAL_ALWAYS_SHOWN:
+        return isDecimalSeparatorAlwaysShown();    
+        
+    case UNUM_MAX_INTEGER_DIGITS:
+        return getMaximumIntegerDigits();
+        
+    case UNUM_MIN_INTEGER_DIGITS:
+        return getMinimumIntegerDigits();
+        
+    case UNUM_INTEGER_DIGITS:
+        // TBD: what should this return?
+        return getMinimumIntegerDigits();
+        
+    case UNUM_MAX_FRACTION_DIGITS:
+        return getMaximumFractionDigits();
+        
+    case UNUM_MIN_FRACTION_DIGITS:
+        return getMinimumFractionDigits();
+        
+    case UNUM_FRACTION_DIGITS:
+        // TBD: what should this return?
+        return getMinimumFractionDigits();
+        
+    case UNUM_SIGNIFICANT_DIGITS_USED:
+        return areSignificantDigitsUsed();
+        
+    case UNUM_MAX_SIGNIFICANT_DIGITS:
+        return getMaximumSignificantDigits();
+        
+    case UNUM_MIN_SIGNIFICANT_DIGITS:
+        return getMinimumSignificantDigits();
+        
+    case UNUM_MULTIPLIER:
+        return getMultiplier();    
+        
+    case UNUM_GROUPING_SIZE:
+        return getGroupingSize();    
+        
+    case UNUM_ROUNDING_MODE:
+        return getRoundingMode();
+        
+    case UNUM_FORMAT_WIDTH:
+        return getFormatWidth();
+        
+    case UNUM_PADDING_POSITION:
+        return getPadPosition();
+        
+    case UNUM_SECONDARY_GROUPING_SIZE:
+        return getSecondaryGroupingSize();
+        
+    /* These are stored in fBoolFlags */
+    case UNUM_PARSE_NO_EXPONENT:
+    case UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS:
+      return fBoolFlags.get(attr);
+
+    case UNUM_SCALE:
+        return fScale;
+
+    default:
+        status = U_UNSUPPORTED_ERROR;
+        break;
+  }
+
+  return -1; /* undefined */
+}
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+void DecimalFormat::setParseAllInput(UNumberFormatAttributeValue value) {
+  fParseAllInput = value;
+#if UCONFIG_FORMAT_FASTPATHS_49
+  handleChanged();
+#endif
+}
+#endif
+
+void
+DecimalFormat::copyHashForAffix(const Hashtable* source,
+                                Hashtable* target,
+                                UErrorCode& status) {
+    if ( U_FAILURE(status) ) {
+        return;
+    }
+    int32_t pos = -1;
+    const UHashElement* element = NULL;
+    if ( source ) {
+        while ( (element = source->nextElement(pos)) != NULL ) {
+            const UHashTok keyTok = element->key;
+            const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+
+            const UHashTok valueTok = element->value;
+            const AffixesForCurrency* value = (AffixesForCurrency*)valueTok.pointer;
+            AffixesForCurrency* copy = new AffixesForCurrency(
+                value->negPrefixForCurrency,
+                value->negSuffixForCurrency,
+                value->posPrefixForCurrency,
+                value->posSuffixForCurrency);
+            target->put(UnicodeString(*key), copy, status);
+            if ( U_FAILURE(status) ) {
+                return;
+            }
+        }
     }
 }