]> granicus.if.org Git - icu/commitdiff
ICU-7635 Modify toString method to handle >>>
authorJohn Emmons <emmo@us.ibm.com>
Wed, 26 Oct 2011 02:16:23 +0000 (02:16 +0000)
committerJohn Emmons <emmo@us.ibm.com>
Wed, 26 Oct 2011 02:16:23 +0000 (02:16 +0000)
X-SVN-Rev: 30868

icu4c/source/i18n/nfsubs.cpp
icu4c/source/test/cintltst/cnumtst.c
icu4c/source/test/cintltst/cnumtst.h

index 2798500d54b5b4397f2f5b1d165d21436ed8eb73..76274af458da963847b5c8ce370ea93c0d805872 100644 (file)
@@ -172,6 +172,8 @@ public:
 
     virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
 
+       virtual void toString(UnicodeString& result) const;
+
 public:
     static UClassID getStaticClassID(void);
     virtual UClassID getDynamicClassID(void) const;
@@ -976,8 +978,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
 //===================================================================
index 73e484dc4f3cc39e9f0c626e712ff0795b7153c0..ebc97621d537845adfb5deffdccf1174f09c0234 100644 (file)
@@ -59,6 +59,7 @@ void addNumForTest(TestNode** root)
     TESTCASE(TestInt64Parse);
     TESTCASE(TestParseZero);
     TESTCASE(TestParseCurrency);
+       TESTCASE(TestCloneWithRBNF);
 }
 
 /** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
@@ -1965,5 +1966,58 @@ static void TestNBSPInPattern(void) {
 
 
 }
+static void TestCloneWithRBNF(void) {
+    const wchar_t* pattern = L"\
+%main:0.x: >%%millis-only>;\n\
+x.0: <%%duration<;\n\
+x.x: <%%durationwithmillis<>%%millis-added>;\n\
+-x: ->>;%%millis-only:\n\
+1000: 00:00.<%%millis<;\n\
+%%millis-added:\n\
+1000: .<%%millis<;\n\
+%%millis:\n\
+0: =000=;\n\
+%%duration:\n\
+0: =%%seconds-only=;\n\
+60: =%%min-sec=;\n\
+3600: =%%hr-min-sec=;\n\
+86400/86400: <%%ddaayyss<[, >>];\n\
+%%durationwithmillis:\n\
+0: =%%seconds-only=;\n\
+60: =%%min-sec=;\n\
+3600: =%%hr-min-sec=;\n\
+86400/86400: <%%ddaayyss<, >>;\n\
+%%seconds-only:\n\
+0: 0:00:=00=;\n\
+%%min-sec:\n\
+0: :=00=;\n\
+60/60: 0:<00<>>;\n\
+%%hr-min-sec:\n\
+0: :=00=;\n\
+60/60: <00<>>;\n\
+3600/60: <0<:>>>;\n\
+%%ddaayyss:\n\
+0 days;\n\
+1 day;\n\
+=0= days;";
+
+       UErrorCode status = U_ZERO_ERROR;
+       UChar buffer[256];
+       UChar buffer_cloned[256];
+       char temp1[256];
+       char temp2[256];
+
+       UNumberFormat *pform_cloned;
+    UNumberFormat *pform = unum_open(UNUM_PATTERN_RULEBASED, pattern, -1, "en_US", NULL, &status);
+
+       unum_formatDouble(pform, 3600, buffer, 256, NULL, &status);
+
+       pform_cloned = unum_clone(pform,&status);
+       unum_formatDouble(pform_cloned, 3600, buffer_cloned, 256, NULL, &status);
+
+       if (u_strcmp(buffer,buffer_cloned)) {
+               log_err("Result from cloned formatter not identical to the original. Original: %s Cloned: %s",u_austrcpy(temp1, buffer),u_austrcpy(temp2,buffer_cloned));
+       }
 
+}
 #endif /* #if !UCONFIG_NO_FORMATTING */
index cc2258a2ecbb60c634edc407b740fb19b7372660..9115ad3a0853c3e6360df0f4bf3c6e72fd6c2bd1 100644 (file)
@@ -70,6 +70,11 @@ static void TestCurrencyRegression(void);
  **/
 static void TestParseZero(void);
 
+/**
+ * Test cloning formatter with RBNF
+ **/
+static void TestCloneWithRBNF(void);
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
 
 #endif