From f2738c97878b0cc17716419ef7941cd663fd0bd1 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Thu, 16 Jan 2014 21:32:53 +0000 Subject: [PATCH] ICU-10468 andy's review comments. X-SVN-Rev: 34914 --- icu4c/source/i18n/decimalformatpattern.cpp | 77 ++++++++++++---------- icu4c/source/i18n/decimalformatpattern.h | 10 +-- icu4c/source/i18n/decimfmt.cpp | 21 ++---- 3 files changed, 56 insertions(+), 52 deletions(-) diff --git a/icu4c/source/i18n/decimalformatpattern.cpp b/icu4c/source/i18n/decimalformatpattern.cpp index 4ed7ca367b4..18ba073b841 100644 --- a/icu4c/source/i18n/decimalformatpattern.cpp +++ b/icu4c/source/i18n/decimalformatpattern.cpp @@ -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); } diff --git a/icu4c/source/i18n/decimalformatpattern.h b/icu4c/source/i18n/decimalformatpattern.h index 4913b7cc5ae..4b04d47d6b0 100644 --- a/icu4c/source/i18n/decimalformatpattern.h +++ b/icu4c/source/i18n/decimalformatpattern.h @@ -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; diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index d9404fcd908..d6864dc6fa3 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -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 #include "unicode/utypes.h" #if !UCONFIG_NO_FORMATTING @@ -74,12 +73,6 @@ #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