X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..2ca993e82fb37b597a3c73ecd1586a139a6579c5:/icuSources/i18n/nfsubs.h diff --git a/icuSources/i18n/nfsubs.h b/icuSources/i18n/nfsubs.h index ec03fee9..2b8beeaa 100644 --- a/icuSources/i18n/nfsubs.h +++ b/icuSources/i18n/nfsubs.h @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1997-2004, International Business Machines +* Copyright (C) 1997-2015, International Business Machines * Corporation and others. All Rights Reserved. ****************************************************************************** * file name: nfsubs.h @@ -32,12 +32,11 @@ U_NAMESPACE_BEGIN class NFSubstitution : public UObject { int32_t pos; const NFRuleSet* ruleSet; - const DecimalFormat* numberFormat; + DecimalFormat* numberFormat; protected: NFSubstitution(int32_t pos, const NFRuleSet* ruleSet, - const RuleBasedNumberFormat* rbnf, const UnicodeString& description, UErrorCode& status); @@ -98,6 +97,8 @@ public: */ virtual void toString(UnicodeString& result) const; + void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status); + //----------------------------------------------------------------------- // formatting //----------------------------------------------------------------------- @@ -112,7 +113,7 @@ public: * rule text begins (this value is added to this substitution's * position to determine exactly where to insert the new text) */ - virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos) const; + virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const; /** * Performs a mathematical operation on the number, formats it using @@ -124,7 +125,7 @@ public: * rule text begins (this value is added to this substitution's * position to determine exactly where to insert the new text) */ - virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const; + virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const; protected: /** @@ -232,14 +233,6 @@ public: */ virtual UChar tokenChar() const = 0; - /** - * Returns true if this is a null substitution. (We didn't do this - * with instanceof partially because it causes source files to - * proliferate and partially because we have to port this to C++.) - * @return true if this object is an instance of NullSubstitution - */ - virtual UBool isNullSubstitution() const; - /** * Returns true if this is a modulus substitution. (We didn't do this * with instanceof partially because it causes source files to @@ -248,298 +241,24 @@ public: */ virtual UBool isModulusSubstitution() const; -private: - NFSubstitution(const NFSubstitution &other); // forbid copying of this class - NFSubstitution &operator=(const NFSubstitution &other); // forbid copying of this class - - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class SameValueSubstitution : public NFSubstitution { -public: - SameValueSubstitution(int32_t pos, - const NFRuleSet* ruleset, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status); - - virtual int64_t transformNumber(int64_t number) const { return number; } - virtual double transformNumber(double number) const { return number; } - virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return newRuleValue; } - virtual double calcUpperBound(double oldUpperBound) const { return oldUpperBound; } - virtual UChar tokenChar() const { return (UChar)0x003d; } // '=' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class MultiplierSubstitution : public NFSubstitution { - double divisor; - int64_t ldivisor; - -public: - MultiplierSubstitution(int32_t _pos, - double _divisor, - const NFRuleSet* _ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, formatter, description, status), divisor(_divisor) - { - ldivisor = util64_fromDouble(divisor); - if (divisor == 0) { - status = U_PARSE_ERROR; - } - } - - virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) { - divisor = uprv_pow(radix, exponent); - ldivisor = util64_fromDouble(divisor); - - if(divisor == 0) { - status = U_PARSE_ERROR; - } - } - - virtual UBool operator==(const NFSubstitution& rhs) const; - - virtual int64_t transformNumber(int64_t number) const { - return number / ldivisor; - } - - virtual double transformNumber(double number) const { - return uprv_floor(number / divisor); - } - - virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { - return newRuleValue * divisor; - } - - virtual double calcUpperBound(double /*oldUpperBound*/) const { return divisor; } - - virtual UChar tokenChar() const { return (UChar)0x003c; } // '<' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class ModulusSubstitution : public NFSubstitution { - double divisor; - int64_t ldivisor; - const NFRule* ruleToUse; -public: - ModulusSubstitution(int32_t pos, - double _divisor, - const NFRule* rulePredecessor, - const NFRuleSet* ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status); - - virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) { - divisor = uprv_pow(radix, exponent); - ldivisor = util64_fromDouble(divisor); - - if (divisor == 0) { - status = U_PARSE_ERROR; - } - } - - virtual UBool operator==(const NFSubstitution& rhs) const; - - virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos) const; - virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const; - - virtual int64_t transformNumber(int64_t number) const { return number % ldivisor; } - virtual double transformNumber(double number) const { return uprv_fmod(number, divisor); } - - virtual UBool doParse(const UnicodeString& text, - ParsePosition& parsePosition, - double baseValue, - double upperBound, - UBool lenientParse, - Formattable& result) const; - - virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { - return oldRuleValue - uprv_fmod(oldRuleValue, divisor) + newRuleValue; - } - - virtual double calcUpperBound(double /*oldUpperBound*/) const { return divisor; } - - virtual UBool isModulusSubstitution() const { return TRUE; } - - virtual UChar tokenChar() const { return (UChar)0x003e; } // '>' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class IntegralPartSubstitution : public NFSubstitution { -public: - IntegralPartSubstitution(int32_t _pos, - const NFRuleSet* _ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, formatter, description, status) {} - - virtual int64_t transformNumber(int64_t number) const { return number; } - virtual double transformNumber(double number) const { return uprv_floor(number); } - virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; } - virtual UChar tokenChar() const { return (UChar)0x003c; } // '<' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class FractionalPartSubstitution : public NFSubstitution { - UBool byDigits; - UBool useSpaces; - enum { kMaxDecimalDigits = 8 }; -public: - FractionalPartSubstitution(int32_t pos, - const NFRuleSet* ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status); - - virtual UBool operator==(const NFSubstitution& rhs) const; - - virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const; - virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {} - virtual int64_t transformNumber(int64_t /*number*/) const { return 0; } - virtual double transformNumber(double number) const { return number - uprv_floor(number); } - - virtual UBool doParse(const UnicodeString& text, - ParsePosition& parsePosition, - double baseValue, - double upperBound, - UBool lenientParse, - Formattable& result) const; - - virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return 0.0; } - virtual UChar tokenChar() const { return (UChar)0x003e; } // '>' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; - -class AbsoluteValueSubstitution : public NFSubstitution { -public: - AbsoluteValueSubstitution(int32_t _pos, - const NFRuleSet* _ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, formatter, description, status) {} - - virtual int64_t transformNumber(int64_t number) const { return number >= 0 ? number : -number; } - virtual double transformNumber(double number) const { return uprv_fabs(number); } - virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return -newRuleValue; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; } - virtual UChar tokenChar() const { return (UChar)0x003e; } // '>' -private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; + /** + * Apple addition + * @return true if this is a decimal format-only substitution + */ + virtual UBool isDecimalFormatSubstitutionOnly() const; -class NumeratorSubstitution : public NFSubstitution { - double denominator; - int64_t ldenominator; -public: - NumeratorSubstitution(int32_t _pos, - double _denominator, - const NFRuleSet* _ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, formatter, description, status), denominator(_denominator) - { - ldenominator = util64_fromDouble(denominator); - } - - virtual UBool operator==(const NFSubstitution& rhs) const; - - virtual int64_t transformNumber(int64_t number) const { return number * ldenominator; } - virtual double transformNumber(double number) const { return uprv_round(number * denominator); } + /** + * Apple addition, not currently used + * @return true if this substitution only points to another ruleSet (no numberFormat) + */ + //virtual UBool isRuleSetSubstitutionOnly() const; - virtual UBool doParse(const UnicodeString& text, - ParsePosition& parsePosition, - double baseValue, - double upperBound, - UBool /*lenientParse*/, - Formattable& result) const - { - // we don't have to do anything special to do the parsing here, - // but we have to turn lenient parsing off-- if we leave it on, - // it SERIOUSLY messes up the algorithm - return NFSubstitution::doParse(text, parsePosition, baseValue, upperBound, FALSE, result); - } - virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue / oldRuleValue; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return denominator; } - virtual UChar tokenChar() const { return (UChar)0x003c; } // '<' private: - static const char fgClassID; - -public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } - virtual UClassID getDynamicClassID(void) const; -}; + NFSubstitution(const NFSubstitution &other); // forbid copying of this class + NFSubstitution &operator=(const NFSubstitution &other); // forbid copying of this class -class NullSubstitution : public NFSubstitution { -public: - NullSubstitution(int32_t _pos, - const NFRuleSet* _ruleSet, - const RuleBasedNumberFormat* formatter, - const UnicodeString& description, - UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, formatter, description, status) {} - - virtual void toString(UnicodeString& /*result*/) const {} - virtual void doSubstitution(double /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {} - virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {} - virtual int64_t transformNumber(int64_t /*number*/) const { return 0; } - virtual double transformNumber(double /*number*/) const { return 0; } - virtual UBool doParse(const UnicodeString& /*text*/, - ParsePosition& /*parsePosition*/, - double baseValue, - double /*upperBound*/, - UBool /*lenientParse*/, - Formattable& result) const - { result.setDouble(baseValue); return TRUE; } - virtual double composeRuleValue(double /*newRuleValue*/, double /*oldRuleValue*/) const { return 0.0; } // never called - virtual double calcUpperBound(double /*oldUpperBound*/) const { return 0; } // never called - virtual UBool isNullSubstitution() const { return TRUE; } - virtual UChar tokenChar() const { return (UChar)0x0020; } // ' ' never called -private: - static const char fgClassID; - public: - static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } + static UClassID getStaticClassID(void); virtual UClassID getDynamicClassID(void) const; };