]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/samples/numfmt/main.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / samples / numfmt / main.cpp
index 1ebd4948c37c90349b87ff26a521084646d238af..172202e46f3b9618a6f04c6ce09849eceb877e32 100644 (file)
@@ -1,8 +1,12 @@
 /********************************************************************
+ *   © 2016 and later: Unicode, Inc. and others.
+ *   License & terms of use: http://www.unicode.org/copyright.html#License
+ *************************************************************************
+ *************************************************************************
  * COPYRIGHT:
- * Copyright (c) 1999-2004, International Business Machines Corporation and
+ * Copyright (c) 1999-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
- ********************************************************************/
+ *************************************************************************/
 
 #include "unicode/utypes.h"
 #include "unicode/unistr.h"
@@ -16,8 +20,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
 extern "C" void capi();
 void cppapi();
 
@@ -113,7 +115,8 @@ setNumberFormatCurrency_2_4(NumberFormat &nf, const char *currency, UErrorCode &
     // check that the formatter is a DecimalFormat instance
     // necessary because we will cast to the DecimalFormat subclass to set
     // the currency symbol
-    if(nf.getDynamicClassID()!=DecimalFormat::getStaticClassID()) {
+    DecimalFormat *dnf=dynamic_cast<DecimalFormat *>(&nf);
+    if(dnf==NULL) {
         errorCode=U_ILLEGAL_ARGUMENT_ERROR;
         return;
     }
@@ -152,12 +155,12 @@ setNumberFormatCurrency_2_4(NumberFormat &nf, const char *currency, UErrorCode &
 
     int32_t i;
 
-    for(i=0; i<LENGTHOF(currencyMap); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(currencyMap); ++i) {
         if(strcmp(currency, currencyMap[i].currency)==0) {
             break;
         }
     }
-    if(i==LENGTHOF(currencyMap)) {
+    if(i==UPRV_LENGTHOF(currencyMap)) {
         // a more specific error code would be useful in a real application
         errorCode=U_UNSUPPORTED_ERROR;
         return;
@@ -168,12 +171,11 @@ setNumberFormatCurrency_2_4(NumberFormat &nf, const char *currency, UErrorCode &
     nf.setMinimumFractionDigits(currencyMap[i].fractionDigits);
     nf.setMaximumFractionDigits(currencyMap[i].fractionDigits);
 
-    DecimalFormat &dnf=(DecimalFormat &)nf;
-    dnf.setRoundingIncrement(currencyMap[i].roundingIncrement);
+    dnf->setRoundingIncrement(currencyMap[i].roundingIncrement);
 
-    DecimalFormatSymbols symbols(*dnf.getDecimalFormatSymbols());
+    DecimalFormatSymbols symbols(*dnf->getDecimalFormatSymbols());
     symbols.setSymbol(DecimalFormatSymbols::kCurrencySymbol, currencyMap[i].symbol);
-    dnf.setDecimalFormatSymbols(symbols); // do not adopt symbols: Jitterbug 2889
+    dnf->setDecimalFormatSymbols(symbols); // do not adopt symbols: Jitterbug 2889
 }
 
 /*
@@ -235,7 +237,7 @@ showCurrencyFormatting(UBool useICU26API) {
     // TODO: Using printf() here assumes that the runtime encoding is ASCII-friendly
     // and can therefore be mixed with UTF-8
 
-    for(i=0; i<LENGTHOF(sampleLocaleIDs); ++i) {
+    for(i=0; i<UPRV_LENGTHOF(sampleLocaleIDs); ++i) {
         printf("show currency formatting (method for %s) in the locale \"%s\"\n",
                 useICU26API ? "ICU 2.6" : "before ICU 2.6",
                 sampleLocaleIDs[i]);
@@ -249,7 +251,7 @@ showCurrencyFormatting(UBool useICU26API) {
             continue;
         }
 
-        for(j=0; j<LENGTHOF(sampleCurrencies); ++j) {
+        for(j=0; j<UPRV_LENGTHOF(sampleCurrencies); ++j) {
             printf("  - format currency \"%s\": ", sampleCurrencies[j]);
 
             // set the actual currency to be formatted