]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/nfsubs.cpp
ICU-491.11.2.tar.gz
[apple/icu.git] / icuSources / i18n / nfsubs.cpp
index 0ac7ec97fd02c04f99d092a856f756665f82c35c..d02c9e15ce4f91c8d382058432f3959c56ad4d2c 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ******************************************************************************
-*   Copyright (C) 1997-2010, International Business Machines
+*   Copyright (C) 1997-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ******************************************************************************
 *   file name:  nfsubs.cpp
@@ -51,6 +51,7 @@ public:
         const RuleBasedNumberFormat* formatter,
         const UnicodeString& description,
         UErrorCode& status);
+    virtual ~SameValueSubstitution();
 
     virtual int64_t transformNumber(int64_t number) const { return number; }
     virtual double transformNumber(double number) const { return number; }
@@ -63,6 +64,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+SameValueSubstitution::~SameValueSubstitution() {}
+
 class MultiplierSubstitution : public NFSubstitution {
     double divisor;
     int64_t ldivisor;
@@ -81,6 +84,7 @@ public:
             status = U_PARSE_ERROR;
         }
     }
+    virtual ~MultiplierSubstitution();
 
     virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) { 
         divisor = uprv_pow(radix, exponent);
@@ -118,6 +122,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+MultiplierSubstitution::~MultiplierSubstitution() {}
+
 class ModulusSubstitution : public NFSubstitution {
     double divisor;
     int64_t  ldivisor;
@@ -130,6 +136,7 @@ public:
         const RuleBasedNumberFormat* formatter,
         const UnicodeString& description,
         UErrorCode& status);
+    virtual ~ModulusSubstitution();
 
     virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) { 
         divisor = uprv_pow(radix, exponent);
@@ -165,11 +172,15 @@ public:
 
     virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
 
+       virtual void toString(UnicodeString& result) const;
+
 public:
     static UClassID getStaticClassID(void);
     virtual UClassID getDynamicClassID(void) const;
 };
 
+ModulusSubstitution::~ModulusSubstitution() {}
+
 class IntegralPartSubstitution : public NFSubstitution {
 public:
     IntegralPartSubstitution(int32_t _pos,
@@ -178,6 +189,7 @@ public:
         const UnicodeString& description,
         UErrorCode& status)
         : NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
+    virtual ~IntegralPartSubstitution();
 
     virtual int64_t transformNumber(int64_t number) const { return number; }
     virtual double transformNumber(double number) const { return uprv_floor(number); }
@@ -190,6 +202,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+IntegralPartSubstitution::~IntegralPartSubstitution() {}
+
 class FractionalPartSubstitution : public NFSubstitution {
     UBool byDigits;
     UBool useSpaces;
@@ -200,6 +214,7 @@ public:
         const RuleBasedNumberFormat* formatter,
         const UnicodeString& description,
         UErrorCode& status);
+    virtual ~FractionalPartSubstitution();
 
     virtual UBool operator==(const NFSubstitution& rhs) const;
 
@@ -224,6 +239,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+FractionalPartSubstitution::~FractionalPartSubstitution() {}
+
 class AbsoluteValueSubstitution : public NFSubstitution {
 public:
     AbsoluteValueSubstitution(int32_t _pos,
@@ -232,6 +249,7 @@ public:
         const UnicodeString& description,
         UErrorCode& status)
         : NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
+    virtual ~AbsoluteValueSubstitution();
 
     virtual int64_t transformNumber(int64_t number) const { return number >= 0 ? number : -number; }
     virtual double transformNumber(double number) const { return uprv_fabs(number); }
@@ -244,6 +262,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+AbsoluteValueSubstitution::~AbsoluteValueSubstitution() {}
+
 class NumeratorSubstitution : public NFSubstitution {
     double denominator;
     int64_t ldenominator;
@@ -267,6 +287,7 @@ public:
         ldenominator = util64_fromDouble(denominator);
         withZeros = description.endsWith(LTLT, 2);
     }
+    virtual ~NumeratorSubstitution();
 
     virtual UBool operator==(const NFSubstitution& rhs) const;
 
@@ -293,6 +314,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+NumeratorSubstitution::~NumeratorSubstitution() {}
+
 class NullSubstitution : public NFSubstitution {
 public:
     NullSubstitution(int32_t _pos,
@@ -301,6 +324,7 @@ public:
         const UnicodeString& description,
         UErrorCode& status)
         : NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
+    virtual ~NullSubstitution();
 
     virtual void toString(UnicodeString& /*result*/) const {}
     virtual void doSubstitution(double /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {}
@@ -324,6 +348,8 @@ public:
     virtual UClassID getDynamicClassID(void) const;
 };
 
+NullSubstitution::~NullSubstitution() {}
+
 NFSubstitution*
 NFSubstitution::makeSubstitution(int32_t pos,
                                  const NFRule* rule,
@@ -802,7 +828,7 @@ SameValueSubstitution::SameValueSubstitution(int32_t _pos,
                         UErrorCode& status)
 : NFSubstitution(_pos, _ruleSet, formatter, description, status)
 {
-    if (description == gEqualsEquals) {
+    if (0 == description.compare(gEqualsEquals, 2)) {
         // throw new IllegalArgumentException("== is not a legal token");
         status = U_PARSE_ERROR;
     }
@@ -853,7 +879,7 @@ ModulusSubstitution::ModulusSubstitution(int32_t _pos,
       status = U_PARSE_ERROR;
   }
 
-  if (description == gGreaterGreaterGreaterThan) {
+  if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
     // the >>> token doesn't alter how this substituion calculates the
     // values it uses for formatting and parsing, but it changes
     // what's done with that value after it's obtained: >>> short-
@@ -970,8 +996,29 @@ ModulusSubstitution::doParse(const UnicodeString& text,
         return TRUE;
     }
 }
+/**
+ * Returns a textual description of the substitution
+ * @return A textual description of the substitution.  This might
+ * not be identical to the description it was created from, but
+ * it'll produce the same result.
+ */
+void
+ModulusSubstitution::toString(UnicodeString& text) const
+{
+  // use tokenChar() to get the character at the beginning and
+  // end of the substitutin token.  In between them will go
+  // either the name of the rule set it uses, or the pattern of
+  // the DecimalFormat it uses
 
-
+  if ( ruleToUse != NULL ) { // Must have been a >>> substitution.
+      text.remove();
+      text.append(tokenChar());
+      text.append(tokenChar());
+      text.append(tokenChar());
+  } else { // Otherwise just use the super-class function.
+         NFSubstitution::toString(text);
+  }
+}
 //===================================================================
 // IntegralPartSubstitution
 //===================================================================
@@ -1000,11 +1047,11 @@ FractionalPartSubstitution::FractionalPartSubstitution(int32_t _pos,
 
 {
     // akk, ruleSet can change in superclass constructor
-    if (description == gGreaterGreaterThan ||
-        description == gGreaterGreaterGreaterThan ||
+    if (0 == description.compare(gGreaterGreaterThan, 2) ||
+        0 == description.compare(gGreaterGreaterGreaterThan, 3) ||
         _ruleSet == getRuleSet()) {
         byDigits = TRUE;
-        if (description == gGreaterGreaterGreaterThan) {
+        if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
             useSpaces = FALSE;
         }
     } else {