| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************* | 2 ******************************************************************************* |
| 3 * Copyright (C) 1996-2010, International Business Machines | 3 * Copyright (C) 1996-2010, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
| 5 ******************************************************************************* | 5 ******************************************************************************* |
| 6 * Modification History: | 6 * Modification History: |
| 7 * | 7 * |
| 8 * Date Name Description | 8 * Date Name Description |
| 9 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixe
s | 9 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixe
s |
| 10 ******************************************************************************* | 10 ******************************************************************************* |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 U_CAPI UNumberFormat* U_EXPORT2 | 162 U_CAPI UNumberFormat* U_EXPORT2 |
| 163 unum_clone(const UNumberFormat *fmt, | 163 unum_clone(const UNumberFormat *fmt, |
| 164 UErrorCode *status) | 164 UErrorCode *status) |
| 165 { | 165 { |
| 166 if(U_FAILURE(*status)) | 166 if(U_FAILURE(*status)) |
| 167 return 0; | 167 return 0; |
| 168 | 168 |
| 169 Format *res = 0; | 169 Format *res = 0; |
| 170 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); | 170 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); |
| 171 const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf); | 171 const DecimalFormat* df = CR_DYNAMIC_CAST<const DecimalFormat*>(nf); |
| 172 if (df != NULL) { | 172 if (df != NULL) { |
| 173 res = df->clone(); | 173 res = df->clone(); |
| 174 } else { | 174 } else { |
| 175 const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFo
rmat*>(nf); | 175 const RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<const RuleBasedNumbe
rFormat*>(nf); |
| 176 U_ASSERT(rbnf != NULL); | 176 U_ASSERT(rbnf != NULL); |
| 177 res = rbnf->clone(); | 177 res = rbnf->clone(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 if(res == 0) { | 180 if(res == 0) { |
| 181 *status = U_MEMORY_ALLOCATION_ERROR; | 181 *status = U_MEMORY_ALLOCATION_ERROR; |
| 182 return 0; | 182 return 0; |
| 183 } | 183 } |
| 184 | 184 |
| 185 return (UNumberFormat*) res; | 185 return (UNumberFormat*) res; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 const UChar* text, | 453 const UChar* text, |
| 454 int32_t textLength, | 454 int32_t textLength, |
| 455 int32_t* parsePos, /* 0 = start */ | 455 int32_t* parsePos, /* 0 = start */ |
| 456 UChar* currency, | 456 UChar* currency, |
| 457 UErrorCode* status) { | 457 UErrorCode* status) { |
| 458 Formattable res; | 458 Formattable res; |
| 459 parseRes(res, fmt, text, textLength, parsePos, TRUE, status); | 459 parseRes(res, fmt, text, textLength, parsePos, TRUE, status); |
| 460 currency[0] = 0; | 460 currency[0] = 0; |
| 461 const CurrencyAmount* c; | 461 const CurrencyAmount* c; |
| 462 if (res.getType() == Formattable::kObject && | 462 if (res.getType() == Formattable::kObject && |
| 463 (c = dynamic_cast<const CurrencyAmount*>(res.getObject())) != NULL) { | 463 (c = CR_DYNAMIC_CAST<const CurrencyAmount*>(res.getObject())) != NULL) { |
| 464 u_strcpy(currency, c->getISOCurrency()); | 464 u_strcpy(currency, c->getISOCurrency()); |
| 465 } | 465 } |
| 466 return res.getDouble(*status); | 466 return res.getDouble(*status); |
| 467 } | 467 } |
| 468 | 468 |
| 469 U_CAPI const char* U_EXPORT2 | 469 U_CAPI const char* U_EXPORT2 |
| 470 unum_getAvailable(int32_t index) | 470 unum_getAvailable(int32_t index) |
| 471 { | 471 { |
| 472 return uloc_getAvailable(index); | 472 return uloc_getAvailable(index); |
| 473 } | 473 } |
| 474 | 474 |
| 475 U_CAPI int32_t U_EXPORT2 | 475 U_CAPI int32_t U_EXPORT2 |
| 476 unum_countAvailable() | 476 unum_countAvailable() |
| 477 { | 477 { |
| 478 return uloc_countAvailable(); | 478 return uloc_countAvailable(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 U_CAPI int32_t U_EXPORT2 | 481 U_CAPI int32_t U_EXPORT2 |
| 482 unum_getAttribute(const UNumberFormat* fmt, | 482 unum_getAttribute(const UNumberFormat* fmt, |
| 483 UNumberFormatAttribute attr) | 483 UNumberFormatAttribute attr) |
| 484 { | 484 { |
| 485 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); | 485 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); |
| 486 const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf); | 486 const DecimalFormat* df = CR_DYNAMIC_CAST<const DecimalFormat*>(nf); |
| 487 if (df != NULL) { | 487 if (df != NULL) { |
| 488 switch(attr) { | 488 switch(attr) { |
| 489 case UNUM_PARSE_INT_ONLY: | 489 case UNUM_PARSE_INT_ONLY: |
| 490 return df->isParseIntegerOnly(); | 490 return df->isParseIntegerOnly(); |
| 491 | 491 |
| 492 case UNUM_GROUPING_USED: | 492 case UNUM_GROUPING_USED: |
| 493 return df->isGroupingUsed(); | 493 return df->isGroupingUsed(); |
| 494 | 494 |
| 495 case UNUM_DECIMAL_ALWAYS_SHOWN: | 495 case UNUM_DECIMAL_ALWAYS_SHOWN: |
| 496 return df->isDecimalSeparatorAlwaysShown(); | 496 return df->isDecimalSeparatorAlwaysShown(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 return df->getPadPosition(); | 540 return df->getPadPosition(); |
| 541 | 541 |
| 542 case UNUM_SECONDARY_GROUPING_SIZE: | 542 case UNUM_SECONDARY_GROUPING_SIZE: |
| 543 return df->getSecondaryGroupingSize(); | 543 return df->getSecondaryGroupingSize(); |
| 544 | 544 |
| 545 default: | 545 default: |
| 546 /* enums out of sync? unsupported enum? */ | 546 /* enums out of sync? unsupported enum? */ |
| 547 break; | 547 break; |
| 548 } | 548 } |
| 549 } else { | 549 } else { |
| 550 const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFormat
*>(nf); | 550 const RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<const RuleBasedNumberFor
mat*>(nf); |
| 551 U_ASSERT(rbnf != NULL); | 551 U_ASSERT(rbnf != NULL); |
| 552 if (attr == UNUM_LENIENT_PARSE) { | 552 if (attr == UNUM_LENIENT_PARSE) { |
| 553 #if !UCONFIG_NO_COLLATION | 553 #if !UCONFIG_NO_COLLATION |
| 554 return rbnf->isLenient(); | 554 return rbnf->isLenient(); |
| 555 #endif | 555 #endif |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 | 558 |
| 559 return -1; | 559 return -1; |
| 560 } | 560 } |
| 561 | 561 |
| 562 U_CAPI void U_EXPORT2 | 562 U_CAPI void U_EXPORT2 |
| 563 unum_setAttribute( UNumberFormat* fmt, | 563 unum_setAttribute( UNumberFormat* fmt, |
| 564 UNumberFormatAttribute attr, | 564 UNumberFormatAttribute attr, |
| 565 int32_t newValue) | 565 int32_t newValue) |
| 566 { | 566 { |
| 567 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); | 567 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); |
| 568 DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf); | 568 DecimalFormat* df = CR_DYNAMIC_CAST<DecimalFormat*>(nf); |
| 569 if (df != NULL) { | 569 if (df != NULL) { |
| 570 switch(attr) { | 570 switch(attr) { |
| 571 case UNUM_PARSE_INT_ONLY: | 571 case UNUM_PARSE_INT_ONLY: |
| 572 df->setParseIntegerOnly(newValue!=0); | 572 df->setParseIntegerOnly(newValue!=0); |
| 573 break; | 573 break; |
| 574 | 574 |
| 575 case UNUM_GROUPING_USED: | 575 case UNUM_GROUPING_USED: |
| 576 df->setGroupingUsed(newValue!=0); | 576 df->setGroupingUsed(newValue!=0); |
| 577 break; | 577 break; |
| 578 | 578 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 641 |
| 642 case UNUM_SECONDARY_GROUPING_SIZE: | 642 case UNUM_SECONDARY_GROUPING_SIZE: |
| 643 df->setSecondaryGroupingSize(newValue); | 643 df->setSecondaryGroupingSize(newValue); |
| 644 break; | 644 break; |
| 645 | 645 |
| 646 default: | 646 default: |
| 647 /* Shouldn't get here anyway */ | 647 /* Shouldn't get here anyway */ |
| 648 break; | 648 break; |
| 649 } | 649 } |
| 650 } else { | 650 } else { |
| 651 RuleBasedNumberFormat* rbnf = dynamic_cast<RuleBasedNumberFormat*>(nf); | 651 RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<RuleBasedNumberFormat*>(nf); |
| 652 U_ASSERT(rbnf != NULL); | 652 U_ASSERT(rbnf != NULL); |
| 653 if (attr == UNUM_LENIENT_PARSE) { | 653 if (attr == UNUM_LENIENT_PARSE) { |
| 654 #if !UCONFIG_NO_COLLATION | 654 #if !UCONFIG_NO_COLLATION |
| 655 rbnf->setLenient((UBool)newValue); | 655 rbnf->setLenient((UBool)newValue); |
| 656 #endif | 656 #endif |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 | 660 |
| 661 U_CAPI double U_EXPORT2 | 661 U_CAPI double U_EXPORT2 |
| 662 unum_getDoubleAttribute(const UNumberFormat* fmt, | 662 unum_getDoubleAttribute(const UNumberFormat* fmt, |
| 663 UNumberFormatAttribute attr) | 663 UNumberFormatAttribute attr) |
| 664 { | 664 { |
| 665 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); | 665 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); |
| 666 const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf); | 666 const DecimalFormat* df = CR_DYNAMIC_CAST<const DecimalFormat*>(nf); |
| 667 if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) { | 667 if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) { |
| 668 return df->getRoundingIncrement(); | 668 return df->getRoundingIncrement(); |
| 669 } else { | 669 } else { |
| 670 return -1.0; | 670 return -1.0; |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 | 673 |
| 674 U_CAPI void U_EXPORT2 | 674 U_CAPI void U_EXPORT2 |
| 675 unum_setDoubleAttribute( UNumberFormat* fmt, | 675 unum_setDoubleAttribute( UNumberFormat* fmt, |
| 676 UNumberFormatAttribute attr, | 676 UNumberFormatAttribute attr, |
| 677 double newValue) | 677 double newValue) |
| 678 { | 678 { |
| 679 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); | 679 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); |
| 680 DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf); | 680 DecimalFormat* df = CR_DYNAMIC_CAST<DecimalFormat*>(nf); |
| 681 if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) { | 681 if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) { |
| 682 df->setRoundingIncrement(newValue); | 682 df->setRoundingIncrement(newValue); |
| 683 } | 683 } |
| 684 } | 684 } |
| 685 | 685 |
| 686 U_CAPI int32_t U_EXPORT2 | 686 U_CAPI int32_t U_EXPORT2 |
| 687 unum_getTextAttribute(const UNumberFormat* fmt, | 687 unum_getTextAttribute(const UNumberFormat* fmt, |
| 688 UNumberFormatTextAttribute tag, | 688 UNumberFormatTextAttribute tag, |
| 689 UChar* result, | 689 UChar* result, |
| 690 int32_t resultLength, | 690 int32_t resultLength, |
| 691 UErrorCode* status) | 691 UErrorCode* status) |
| 692 { | 692 { |
| 693 if(U_FAILURE(*status)) | 693 if(U_FAILURE(*status)) |
| 694 return -1; | 694 return -1; |
| 695 | 695 |
| 696 UnicodeString res; | 696 UnicodeString res; |
| 697 if(!(result==NULL && resultLength==0)) { | 697 if(!(result==NULL && resultLength==0)) { |
| 698 // NULL destination for pure preflighting: empty dummy string | 698 // NULL destination for pure preflighting: empty dummy string |
| 699 // otherwise, alias the destination buffer | 699 // otherwise, alias the destination buffer |
| 700 res.setTo(result, 0, resultLength); | 700 res.setTo(result, 0, resultLength); |
| 701 } | 701 } |
| 702 | 702 |
| 703 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); | 703 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); |
| 704 const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf); | 704 const DecimalFormat* df = CR_DYNAMIC_CAST<const DecimalFormat*>(nf); |
| 705 if (df != NULL) { | 705 if (df != NULL) { |
| 706 switch(tag) { | 706 switch(tag) { |
| 707 case UNUM_POSITIVE_PREFIX: | 707 case UNUM_POSITIVE_PREFIX: |
| 708 df->getPositivePrefix(res); | 708 df->getPositivePrefix(res); |
| 709 break; | 709 break; |
| 710 | 710 |
| 711 case UNUM_POSITIVE_SUFFIX: | 711 case UNUM_POSITIVE_SUFFIX: |
| 712 df->getPositiveSuffix(res); | 712 df->getPositiveSuffix(res); |
| 713 break; | 713 break; |
| 714 | 714 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 726 | 726 |
| 727 case UNUM_CURRENCY_CODE: | 727 case UNUM_CURRENCY_CODE: |
| 728 res = UnicodeString(df->getCurrency()); | 728 res = UnicodeString(df->getCurrency()); |
| 729 break; | 729 break; |
| 730 | 730 |
| 731 default: | 731 default: |
| 732 *status = U_UNSUPPORTED_ERROR; | 732 *status = U_UNSUPPORTED_ERROR; |
| 733 return -1; | 733 return -1; |
| 734 } | 734 } |
| 735 } else { | 735 } else { |
| 736 const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFo
rmat*>(nf); | 736 const RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<const RuleBasedNumbe
rFormat*>(nf); |
| 737 U_ASSERT(rbnf != NULL); | 737 U_ASSERT(rbnf != NULL); |
| 738 if (tag == UNUM_DEFAULT_RULESET) { | 738 if (tag == UNUM_DEFAULT_RULESET) { |
| 739 res = rbnf->getDefaultRuleSetName(); | 739 res = rbnf->getDefaultRuleSetName(); |
| 740 } else if (tag == UNUM_PUBLIC_RULESETS) { | 740 } else if (tag == UNUM_PUBLIC_RULESETS) { |
| 741 int32_t count = rbnf->getNumberOfRuleSetNames(); | 741 int32_t count = rbnf->getNumberOfRuleSetNames(); |
| 742 for (int i = 0; i < count; ++i) { | 742 for (int i = 0; i < count; ++i) { |
| 743 res += rbnf->getRuleSetName(i); | 743 res += rbnf->getRuleSetName(i); |
| 744 res += (UChar)0x003b; // semicolon | 744 res += (UChar)0x003b; // semicolon |
| 745 } | 745 } |
| 746 } else { | 746 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 758 const UChar* newValue, | 758 const UChar* newValue, |
| 759 int32_t newValueLength, | 759 int32_t newValueLength, |
| 760 UErrorCode *status) | 760 UErrorCode *status) |
| 761 { | 761 { |
| 762 if(U_FAILURE(*status)) | 762 if(U_FAILURE(*status)) |
| 763 return; | 763 return; |
| 764 | 764 |
| 765 int32_t len = (newValueLength == -1 ? u_strlen(newValue) : newValueLength); | 765 int32_t len = (newValueLength == -1 ? u_strlen(newValue) : newValueLength); |
| 766 const UnicodeString val((UChar*)newValue, len, len); | 766 const UnicodeString val((UChar*)newValue, len, len); |
| 767 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); | 767 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); |
| 768 DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf); | 768 DecimalFormat* df = CR_DYNAMIC_CAST<DecimalFormat*>(nf); |
| 769 if (df != NULL) { | 769 if (df != NULL) { |
| 770 switch(tag) { | 770 switch(tag) { |
| 771 case UNUM_POSITIVE_PREFIX: | 771 case UNUM_POSITIVE_PREFIX: |
| 772 df->setPositivePrefix(val); | 772 df->setPositivePrefix(val); |
| 773 break; | 773 break; |
| 774 | 774 |
| 775 case UNUM_POSITIVE_SUFFIX: | 775 case UNUM_POSITIVE_SUFFIX: |
| 776 df->setPositiveSuffix(val); | 776 df->setPositiveSuffix(val); |
| 777 break; | 777 break; |
| 778 | 778 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 790 | 790 |
| 791 case UNUM_CURRENCY_CODE: | 791 case UNUM_CURRENCY_CODE: |
| 792 df->setCurrency(newValue, *status); | 792 df->setCurrency(newValue, *status); |
| 793 break; | 793 break; |
| 794 | 794 |
| 795 default: | 795 default: |
| 796 *status = U_UNSUPPORTED_ERROR; | 796 *status = U_UNSUPPORTED_ERROR; |
| 797 break; | 797 break; |
| 798 } | 798 } |
| 799 } else { | 799 } else { |
| 800 RuleBasedNumberFormat* rbnf = dynamic_cast<RuleBasedNumberFormat*>(nf); | 800 RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<RuleBasedNumberFormat*>(nf); |
| 801 U_ASSERT(rbnf != NULL); | 801 U_ASSERT(rbnf != NULL); |
| 802 if (tag == UNUM_DEFAULT_RULESET) { | 802 if (tag == UNUM_DEFAULT_RULESET) { |
| 803 rbnf->setDefaultRuleSet(newValue, *status); | 803 rbnf->setDefaultRuleSet(newValue, *status); |
| 804 } else { | 804 } else { |
| 805 *status = U_UNSUPPORTED_ERROR; | 805 *status = U_UNSUPPORTED_ERROR; |
| 806 } | 806 } |
| 807 } | 807 } |
| 808 } | 808 } |
| 809 | 809 |
| 810 U_CAPI int32_t U_EXPORT2 | 810 U_CAPI int32_t U_EXPORT2 |
| 811 unum_toPattern( const UNumberFormat* fmt, | 811 unum_toPattern( const UNumberFormat* fmt, |
| 812 UBool isPatternLocalized, | 812 UBool isPatternLocalized, |
| 813 UChar* result, | 813 UChar* result, |
| 814 int32_t resultLength, | 814 int32_t resultLength, |
| 815 UErrorCode* status) | 815 UErrorCode* status) |
| 816 { | 816 { |
| 817 if(U_FAILURE(*status)) | 817 if(U_FAILURE(*status)) |
| 818 return -1; | 818 return -1; |
| 819 | 819 |
| 820 UnicodeString pat; | 820 UnicodeString pat; |
| 821 if(!(result==NULL && resultLength==0)) { | 821 if(!(result==NULL && resultLength==0)) { |
| 822 // NULL destination for pure preflighting: empty dummy string | 822 // NULL destination for pure preflighting: empty dummy string |
| 823 // otherwise, alias the destination buffer | 823 // otherwise, alias the destination buffer |
| 824 pat.setTo(result, 0, resultLength); | 824 pat.setTo(result, 0, resultLength); |
| 825 } | 825 } |
| 826 | 826 |
| 827 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); | 827 const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt); |
| 828 const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf); | 828 const DecimalFormat* df = CR_DYNAMIC_CAST<const DecimalFormat*>(nf); |
| 829 if (df != NULL) { | 829 if (df != NULL) { |
| 830 if(isPatternLocalized) | 830 if(isPatternLocalized) |
| 831 df->toLocalizedPattern(pat); | 831 df->toLocalizedPattern(pat); |
| 832 else | 832 else |
| 833 df->toPattern(pat); | 833 df->toPattern(pat); |
| 834 } else { | 834 } else { |
| 835 const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberForm
at*>(nf); | 835 const RuleBasedNumberFormat* rbnf = CR_DYNAMIC_CAST<const RuleBasedNumberF
ormat*>(nf); |
| 836 U_ASSERT(rbnf != NULL); | 836 U_ASSERT(rbnf != NULL); |
| 837 pat = rbnf->getRules(); | 837 pat = rbnf->getRules(); |
| 838 } | 838 } |
| 839 return pat.extract(result, resultLength, *status); | 839 return pat.extract(result, resultLength, *status); |
| 840 } | 840 } |
| 841 | 841 |
| 842 U_CAPI int32_t U_EXPORT2 | 842 U_CAPI int32_t U_EXPORT2 |
| 843 unum_getSymbol(const UNumberFormat *fmt, | 843 unum_getSymbol(const UNumberFormat *fmt, |
| 844 UNumberFormatSymbol symbol, | 844 UNumberFormatSymbol symbol, |
| 845 UChar *buffer, | 845 UChar *buffer, |
| 846 int32_t size, | 846 int32_t size, |
| 847 UErrorCode *status) | 847 UErrorCode *status) |
| 848 { | 848 { |
| 849 if(status==NULL || U_FAILURE(*status)) { | 849 if(status==NULL || U_FAILURE(*status)) { |
| 850 return 0; | 850 return 0; |
| 851 } | 851 } |
| 852 if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT) { | 852 if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT) { |
| 853 *status=U_ILLEGAL_ARGUMENT_ERROR; | 853 *status=U_ILLEGAL_ARGUMENT_ERROR; |
| 854 return 0; | 854 return 0; |
| 855 } | 855 } |
| 856 const NumberFormat *nf = reinterpret_cast<const NumberFormat *>(fmt); | 856 const NumberFormat *nf = reinterpret_cast<const NumberFormat *>(fmt); |
| 857 const DecimalFormat *dcf = dynamic_cast<const DecimalFormat *>(nf); | 857 const DecimalFormat *dcf = CR_DYNAMIC_CAST<const DecimalFormat *>(nf); |
| 858 if (dcf == NULL) { | 858 if (dcf == NULL) { |
| 859 *status = U_UNSUPPORTED_ERROR; | 859 *status = U_UNSUPPORTED_ERROR; |
| 860 return 0; | 860 return 0; |
| 861 } | 861 } |
| 862 | 862 |
| 863 return dcf-> | 863 return dcf-> |
| 864 getDecimalFormatSymbols()-> | 864 getDecimalFormatSymbols()-> |
| 865 getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol). | 865 getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol). |
| 866 extract(buffer, size, *status); | 866 extract(buffer, size, *status); |
| 867 } | 867 } |
| 868 | 868 |
| 869 U_CAPI void U_EXPORT2 | 869 U_CAPI void U_EXPORT2 |
| 870 unum_setSymbol(UNumberFormat *fmt, | 870 unum_setSymbol(UNumberFormat *fmt, |
| 871 UNumberFormatSymbol symbol, | 871 UNumberFormatSymbol symbol, |
| 872 const UChar *value, | 872 const UChar *value, |
| 873 int32_t length, | 873 int32_t length, |
| 874 UErrorCode *status) | 874 UErrorCode *status) |
| 875 { | 875 { |
| 876 if(status==NULL || U_FAILURE(*status)) { | 876 if(status==NULL || U_FAILURE(*status)) { |
| 877 return; | 877 return; |
| 878 } | 878 } |
| 879 if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL ||
length<-1) { | 879 if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL ||
length<-1) { |
| 880 *status=U_ILLEGAL_ARGUMENT_ERROR; | 880 *status=U_ILLEGAL_ARGUMENT_ERROR; |
| 881 return; | 881 return; |
| 882 } | 882 } |
| 883 NumberFormat *nf = reinterpret_cast<NumberFormat *>(fmt); | 883 NumberFormat *nf = reinterpret_cast<NumberFormat *>(fmt); |
| 884 DecimalFormat *dcf = dynamic_cast<DecimalFormat *>(nf); | 884 DecimalFormat *dcf = CR_DYNAMIC_CAST<DecimalFormat *>(nf); |
| 885 if (dcf == NULL) { | 885 if (dcf == NULL) { |
| 886 *status = U_UNSUPPORTED_ERROR; | 886 *status = U_UNSUPPORTED_ERROR; |
| 887 return; | 887 return; |
| 888 } | 888 } |
| 889 | 889 |
| 890 DecimalFormatSymbols symbols(*dcf->getDecimalFormatSymbols()); | 890 DecimalFormatSymbols symbols(*dcf->getDecimalFormatSymbols()); |
| 891 symbols.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol, | 891 symbols.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol, |
| 892 UnicodeString(value, length)); /* UnicodeString can handle the case whe
n length = -1. */ | 892 UnicodeString(value, length)); /* UnicodeString can handle the case whe
n length = -1. */ |
| 893 dcf->setDecimalFormatSymbols(symbols); | 893 dcf->setDecimalFormatSymbols(symbols); |
| 894 } | 894 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 910 | 910 |
| 911 if(status==NULL){ | 911 if(status==NULL){ |
| 912 status = &tStatus; | 912 status = &tStatus; |
| 913 } | 913 } |
| 914 | 914 |
| 915 int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength); | 915 int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength); |
| 916 const UnicodeString pat((UChar*)pattern, len, len); | 916 const UnicodeString pat((UChar*)pattern, len, len); |
| 917 | 917 |
| 918 // Verify if the object passed is a DecimalFormat object | 918 // Verify if the object passed is a DecimalFormat object |
| 919 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); | 919 NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt); |
| 920 DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf); | 920 DecimalFormat* df = CR_DYNAMIC_CAST<DecimalFormat*>(nf); |
| 921 if (df != NULL) { | 921 if (df != NULL) { |
| 922 if(localized) { | 922 if(localized) { |
| 923 df->applyLocalizedPattern(pat,*parseError, *status); | 923 df->applyLocalizedPattern(pat,*parseError, *status); |
| 924 } else { | 924 } else { |
| 925 df->applyPattern(pat,*parseError, *status); | 925 df->applyPattern(pat,*parseError, *status); |
| 926 } | 926 } |
| 927 } else { | 927 } else { |
| 928 *status = U_UNSUPPORTED_ERROR; | 928 *status = U_UNSUPPORTED_ERROR; |
| 929 return; | 929 return; |
| 930 } | 930 } |
| 931 } | 931 } |
| 932 | 932 |
| 933 U_CAPI const char* U_EXPORT2 | 933 U_CAPI const char* U_EXPORT2 |
| 934 unum_getLocaleByType(const UNumberFormat *fmt, | 934 unum_getLocaleByType(const UNumberFormat *fmt, |
| 935 ULocDataLocaleType type, | 935 ULocDataLocaleType type, |
| 936 UErrorCode* status) | 936 UErrorCode* status) |
| 937 { | 937 { |
| 938 if (fmt == NULL) { | 938 if (fmt == NULL) { |
| 939 if (U_SUCCESS(*status)) { | 939 if (U_SUCCESS(*status)) { |
| 940 *status = U_ILLEGAL_ARGUMENT_ERROR; | 940 *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 941 } | 941 } |
| 942 return NULL; | 942 return NULL; |
| 943 } | 943 } |
| 944 return ((const Format*)fmt)->getLocaleID(type, *status); | 944 return ((const Format*)fmt)->getLocaleID(type, *status); |
| 945 } | 945 } |
| 946 | 946 |
| 947 #endif /* #if !UCONFIG_NO_FORMATTING */ | 947 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| OLD | NEW |