2 *******************************************************************************
3 * Copyright (C) 1996-2010, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * Modification History:
8 * Date Name Description
9 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
10 *******************************************************************************
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_FORMATTING
17 #include "unicode/unum.h"
19 #include "unicode/uloc.h"
20 #include "unicode/numfmt.h"
21 #include "unicode/decimfmt.h"
22 #include "unicode/rbnf.h"
23 #include "unicode/ustring.h"
24 #include "unicode/fmtable.h"
25 #include "unicode/dcfmtsym.h"
26 #include "unicode/curramt.h"
35 U_CAPI UNumberFormat
* U_EXPORT2
36 unum_open( UNumberFormatStyle style
,
38 int32_t patternLength
,
40 UParseError
* parseErr
,
44 if(U_FAILURE(*status
))
49 UNumberFormat
*retVal
= 0;
54 retVal
= (UNumberFormat
*)NumberFormat::createInstance(*status
);
56 retVal
= (UNumberFormat
*)NumberFormat::createInstance(Locale(locale
),
62 retVal
= (UNumberFormat
*)NumberFormat::createCurrencyInstance(*status
);
64 retVal
= (UNumberFormat
*)NumberFormat::createCurrencyInstance(Locale(locale
),
70 retVal
= (UNumberFormat
*)NumberFormat::createPercentInstance(*status
);
72 retVal
= (UNumberFormat
*)NumberFormat::createPercentInstance(Locale(locale
),
78 retVal
= (UNumberFormat
*)NumberFormat::createScientificInstance(*status
);
80 retVal
= (UNumberFormat
*)NumberFormat::createScientificInstance(Locale(locale
),
84 case UNUM_PATTERN_DECIMAL
: {
86 /* UnicodeString can handle the case when patternLength = -1. */
87 const UnicodeString
pat(pattern
, patternLength
);
88 DecimalFormatSymbols
*syms
= 0;
95 syms
= new DecimalFormatSymbols(*status
);
97 syms
= new DecimalFormatSymbols(Locale(locale
), *status
);
100 *status
= U_MEMORY_ALLOCATION_ERROR
;
103 if (U_FAILURE(*status
)) {
108 retVal
= (UNumberFormat
*)new DecimalFormat(pat
, syms
, *parseErr
, *status
);
115 case UNUM_PATTERN_RULEBASED
: {
117 /* UnicodeString can handle the case when patternLength = -1. */
118 const UnicodeString
pat(pattern
, patternLength
);
124 retVal
= (UNumberFormat
*)new RuleBasedNumberFormat(pat
, Locale(locale
), *parseErr
, *status
);
128 retVal
= (UNumberFormat
*)new RuleBasedNumberFormat(URBNF_SPELLOUT
, Locale(locale
), *status
);
132 retVal
= (UNumberFormat
*)new RuleBasedNumberFormat(URBNF_ORDINAL
, Locale(locale
), *status
);
136 retVal
= (UNumberFormat
*)new RuleBasedNumberFormat(URBNF_DURATION
, Locale(locale
), *status
);
139 case UNUM_NUMBERING_SYSTEM
:
140 retVal
= (UNumberFormat
*)new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM
, Locale(locale
), *status
);
145 *status
= U_UNSUPPORTED_ERROR
;
149 if(retVal
== 0 && U_SUCCESS(*status
)) {
150 *status
= U_MEMORY_ALLOCATION_ERROR
;
156 U_CAPI
void U_EXPORT2
157 unum_close(UNumberFormat
* fmt
)
159 delete (NumberFormat
*) fmt
;
162 U_CAPI UNumberFormat
* U_EXPORT2
163 unum_clone(const UNumberFormat
*fmt
,
166 if(U_FAILURE(*status
))
170 const NumberFormat
* nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
171 const DecimalFormat
* df
= dynamic_cast<const DecimalFormat
*>(nf
);
175 const RuleBasedNumberFormat
* rbnf
= dynamic_cast<const RuleBasedNumberFormat
*>(nf
);
176 U_ASSERT(rbnf
!= NULL
);
181 *status
= U_MEMORY_ALLOCATION_ERROR
;
185 return (UNumberFormat
*) res
;
188 U_CAPI
int32_t U_EXPORT2
189 unum_format( const UNumberFormat
* fmt
,
192 int32_t resultLength
,
196 return unum_formatInt64(fmt
, number
, result
, resultLength
, pos
, status
);
199 U_CAPI
int32_t U_EXPORT2
200 unum_formatInt64(const UNumberFormat
* fmt
,
203 int32_t resultLength
,
207 if(U_FAILURE(*status
))
211 if(!(result
==NULL
&& resultLength
==0)) {
212 // NULL destination for pure preflighting: empty dummy string
213 // otherwise, alias the destination buffer
214 res
.setTo(result
, 0, resultLength
);
220 fp
.setField(pos
->field
);
222 ((const NumberFormat
*)fmt
)->format(number
, res
, fp
);
225 pos
->beginIndex
= fp
.getBeginIndex();
226 pos
->endIndex
= fp
.getEndIndex();
229 return res
.extract(result
, resultLength
, *status
);
232 U_CAPI
int32_t U_EXPORT2
233 unum_formatDouble( const UNumberFormat
* fmt
,
236 int32_t resultLength
,
237 UFieldPosition
*pos
, /* 0 if ignore */
241 if(U_FAILURE(*status
)) return -1;
244 if(!(result
==NULL
&& resultLength
==0)) {
245 // NULL destination for pure preflighting: empty dummy string
246 // otherwise, alias the destination buffer
247 res
.setTo(result
, 0, resultLength
);
253 fp
.setField(pos
->field
);
255 ((const NumberFormat
*)fmt
)->format(number
, res
, fp
);
258 pos
->beginIndex
= fp
.getBeginIndex();
259 pos
->endIndex
= fp
.getEndIndex();
262 return res
.extract(result
, resultLength
, *status
);
266 U_DRAFT
int32_t U_EXPORT2
267 unum_formatDecimal(const UNumberFormat
* fmt
,
271 int32_t resultLength
,
272 UFieldPosition
*pos
, /* 0 if ignore */
273 UErrorCode
* status
) {
275 if(U_FAILURE(*status
)) {
278 if ((result
== NULL
&& resultLength
!= 0) || resultLength
< 0) {
279 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
285 fp
.setField(pos
->field
);
289 length
= uprv_strlen(number
);
291 StringPiece
numSP(number
, length
);
292 Formattable
numFmtbl(numSP
, *status
);
294 UnicodeString resultStr
;
295 if (resultLength
> 0) {
296 // Alias the destination buffer.
297 resultStr
.setTo(result
, 0, resultLength
);
299 ((const NumberFormat
*)fmt
)->format(numFmtbl
, resultStr
, fp
, *status
);
301 pos
->beginIndex
= fp
.getBeginIndex();
302 pos
->endIndex
= fp
.getEndIndex();
304 return resultStr
.extract(result
, resultLength
, *status
);
310 U_CAPI
int32_t U_EXPORT2
311 unum_formatDoubleCurrency(const UNumberFormat
* fmt
,
315 int32_t resultLength
,
316 UFieldPosition
* pos
, /* ignored if 0 */
317 UErrorCode
* status
) {
318 if (U_FAILURE(*status
)) return -1;
321 if (!(result
==NULL
&& resultLength
==0)) {
322 // NULL destination for pure preflighting: empty dummy string
323 // otherwise, alias the destination buffer
324 res
.setTo(result
, 0, resultLength
);
329 fp
.setField(pos
->field
);
331 CurrencyAmount
*tempCurrAmnt
= new CurrencyAmount(number
, currency
, *status
);
332 // Check for null pointer.
333 if (tempCurrAmnt
== NULL
) {
334 *status
= U_MEMORY_ALLOCATION_ERROR
;
337 Formattable
n(tempCurrAmnt
);
338 ((const NumberFormat
*)fmt
)->format(n
, res
, fp
, *status
);
341 pos
->beginIndex
= fp
.getBeginIndex();
342 pos
->endIndex
= fp
.getEndIndex();
345 return res
.extract(result
, resultLength
, *status
);
349 parseRes(Formattable
& res
,
350 const UNumberFormat
* fmt
,
353 int32_t *parsePos
/* 0 = start */,
357 if(U_FAILURE(*status
))
360 int32_t len
= (textLength
== -1 ? u_strlen(text
) : textLength
);
361 const UnicodeString
src((UChar
*)text
, len
, len
);
365 pp
.setIndex(*parsePos
);
368 ((const NumberFormat
*)fmt
)->parseCurrency(src
, res
, pp
);
370 ((const NumberFormat
*)fmt
)->parse(src
, res
, pp
);
373 if(pp
.getErrorIndex() != -1) {
374 *status
= U_PARSE_ERROR
;
376 *parsePos
= pp
.getErrorIndex();
378 } else if(parsePos
!= 0) {
379 *parsePos
= pp
.getIndex();
383 U_CAPI
int32_t U_EXPORT2
384 unum_parse( const UNumberFormat
* fmt
,
387 int32_t *parsePos
/* 0 = start */,
391 parseRes(res
, fmt
, text
, textLength
, parsePos
, FALSE
, status
);
392 return res
.getLong(*status
);
395 U_CAPI
int64_t U_EXPORT2
396 unum_parseInt64( const UNumberFormat
* fmt
,
399 int32_t *parsePos
/* 0 = start */,
403 parseRes(res
, fmt
, text
, textLength
, parsePos
, FALSE
, status
);
404 return res
.getInt64(*status
);
407 U_CAPI
double U_EXPORT2
408 unum_parseDouble( const UNumberFormat
* fmt
,
411 int32_t *parsePos
/* 0 = start */,
415 parseRes(res
, fmt
, text
, textLength
, parsePos
, FALSE
, status
);
416 return res
.getDouble(*status
);
419 U_CAPI
int32_t U_EXPORT2
420 unum_parseDecimal(const UNumberFormat
* fmt
,
423 int32_t *parsePos
/* 0 = start */,
425 int32_t outBufLength
,
428 if (U_FAILURE(*status
)) {
431 if ((outBuf
== NULL
&& outBufLength
!= 0) || outBufLength
< 0) {
432 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
436 parseRes(res
, fmt
, text
, textLength
, parsePos
, FALSE
, status
);
437 StringPiece sp
= res
.getDecimalNumber(*status
);
438 if (U_FAILURE(*status
)) {
440 } else if (sp
.size() > outBufLength
) {
441 *status
= U_BUFFER_OVERFLOW_ERROR
;
442 } else if (sp
.size() == outBufLength
) {
443 uprv_strncpy(outBuf
, sp
.data(), sp
.size());
444 *status
= U_STRING_NOT_TERMINATED_WARNING
;
446 uprv_strcpy(outBuf
, sp
.data());
451 U_CAPI
double U_EXPORT2
452 unum_parseDoubleCurrency(const UNumberFormat
* fmt
,
455 int32_t* parsePos
, /* 0 = start */
457 UErrorCode
* status
) {
459 parseRes(res
, fmt
, text
, textLength
, parsePos
, TRUE
, status
);
461 const CurrencyAmount
* c
;
462 if (res
.getType() == Formattable::kObject
&&
463 (c
= dynamic_cast<const CurrencyAmount
*>(res
.getObject())) != NULL
) {
464 u_strcpy(currency
, c
->getISOCurrency());
466 return res
.getDouble(*status
);
469 U_CAPI
const char* U_EXPORT2
470 unum_getAvailable(int32_t index
)
472 return uloc_getAvailable(index
);
475 U_CAPI
int32_t U_EXPORT2
476 unum_countAvailable()
478 return uloc_countAvailable();
481 U_CAPI
int32_t U_EXPORT2
482 unum_getAttribute(const UNumberFormat
* fmt
,
483 UNumberFormatAttribute attr
)
485 const NumberFormat
* nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
486 const DecimalFormat
* df
= dynamic_cast<const DecimalFormat
*>(nf
);
489 case UNUM_PARSE_INT_ONLY
:
490 return df
->isParseIntegerOnly();
492 case UNUM_GROUPING_USED
:
493 return df
->isGroupingUsed();
495 case UNUM_DECIMAL_ALWAYS_SHOWN
:
496 return df
->isDecimalSeparatorAlwaysShown();
498 case UNUM_MAX_INTEGER_DIGITS
:
499 return df
->getMaximumIntegerDigits();
501 case UNUM_MIN_INTEGER_DIGITS
:
502 return df
->getMinimumIntegerDigits();
504 case UNUM_INTEGER_DIGITS
:
505 // TBD: what should this return?
506 return df
->getMinimumIntegerDigits();
508 case UNUM_MAX_FRACTION_DIGITS
:
509 return df
->getMaximumFractionDigits();
511 case UNUM_MIN_FRACTION_DIGITS
:
512 return df
->getMinimumFractionDigits();
514 case UNUM_FRACTION_DIGITS
:
515 // TBD: what should this return?
516 return df
->getMinimumFractionDigits();
518 case UNUM_SIGNIFICANT_DIGITS_USED
:
519 return df
->areSignificantDigitsUsed();
521 case UNUM_MAX_SIGNIFICANT_DIGITS
:
522 return df
->getMaximumSignificantDigits();
524 case UNUM_MIN_SIGNIFICANT_DIGITS
:
525 return df
->getMinimumSignificantDigits();
527 case UNUM_MULTIPLIER
:
528 return df
->getMultiplier();
530 case UNUM_GROUPING_SIZE
:
531 return df
->getGroupingSize();
533 case UNUM_ROUNDING_MODE
:
534 return df
->getRoundingMode();
536 case UNUM_FORMAT_WIDTH
:
537 return df
->getFormatWidth();
539 case UNUM_PADDING_POSITION
:
540 return df
->getPadPosition();
542 case UNUM_SECONDARY_GROUPING_SIZE
:
543 return df
->getSecondaryGroupingSize();
545 case UNUM_LENIENT_PARSE
:
546 return ! df
->isParseStrict();
549 /* enums out of sync? unsupported enum? */
553 const RuleBasedNumberFormat
* rbnf
= dynamic_cast<const RuleBasedNumberFormat
*>(nf
);
554 U_ASSERT(rbnf
!= NULL
);
555 if (attr
== UNUM_LENIENT_PARSE
) {
556 #if !UCONFIG_NO_COLLATION
557 return rbnf
->isLenient();
565 U_CAPI
void U_EXPORT2
566 unum_setAttribute( UNumberFormat
* fmt
,
567 UNumberFormatAttribute attr
,
570 NumberFormat
* nf
= reinterpret_cast<NumberFormat
*>(fmt
);
571 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
574 case UNUM_PARSE_INT_ONLY
:
575 df
->setParseIntegerOnly(newValue
!=0);
578 case UNUM_GROUPING_USED
:
579 df
->setGroupingUsed(newValue
!=0);
582 case UNUM_DECIMAL_ALWAYS_SHOWN
:
583 df
->setDecimalSeparatorAlwaysShown(newValue
!=0);
586 case UNUM_MAX_INTEGER_DIGITS
:
587 df
->setMaximumIntegerDigits(newValue
);
590 case UNUM_MIN_INTEGER_DIGITS
:
591 df
->setMinimumIntegerDigits(newValue
);
594 case UNUM_INTEGER_DIGITS
:
595 df
->setMinimumIntegerDigits(newValue
);
596 df
->setMaximumIntegerDigits(newValue
);
599 case UNUM_MAX_FRACTION_DIGITS
:
600 df
->setMaximumFractionDigits(newValue
);
603 case UNUM_MIN_FRACTION_DIGITS
:
604 df
->setMinimumFractionDigits(newValue
);
607 case UNUM_FRACTION_DIGITS
:
608 df
->setMinimumFractionDigits(newValue
);
609 df
->setMaximumFractionDigits(newValue
);
612 case UNUM_SIGNIFICANT_DIGITS_USED
:
613 df
->setSignificantDigitsUsed(newValue
!=0);
616 case UNUM_MAX_SIGNIFICANT_DIGITS
:
617 df
->setMaximumSignificantDigits(newValue
);
620 case UNUM_MIN_SIGNIFICANT_DIGITS
:
621 df
->setMinimumSignificantDigits(newValue
);
624 case UNUM_MULTIPLIER
:
625 df
->setMultiplier(newValue
);
628 case UNUM_GROUPING_SIZE
:
629 df
->setGroupingSize(newValue
);
632 case UNUM_ROUNDING_MODE
:
633 df
->setRoundingMode((DecimalFormat::ERoundingMode
)newValue
);
636 case UNUM_FORMAT_WIDTH
:
637 df
->setFormatWidth(newValue
);
640 case UNUM_PADDING_POSITION
:
641 /** The position at which padding will take place. */
642 df
->setPadPosition((DecimalFormat::EPadPosition
)newValue
);
645 case UNUM_SECONDARY_GROUPING_SIZE
:
646 df
->setSecondaryGroupingSize(newValue
);
649 case UNUM_LENIENT_PARSE
:
650 df
->setParseStrict(newValue
== 0);
654 /* Shouldn't get here anyway */
658 RuleBasedNumberFormat
* rbnf
= dynamic_cast<RuleBasedNumberFormat
*>(nf
);
659 U_ASSERT(rbnf
!= NULL
);
660 if (attr
== UNUM_LENIENT_PARSE
) {
661 #if !UCONFIG_NO_COLLATION
662 rbnf
->setLenient((UBool
)newValue
);
668 U_CAPI
double U_EXPORT2
669 unum_getDoubleAttribute(const UNumberFormat
* fmt
,
670 UNumberFormatAttribute attr
)
672 const NumberFormat
* nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
673 const DecimalFormat
* df
= dynamic_cast<const DecimalFormat
*>(nf
);
674 if (df
!= NULL
&& attr
== UNUM_ROUNDING_INCREMENT
) {
675 return df
->getRoundingIncrement();
681 U_CAPI
void U_EXPORT2
682 unum_setDoubleAttribute( UNumberFormat
* fmt
,
683 UNumberFormatAttribute attr
,
686 NumberFormat
* nf
= reinterpret_cast<NumberFormat
*>(fmt
);
687 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
688 if (df
!= NULL
&& attr
== UNUM_ROUNDING_INCREMENT
) {
689 df
->setRoundingIncrement(newValue
);
693 U_CAPI
int32_t U_EXPORT2
694 unum_getTextAttribute(const UNumberFormat
* fmt
,
695 UNumberFormatTextAttribute tag
,
697 int32_t resultLength
,
700 if(U_FAILURE(*status
))
704 if(!(result
==NULL
&& resultLength
==0)) {
705 // NULL destination for pure preflighting: empty dummy string
706 // otherwise, alias the destination buffer
707 res
.setTo(result
, 0, resultLength
);
710 const NumberFormat
* nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
711 const DecimalFormat
* df
= dynamic_cast<const DecimalFormat
*>(nf
);
714 case UNUM_POSITIVE_PREFIX
:
715 df
->getPositivePrefix(res
);
718 case UNUM_POSITIVE_SUFFIX
:
719 df
->getPositiveSuffix(res
);
722 case UNUM_NEGATIVE_PREFIX
:
723 df
->getNegativePrefix(res
);
726 case UNUM_NEGATIVE_SUFFIX
:
727 df
->getNegativeSuffix(res
);
730 case UNUM_PADDING_CHARACTER
:
731 res
= df
->getPadCharacterString();
734 case UNUM_CURRENCY_CODE
:
735 res
= UnicodeString(df
->getCurrency());
739 *status
= U_UNSUPPORTED_ERROR
;
743 const RuleBasedNumberFormat
* rbnf
= dynamic_cast<const RuleBasedNumberFormat
*>(nf
);
744 U_ASSERT(rbnf
!= NULL
);
745 if (tag
== UNUM_DEFAULT_RULESET
) {
746 res
= rbnf
->getDefaultRuleSetName();
747 } else if (tag
== UNUM_PUBLIC_RULESETS
) {
748 int32_t count
= rbnf
->getNumberOfRuleSetNames();
749 for (int i
= 0; i
< count
; ++i
) {
750 res
+= rbnf
->getRuleSetName(i
);
751 res
+= (UChar
)0x003b; // semicolon
754 *status
= U_UNSUPPORTED_ERROR
;
759 return res
.extract(result
, resultLength
, *status
);
762 U_CAPI
void U_EXPORT2
763 unum_setTextAttribute( UNumberFormat
* fmt
,
764 UNumberFormatTextAttribute tag
,
765 const UChar
* newValue
,
766 int32_t newValueLength
,
769 if(U_FAILURE(*status
))
772 int32_t len
= (newValueLength
== -1 ? u_strlen(newValue
) : newValueLength
);
773 const UnicodeString
val((UChar
*)newValue
, len
, len
);
774 NumberFormat
* nf
= reinterpret_cast<NumberFormat
*>(fmt
);
775 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
778 case UNUM_POSITIVE_PREFIX
:
779 df
->setPositivePrefix(val
);
782 case UNUM_POSITIVE_SUFFIX
:
783 df
->setPositiveSuffix(val
);
786 case UNUM_NEGATIVE_PREFIX
:
787 df
->setNegativePrefix(val
);
790 case UNUM_NEGATIVE_SUFFIX
:
791 df
->setNegativeSuffix(val
);
794 case UNUM_PADDING_CHARACTER
:
795 df
->setPadCharacter(*newValue
);
798 case UNUM_CURRENCY_CODE
:
799 df
->setCurrency(newValue
, *status
);
803 *status
= U_UNSUPPORTED_ERROR
;
807 RuleBasedNumberFormat
* rbnf
= dynamic_cast<RuleBasedNumberFormat
*>(nf
);
808 U_ASSERT(rbnf
!= NULL
);
809 if (tag
== UNUM_DEFAULT_RULESET
) {
810 rbnf
->setDefaultRuleSet(newValue
, *status
);
812 *status
= U_UNSUPPORTED_ERROR
;
817 U_CAPI
int32_t U_EXPORT2
818 unum_toPattern( const UNumberFormat
* fmt
,
819 UBool isPatternLocalized
,
821 int32_t resultLength
,
824 if(U_FAILURE(*status
))
828 if(!(result
==NULL
&& resultLength
==0)) {
829 // NULL destination for pure preflighting: empty dummy string
830 // otherwise, alias the destination buffer
831 pat
.setTo(result
, 0, resultLength
);
834 const NumberFormat
* nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
835 const DecimalFormat
* df
= dynamic_cast<const DecimalFormat
*>(nf
);
837 if(isPatternLocalized
)
838 df
->toLocalizedPattern(pat
);
842 const RuleBasedNumberFormat
* rbnf
= dynamic_cast<const RuleBasedNumberFormat
*>(nf
);
843 U_ASSERT(rbnf
!= NULL
);
844 pat
= rbnf
->getRules();
846 return pat
.extract(result
, resultLength
, *status
);
849 U_CAPI
int32_t U_EXPORT2
850 unum_getSymbol(const UNumberFormat
*fmt
,
851 UNumberFormatSymbol symbol
,
856 if(status
==NULL
|| U_FAILURE(*status
)) {
859 if(fmt
==NULL
|| (uint16_t)symbol
>=UNUM_FORMAT_SYMBOL_COUNT
) {
860 *status
=U_ILLEGAL_ARGUMENT_ERROR
;
863 const NumberFormat
*nf
= reinterpret_cast<const NumberFormat
*>(fmt
);
864 const DecimalFormat
*dcf
= dynamic_cast<const DecimalFormat
*>(nf
);
866 *status
= U_UNSUPPORTED_ERROR
;
871 getDecimalFormatSymbols()->
872 getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol
)symbol
).
873 extract(buffer
, size
, *status
);
876 U_CAPI
void U_EXPORT2
877 unum_setSymbol(UNumberFormat
*fmt
,
878 UNumberFormatSymbol symbol
,
883 if(status
==NULL
|| U_FAILURE(*status
)) {
886 if(fmt
==NULL
|| (uint16_t)symbol
>=UNUM_FORMAT_SYMBOL_COUNT
|| value
==NULL
|| length
<-1) {
887 *status
=U_ILLEGAL_ARGUMENT_ERROR
;
890 NumberFormat
*nf
= reinterpret_cast<NumberFormat
*>(fmt
);
891 DecimalFormat
*dcf
= dynamic_cast<DecimalFormat
*>(nf
);
893 *status
= U_UNSUPPORTED_ERROR
;
897 DecimalFormatSymbols
symbols(*dcf
->getDecimalFormatSymbols());
898 symbols
.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol
)symbol
,
899 UnicodeString(value
, length
)); /* UnicodeString can handle the case when length = -1. */
900 dcf
->setDecimalFormatSymbols(symbols
);
903 U_CAPI
void U_EXPORT2
904 unum_applyPattern( UNumberFormat
*fmt
,
906 const UChar
*pattern
,
907 int32_t patternLength
,
908 UParseError
*parseError
,
911 UErrorCode tStatus
= U_ZERO_ERROR
;
912 UParseError tParseError
;
914 if(parseError
== NULL
){
915 parseError
= &tParseError
;
922 int32_t len
= (patternLength
== -1 ? u_strlen(pattern
) : patternLength
);
923 const UnicodeString
pat((UChar
*)pattern
, len
, len
);
925 // Verify if the object passed is a DecimalFormat object
926 NumberFormat
* nf
= reinterpret_cast<NumberFormat
*>(fmt
);
927 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
930 df
->applyLocalizedPattern(pat
,*parseError
, *status
);
932 df
->applyPattern(pat
,*parseError
, *status
);
935 *status
= U_UNSUPPORTED_ERROR
;
940 U_CAPI
const char* U_EXPORT2
941 unum_getLocaleByType(const UNumberFormat
*fmt
,
942 ULocDataLocaleType type
,
946 if (U_SUCCESS(*status
)) {
947 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
951 return ((const Format
*)fmt
)->getLocaleID(type
, *status
);
954 #endif /* #if !UCONFIG_NO_FORMATTING */