]> granicus.if.org Git - icu/commitdiff
ICU-10468 andy's review comments.
authorTravis Keep <keep94@gmail.com>
Thu, 16 Jan 2014 21:32:53 +0000 (21:32 +0000)
committerTravis Keep <keep94@gmail.com>
Thu, 16 Jan 2014 21:32:53 +0000 (21:32 +0000)
X-SVN-Rev: 34914

icu4c/source/i18n/decimalformatpattern.cpp
icu4c/source/i18n/decimalformatpattern.h
icu4c/source/i18n/decimfmt.cpp

index 4ed7ca367b4dfb5688545099342478e8caf06650..18ba073b8414eb7947ed047a3b8fb93cb94f182b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2013, International Business Machines Corporation and    *
+* Copyright (C) 1997-2014, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
@@ -71,6 +71,37 @@ static void syntaxError(const UnicodeString& pattern,
     parseError.postContext[stop-start]= 0;
 }
 
+DecimalFormatPattern::DecimalFormatPattern()
+        : fMinimumIntegerDigits(1),
+          fMaximumIntegerDigits(gDefaultMaxIntegerDigits),
+          fMinimumFractionDigits(0),
+          fMaximumFractionDigits(3),
+          fUseSignificantDigits(FALSE),
+          fMinimumSignificantDigits(1),
+          fMaximumSignificantDigits(6),
+          fUseExponentialNotation(FALSE),
+          fMinExponentDigits(0),
+          fExponentSignAlwaysShown(FALSE),
+          fCurrencySignCount(fgCurrencySignCountZero),
+          fGroupingUsed(TRUE),
+          fGroupingSize(0),
+          fGroupingSize2(0),
+          fMultiplier(1),
+          fDecimalSeparatorAlwaysShown(FALSE),
+          fFormatWidth(0),
+          fRoundingIncrementUsed(FALSE),
+          fRoundingIncrement(),
+          fPad(kPatternPadEscape),
+          fNegPatternsBogus(TRUE),
+          fPosPatternsBogus(TRUE),
+          fNegPrefixPattern(),
+          fNegSuffixPattern(),
+          fPosPrefixPattern(),
+          fPosSuffixPattern(),
+          fPadPosition(DecimalFormatPattern::kPadBeforePrefix) {
+}
+
+
 DecimalFormatPatternParser::DecimalFormatPatternParser() :
     fZeroDigit(kPatternZeroDigit),
     fSigDigit(kPatternSignificantDigit),
@@ -124,32 +155,7 @@ DecimalFormatPatternParser::applyPatternWithoutExpandAffix(
     {
         return;
     }
-
-    out.fMinimumIntegerDigits = 1;
-    out.fMaximumIntegerDigits = gDefaultMaxIntegerDigits;
-    out.fMinimumFractionDigits = 0;
-    out.fMaximumFractionDigits = 3;
-    out.fUseSignificantDigits = FALSE;
-    out.fMinimumSignificantDigits = 1;
-    out.fMaximumSignificantDigits = 6;
-    out.fUseExponentialNotation = FALSE;
-    out.fMinExponentDigits = 0;
-    out.fExponentSignAlwaysShown = FALSE;
-    out.fCurrencySignCount = fgCurrencySignCountZero;
-    out.fGroupingUsed = TRUE;
-    out.fGroupingSize = 0;
-    out.fGroupingSize2 = 0;
-    out.fMultiplier = 1;
-    out.fDecimalSeparatorAlwaysShown = FALSE;
-    out.fFormatWidth = 0;
-    out.fRoundingIncrementUsed = FALSE;
-    out.fPad = 0;
-    out.fNegPrefixPattern.setToBogus();
-    out.fNegSuffixPattern.setToBogus();
-    out.fPosPrefixPattern.setToBogus();
-    out.fPosSuffixPattern.setToBogus();
-    out.fPadPosition = DecimalFormatPattern::kPadBeforePrefix;
-    out.fPad = kPatternPadEscape;
+    out = DecimalFormatPattern();
 
     // Clear error struct
     parseError.offset = -1;
@@ -542,10 +548,12 @@ DecimalFormatPatternParser::applyPatternWithoutExpandAffix(
         }
 
         if (part == 0) {
+            out.fPosPatternsBogus = FALSE;
             out.fPosPrefixPattern = prefix;
             out.fPosSuffixPattern = suffix;
-            out.fNegPrefixPattern.setToBogus();
-            out.fNegSuffixPattern.setToBogus();
+            out.fNegPatternsBogus = TRUE;
+            out.fNegPrefixPattern.remove();
+            out.fNegSuffixPattern.remove();
 
             out.fUseExponentialNotation = (expDigits >= 0);
             if (out.fUseExponentialNotation) {
@@ -601,14 +609,17 @@ DecimalFormatPatternParser::applyPatternWithoutExpandAffix(
                 out.fRoundingIncrementUsed = FALSE;
             }
         } else {
+            out.fNegPatternsBogus = FALSE;
             out.fNegPrefixPattern = prefix;
             out.fNegSuffixPattern = suffix;
         }
     }
 
     if (pattern.length() == 0) {
-        out.fNegPrefixPattern.setToBogus();
-        out.fNegSuffixPattern.setToBogus();
+        out.fNegPatternsBogus = TRUE;
+        out.fNegPrefixPattern.remove();
+        out.fNegSuffixPattern.remove();
+        out.fPosPatternsBogus = FALSE;
         out.fPosPrefixPattern.remove();
         out.fPosSuffixPattern.remove();
 
@@ -631,11 +642,11 @@ DecimalFormatPatternParser::applyPatternWithoutExpandAffix(
     // If there was no negative pattern, or if the negative pattern is
     // identical to the positive pattern, then prepend the minus sign to the
     // positive pattern to form the negative pattern.
-    if (out.fNegPrefixPattern.isBogus() ||
+    if (out.fNegPatternsBogus ||
         (out.fNegPrefixPattern == out.fPosPrefixPattern
          && out.fNegSuffixPattern == out.fPosSuffixPattern)) {
+        out.fNegPatternsBogus = FALSE;
         out.fNegSuffixPattern = out.fPosSuffixPattern;
-        out.fNegPrefixPattern.remove();
         out.fNegPrefixPattern.append(kQuote).append(kPatternMinus)
             .append(out.fPosPrefixPattern);
     }
index 4913b7cc5ae2b870e6b36c68298bde9a5eef4950..4b04d47d6b021e64cf0b5c1a3ef462464b8d7ec3 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2013, International Business Machines Corporation and    *
+* Copyright (C) 1997-2014, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
@@ -35,6 +35,8 @@ struct DecimalFormatPattern : UMemory {
       kPadAfterSuffix
   };
 
+  DecimalFormatPattern();
+
   int32_t fMinimumIntegerDigits;
   int32_t fMaximumIntegerDigits;
   int32_t fMinimumFractionDigits;
@@ -55,10 +57,8 @@ struct DecimalFormatPattern : UMemory {
   UBool fRoundingIncrementUsed;
   DigitList fRoundingIncrement;
   UChar32 fPad;
-
-  // These next four can be set to empty or bogus as
-  // there is a difference between having an empty
-  // pattern and having an unspecified pattern.
+  UBool fNegPatternsBogus;
+  UBool fPosPatternsBogus;
   UnicodeString fNegPrefixPattern;
   UnicodeString fNegSuffixPattern;
   UnicodeString fPosPrefixPattern;
index d9404fcd908bcc2206527209abe0bda2b761346f..d6864dc6fa39163ba1ef8cb6d4417a68fed50592 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *******************************************************************************
-* Copyright (C) 1997-2013, International Business Machines Corporation and    *
+* Copyright (C) 1997-2014, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 *
@@ -37,7 +37,6 @@
 ********************************************************************************
 */
 
-#include <iostream>
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_FORMATTING
 #include "plurrule_impl.h"
 #include "decimalformatpattern.h"
 
-#define COMPLAIN(W, X, Y) (std::cout << (W) << ": " << (X) << ", got: " << (Y) << std::endl)
-
-#define CHECK_COMPLAIN(W, X, Y) if ((X) != (Y)) COMPLAIN(W, X, Y)
-
-#define CHECK_STRING(W, X, Y) if (((X) == NULL && !(Y).isBogus()) || ((X) != NULL && (Y) != *(X))) COMPLAIN(W, "EXPECTED", "ACTUAL")
-
 /*
  * On certain platforms, round is a macro defined in math.h
  * This undefine is to avoid conflict between the macro and
@@ -296,11 +289,11 @@ 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; }
 
-static void copyString(const UnicodeString& src, UnicodeString *& dest, UErrorCode &status) {
+static void copyString(const UnicodeString& src, UBool isBogus, UnicodeString *& dest, UErrorCode &status) {
     if (U_FAILURE(status)) {
         return;
     }
-    if (src.isBogus()) {
+    if (isBogus) {
         delete dest;
         dest = NULL;
     } else {
@@ -4908,10 +4901,10 @@ DecimalFormat::applyPatternWithoutExpandAffix(const UnicodeString& pattern,
             fPadPosition = kPadAfterSuffix;
             break;
     }
-    copyString(out.fNegPrefixPattern, fNegPrefixPattern, status);
-    copyString(out.fNegSuffixPattern, fNegSuffixPattern, status);
-    copyString(out.fPosPrefixPattern, fPosPrefixPattern, status);
-    copyString(out.fPosSuffixPattern, fPosSuffixPattern, status);
+    copyString(out.fNegPrefixPattern, out.fNegPatternsBogus, fNegPrefixPattern, status);
+    copyString(out.fNegSuffixPattern, out.fNegPatternsBogus, fNegSuffixPattern, status);
+    copyString(out.fPosPrefixPattern, out.fPosPatternsBogus, fPosPrefixPattern, status);
+    copyString(out.fPosSuffixPattern, out.fPosPatternsBogus, fPosSuffixPattern, status);
 }