1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
* Copyright (C) 1996-2001, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unum.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/numfmt.h"
|
|
|
|
#include "unicode/decimfmt.h"
|
2001-11-07 00:01:56 +00:00
|
|
|
#include "unicode/rbnf.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/fmtable.h"
|
|
|
|
#include "unicode/dcfmtsym.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-08-16 00:55:16 +00:00
|
|
|
/*
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UNumberFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_open( UNumberFormatStyle style,
|
|
|
|
const char* locale,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-02-10 02:16:19 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
UNumberFormat *retVal = 0;
|
|
|
|
|
|
|
|
switch(style) {
|
|
|
|
case UNUM_DECIMAL:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(*status);
|
|
|
|
else
|
2000-04-15 21:23:28 +00:00
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(Locale(locale),
|
1999-08-16 21:50:52 +00:00
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_CURRENCY:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(*status);
|
|
|
|
else
|
2000-04-15 21:23:28 +00:00
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(Locale(locale),
|
1999-08-16 21:50:52 +00:00
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PERCENT:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(*status);
|
|
|
|
else
|
2000-04-15 21:23:28 +00:00
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(Locale(locale),
|
1999-08-16 21:50:52 +00:00
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_SPELLOUT:
|
2000-08-30 23:42:28 +00:00
|
|
|
// Todo: TBD: Add spellout support
|
1999-08-16 21:50:52 +00:00
|
|
|
//retVal = (UNumberFormat*)new NumberSpelloutFormat();
|
2000-08-30 23:42:28 +00:00
|
|
|
//break;
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
2001-02-10 02:16:19 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(retVal == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UNumberFormat*
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_openPattern( const UChar* pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
const char* locale,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-08-16 00:55:16 +00:00
|
|
|
UParseError parseError;
|
|
|
|
return unum_openPatternWithError( pattern,patternLength,locale,&parseError,status);
|
|
|
|
}*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UNumberFormat* U_EXPORT2
|
2001-08-16 00:55:16 +00:00
|
|
|
unum_open( UNumberFormatStyle style,
|
|
|
|
const UChar* pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
const char* locale,
|
|
|
|
UParseError* parseErr,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-11-19 16:56:38 +00:00
|
|
|
if(style!=UNUM_IGNORE){
|
2001-08-16 00:55:16 +00:00
|
|
|
UNumberFormat *retVal = 0;
|
|
|
|
|
|
|
|
switch(style) {
|
|
|
|
case UNUM_DECIMAL:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_CURRENCY:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PERCENT:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
2002-02-23 00:34:39 +00:00
|
|
|
case UNUM_SCIENTIFIC:
|
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createScientificInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createScientificInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
case UNUM_SPELLOUT:
|
2002-03-14 00:28:22 +00:00
|
|
|
#if U_HAVE_RBNF
|
2002-02-28 01:42:40 +00:00
|
|
|
return (UNumberFormat*)new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale(locale), *status);
|
2002-03-14 00:28:22 +00:00
|
|
|
#else
|
2002-04-02 02:55:31 +00:00
|
|
|
// fall through
|
2002-03-14 00:28:22 +00:00
|
|
|
#endif
|
2001-08-16 00:55:16 +00:00
|
|
|
default:
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(retVal == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}else{
|
2002-02-28 01:42:40 +00:00
|
|
|
/* we don't support RBNF patterns yet */
|
2001-08-16 00:55:16 +00:00
|
|
|
UParseError tErr;
|
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
const UnicodeString pat((UChar*)pattern, len, len);
|
|
|
|
DecimalFormatSymbols *syms = 0;
|
|
|
|
|
|
|
|
if(parseErr==NULL){
|
|
|
|
parseErr = &tErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(locale == 0)
|
|
|
|
syms = new DecimalFormatSymbols(*status);
|
|
|
|
else
|
|
|
|
syms = new DecimalFormatSymbols(Locale(locale),
|
|
|
|
*status);
|
|
|
|
|
|
|
|
if(syms == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecimalFormat *fmt = 0;
|
|
|
|
fmt = new DecimalFormat(pat, syms, *parseErr, *status);
|
|
|
|
if(fmt == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
delete syms;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UNumberFormat*) fmt;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_close(UNumberFormat* fmt)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
delete (NumberFormat*) fmt;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UNumberFormat* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_clone(const UNumberFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
Format *res = ((DecimalFormat*)fmt)->clone();
|
|
|
|
|
|
|
|
if(res == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UNumberFormat*) res;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_format( const UNumberFormat* fmt,
|
|
|
|
int32_t number,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition *pos,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString res(result, 0, resultLength);
|
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(pos != 0)
|
|
|
|
fp.setField(pos->field);
|
|
|
|
|
|
|
|
((NumberFormat*)fmt)->format(number, res, fp);
|
|
|
|
|
|
|
|
if(pos != 0) {
|
|
|
|
pos->beginIndex = fp.getBeginIndex();
|
|
|
|
pos->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
2001-09-05 23:39:38 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_formatDouble( const UNumberFormat* fmt,
|
|
|
|
double number,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition *pos, /* 0 if ignore */
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString res(result, 0, resultLength);
|
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(pos != 0)
|
|
|
|
fp.setField(pos->field);
|
|
|
|
|
|
|
|
((NumberFormat*)fmt)->format(number, res, fp);
|
|
|
|
|
|
|
|
if(pos != 0) {
|
|
|
|
pos->beginIndex = fp.getBeginIndex();
|
|
|
|
pos->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
2001-09-05 23:39:38 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_parse( const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
ParsePosition pp;
|
|
|
|
Formattable res;
|
|
|
|
|
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
|
|
|
((NumberFormat*)fmt)->parse(src, res, pp);
|
|
|
|
|
|
|
|
if(parsePos != 0) {
|
|
|
|
if(pp.getErrorIndex() == -1)
|
|
|
|
*parsePos = pp.getIndex();
|
|
|
|
else {
|
|
|
|
*parsePos = pp.getErrorIndex();
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_PARSE_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the actual type of the result, cast to a long */
|
|
|
|
return (res.getType() == Formattable::kLong)
|
|
|
|
? res.getLong()
|
|
|
|
: (int32_t) res.getDouble();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_parseDouble( const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-10-24 16:09:39 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-10-24 16:09:39 +00:00
|
|
|
int32_t len = (textLength < 0 ? u_strlen(text) : textLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
ParsePosition pp;
|
|
|
|
Formattable res;
|
|
|
|
|
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
|
|
|
((NumberFormat*)fmt)->parse(src, res, pp);
|
|
|
|
|
|
|
|
if(parsePos != 0) {
|
|
|
|
if(pp.getErrorIndex() == -1)
|
|
|
|
*parsePos = pp.getIndex();
|
|
|
|
else {
|
|
|
|
*parsePos = pp.getErrorIndex();
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_PARSE_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the actual type of the result, cast to a double */
|
|
|
|
return (res.getType() == Formattable::kDouble)
|
|
|
|
? res.getDouble()
|
|
|
|
: (double) res.getLong();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_getAvailable(int32_t index)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_countAvailable()
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_getAttribute(const UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UNUM_PARSE_INT_ONLY:
|
|
|
|
return ((NumberFormat*)fmt)->isParseIntegerOnly();
|
|
|
|
|
|
|
|
case UNUM_GROUPING_USED:
|
|
|
|
return ((NumberFormat*)fmt)->isGroupingUsed();
|
|
|
|
|
|
|
|
case UNUM_DECIMAL_ALWAYS_SHOWN:
|
|
|
|
return ((DecimalFormat*)fmt)->isDecimalSeparatorAlwaysShown();
|
|
|
|
|
|
|
|
case UNUM_MAX_INTEGER_DIGITS:
|
|
|
|
return ((NumberFormat*)fmt)->getMaximumIntegerDigits();
|
|
|
|
|
|
|
|
case UNUM_MIN_INTEGER_DIGITS:
|
|
|
|
return ((NumberFormat*)fmt)->getMinimumIntegerDigits();
|
|
|
|
|
|
|
|
case UNUM_INTEGER_DIGITS:
|
|
|
|
// TBD: what should this return?
|
|
|
|
return ((NumberFormat*)fmt)->getMinimumIntegerDigits();
|
|
|
|
|
|
|
|
case UNUM_MAX_FRACTION_DIGITS:
|
|
|
|
return ((NumberFormat*)fmt)->getMaximumFractionDigits();
|
|
|
|
|
|
|
|
case UNUM_MIN_FRACTION_DIGITS:
|
|
|
|
return ((NumberFormat*)fmt)->getMinimumFractionDigits();
|
|
|
|
|
|
|
|
case UNUM_FRACTION_DIGITS:
|
|
|
|
// TBD: what should this return?
|
|
|
|
return ((NumberFormat*)fmt)->getMinimumFractionDigits();
|
|
|
|
|
|
|
|
case UNUM_MULTIPLIER:
|
|
|
|
return ((DecimalFormat*)fmt)->getMultiplier();
|
|
|
|
|
|
|
|
case UNUM_GROUPING_SIZE:
|
|
|
|
return ((DecimalFormat*)fmt)->getGroupingSize();
|
|
|
|
|
|
|
|
case UNUM_ROUNDING_MODE:
|
|
|
|
return ((DecimalFormat*)fmt)->getRoundingMode();
|
|
|
|
|
|
|
|
case UNUM_FORMAT_WIDTH:
|
|
|
|
return ((DecimalFormat*)fmt)->getFormatWidth();
|
|
|
|
|
|
|
|
/** The position at which padding will take place. */
|
|
|
|
case UNUM_PADDING_POSITION:
|
|
|
|
return ((DecimalFormat*)fmt)->getPadPosition();
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-10-22 00:43:39 +00:00
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_setAttribute( UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr,
|
|
|
|
int32_t newValue)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UNUM_PARSE_INT_ONLY:
|
2000-05-18 22:08:39 +00:00
|
|
|
((NumberFormat*)fmt)->setParseIntegerOnly((UBool)newValue);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_GROUPING_USED:
|
2000-05-18 22:08:39 +00:00
|
|
|
((NumberFormat*)fmt)->setGroupingUsed((UBool)newValue);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_DECIMAL_ALWAYS_SHOWN:
|
2000-05-18 22:08:39 +00:00
|
|
|
((DecimalFormat*)fmt)->setDecimalSeparatorAlwaysShown((UBool)newValue);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_MAX_INTEGER_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMaximumIntegerDigits(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_MIN_INTEGER_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMinimumIntegerDigits(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_INTEGER_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMinimumIntegerDigits(newValue);
|
|
|
|
((NumberFormat*)fmt)->setMaximumIntegerDigits(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_MAX_FRACTION_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMaximumFractionDigits(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_MIN_FRACTION_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMinimumFractionDigits(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_FRACTION_DIGITS:
|
|
|
|
((NumberFormat*)fmt)->setMinimumFractionDigits(newValue);
|
|
|
|
((NumberFormat*)fmt)->setMaximumFractionDigits(newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MULTIPLIER:
|
|
|
|
((DecimalFormat*)fmt)->setMultiplier(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
case UNUM_GROUPING_SIZE:
|
|
|
|
((DecimalFormat*)fmt)->setGroupingSize(newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_ROUNDING_MODE:
|
|
|
|
((DecimalFormat*)fmt)->setRoundingMode((DecimalFormat::ERoundingMode)newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_FORMAT_WIDTH:
|
|
|
|
((DecimalFormat*)fmt)->setFormatWidth(newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/** The position at which padding will take place. */
|
|
|
|
case UNUM_PADDING_POSITION:
|
|
|
|
((DecimalFormat*)fmt)->setPadPosition((DecimalFormat::EPadPosition)newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
2000-07-20 23:47:59 +00:00
|
|
|
case UNUM_SECONDARY_GROUPING_SIZE:
|
|
|
|
((DecimalFormat*)fmt)->setSecondaryGroupingSize(newValue);
|
|
|
|
break;
|
2000-11-28 19:38:56 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Shouldn't get here anyway */
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_getDoubleAttribute(const UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-11-28 19:38:56 +00:00
|
|
|
if (attr == UNUM_ROUNDING_INCREMENT) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return ((DecimalFormat*)fmt)->getRoundingIncrement();
|
1999-10-22 00:43:39 +00:00
|
|
|
} else {
|
1999-08-16 21:50:52 +00:00
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_setDoubleAttribute( UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr,
|
|
|
|
double newValue)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-11-28 19:38:56 +00:00
|
|
|
if (attr == UNUM_ROUNDING_INCREMENT) {
|
1999-08-16 21:50:52 +00:00
|
|
|
((DecimalFormat*)fmt)->setRoundingIncrement(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-03-28 23:23:23 +00:00
|
|
|
unum_getTextAttribute(const UNumberFormat* fmt,
|
1999-08-16 21:50:52 +00:00
|
|
|
UNumberFormatTextAttribute tag,
|
2001-03-28 23:23:23 +00:00
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-11-28 19:38:56 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString res(result, 0, resultLength);
|
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case UNUM_POSITIVE_PREFIX:
|
|
|
|
((DecimalFormat*)fmt)->getPositivePrefix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_POSITIVE_SUFFIX:
|
|
|
|
((DecimalFormat*)fmt)->getPositiveSuffix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_PREFIX:
|
|
|
|
((DecimalFormat*)fmt)->getNegativePrefix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_SUFFIX:
|
|
|
|
((DecimalFormat*)fmt)->getNegativeSuffix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PADDING_CHARACTER:
|
|
|
|
*result = ((DecimalFormat*)fmt)->getPadCharacter();
|
2001-03-17 23:36:26 +00:00
|
|
|
return 1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
default:
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-09-05 23:39:38 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_setTextAttribute( UNumberFormat* fmt,
|
|
|
|
UNumberFormatTextAttribute tag,
|
|
|
|
const UChar* newValue,
|
|
|
|
int32_t newValueLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (newValueLength == -1 ? u_strlen(newValue) : newValueLength);
|
|
|
|
const UnicodeString val((UChar*)newValue, len, len);
|
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case UNUM_POSITIVE_PREFIX:
|
|
|
|
((DecimalFormat*)fmt)->setPositivePrefix(val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_POSITIVE_SUFFIX:
|
|
|
|
((DecimalFormat*)fmt)->setPositiveSuffix(val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_PREFIX:
|
|
|
|
((DecimalFormat*)fmt)->setNegativePrefix(val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_SUFFIX:
|
|
|
|
((DecimalFormat*)fmt)->setNegativeSuffix(val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PADDING_CHARACTER:
|
|
|
|
((DecimalFormat*)fmt)->setPadCharacter(*newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_toPattern( const UNumberFormat* fmt,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isPatternLocalized,
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString pat(result, 0, resultLength);
|
|
|
|
|
|
|
|
if(isPatternLocalized)
|
|
|
|
((DecimalFormat*)fmt)->toLocalizedPattern(pat);
|
|
|
|
else
|
|
|
|
((DecimalFormat*)fmt)->toPattern(pat);
|
|
|
|
|
2001-09-05 23:39:38 +00:00
|
|
|
return pat.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
#ifdef ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_getSymbols(const UNumberFormat* fmt,
|
|
|
|
UNumberFormatSymbols *syms)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString temp;
|
|
|
|
int32_t len;
|
|
|
|
const DecimalFormatSymbols *dfs =
|
|
|
|
((DecimalFormat*)fmt)->getDecimalFormatSymbols();
|
|
|
|
|
|
|
|
syms->decimalSeparator = dfs->getDecimalSeparator();
|
|
|
|
syms->groupingSeparator = dfs->getGroupingSeparator();
|
|
|
|
syms->patternSeparator = dfs->getPatternSeparator();
|
|
|
|
syms->percent = dfs->getPercent();
|
|
|
|
syms->zeroDigit = dfs->getZeroDigit();
|
|
|
|
syms->digit = dfs->getDigit();
|
|
|
|
syms->plusSign = dfs->getPlusSign();
|
|
|
|
syms->minusSign = dfs->getMinusSign();
|
|
|
|
|
|
|
|
dfs->getCurrencySymbol(temp);
|
1999-12-28 23:57:50 +00:00
|
|
|
len = uprv_min(temp.length(), UNFSYMBOLSMAXSIZE);
|
2001-08-17 18:01:56 +00:00
|
|
|
//u_strncpy(syms->currency, temp.getUChars(), len);
|
|
|
|
temp.extract(0,len,syms->currency);
|
2001-03-16 00:05:20 +00:00
|
|
|
syms->currency[len > 0 ? len : 0] = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
dfs->getInternationalCurrencySymbol(temp);
|
1999-12-28 23:57:50 +00:00
|
|
|
len = uprv_min(temp.length(), UNFSYMBOLSMAXSIZE);
|
2001-08-17 18:01:56 +00:00
|
|
|
//u_strncpy(syms->intlCurrency, temp.getUChars(), len);
|
|
|
|
temp.extract(0,len,syms->intlCurrency);
|
2001-03-16 00:05:20 +00:00
|
|
|
syms->intlCurrency[len > 0 ? len : 0] = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
syms->monetarySeparator = dfs->getMonetaryDecimalSeparator();
|
|
|
|
syms->exponential = dfs->getExponentialSymbol();
|
|
|
|
syms->perMill = dfs->getPerMill();
|
|
|
|
syms->padEscape = dfs->getPadEscape();
|
|
|
|
|
|
|
|
dfs->getInfinity(temp);
|
1999-12-28 23:57:50 +00:00
|
|
|
len = uprv_min(temp.length(), UNFSYMBOLSMAXSIZE);
|
2001-08-17 18:01:56 +00:00
|
|
|
//u_strncpy(syms->infinity, temp.getUChars(), len);
|
|
|
|
temp.extract(0,len,syms->infinity);
|
2001-03-16 00:05:20 +00:00
|
|
|
syms->infinity[len > 0 ? len : 0] = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
dfs->getNaN(temp);
|
1999-12-28 23:57:50 +00:00
|
|
|
len = uprv_min(temp.length(), UNFSYMBOLSMAXSIZE);
|
2001-08-17 18:01:56 +00:00
|
|
|
//u_strncpy(syms->naN, temp.getUChars(), len);
|
|
|
|
temp.extract(0,len,syms->naN);
|
2001-03-16 00:05:20 +00:00
|
|
|
syms->naN[len > 0 ? len : 0] = 0x0000;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
unum_setSymbols( UNumberFormat* fmt,
|
|
|
|
const UNumberFormatSymbols* symbolsToSet,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
DecimalFormatSymbols *syms = new DecimalFormatSymbols(*status);
|
|
|
|
if(syms == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
syms->setDecimalSeparator(symbolsToSet->decimalSeparator);
|
|
|
|
syms->setGroupingSeparator(symbolsToSet->groupingSeparator);
|
|
|
|
syms->setPatternSeparator(symbolsToSet->patternSeparator);
|
|
|
|
syms->setPercent(symbolsToSet->percent);
|
|
|
|
syms->setZeroDigit(symbolsToSet->zeroDigit);
|
|
|
|
syms->setDigit(symbolsToSet->digit);
|
|
|
|
syms->setPlusSign(symbolsToSet->plusSign);
|
|
|
|
syms->setMinusSign(symbolsToSet->minusSign);
|
|
|
|
|
|
|
|
syms->setCurrencySymbol(symbolsToSet->currency);
|
|
|
|
syms->setInternationalCurrencySymbol(symbolsToSet->intlCurrency);
|
|
|
|
|
|
|
|
syms->setMonetaryDecimalSeparator(symbolsToSet->monetarySeparator);
|
|
|
|
syms->setExponentialSymbol(symbolsToSet->exponential);
|
|
|
|
syms->setPerMill(symbolsToSet->perMill);
|
|
|
|
syms->setPadEscape(symbolsToSet->padEscape);
|
|
|
|
|
|
|
|
syms->setInfinity(symbolsToSet->infinity);
|
|
|
|
syms->setNaN(symbolsToSet->naN);
|
|
|
|
|
|
|
|
((DecimalFormat*)fmt)->adoptDecimalFormatSymbols(syms);
|
|
|
|
}
|
2000-05-25 01:10:55 +00:00
|
|
|
|
2001-09-17 21:50:19 +00:00
|
|
|
#endif /* ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES */
|
|
|
|
|
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
unum_getSymbol(UNumberFormat *fmt,
|
|
|
|
UNumberFormatSymbol symbol,
|
|
|
|
UChar *buffer,
|
|
|
|
int32_t size,
|
|
|
|
UErrorCode *status) {
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
if(status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT) {
|
|
|
|
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString s=((DecimalFormat *)fmt)->getDecimalFormatSymbols()->getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol);
|
2001-09-18 23:50:55 +00:00
|
|
|
return s.extract(buffer, size, *status);
|
2000-05-25 01:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
unum_setSymbol(UNumberFormat *fmt,
|
|
|
|
UNumberFormatSymbol symbol,
|
|
|
|
const UChar *value,
|
|
|
|
int32_t length,
|
|
|
|
UErrorCode *status) {
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
if(status==NULL || U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fmt==NULL || (uint16_t)symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL || length<-1) {
|
|
|
|
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecimalFormatSymbols symbols(*((DecimalFormat *)fmt)->getDecimalFormatSymbols());
|
|
|
|
symbols.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol,
|
|
|
|
length>=0 ? UnicodeString(value, length) : UnicodeString(value));
|
|
|
|
((DecimalFormat *)fmt)->setDecimalFormatSymbols(symbols);
|
|
|
|
}
|
2000-07-20 23:47:59 +00:00
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
/*
|
2000-07-20 23:47:59 +00:00
|
|
|
U_CAPI void
|
|
|
|
unum_applyPattern( UNumberFormat *format,
|
|
|
|
UBool localized,
|
|
|
|
const UChar *pattern,
|
2001-08-16 00:55:16 +00:00
|
|
|
int32_t patternLength
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UParseError parseError;
|
|
|
|
unum_applyPatternWithError(format,localized,pattern,patternLength,&parseError,&status);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-08-16 00:55:16 +00:00
|
|
|
unum_applyPattern( UNumberFormat *format,
|
|
|
|
UBool localized,
|
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
UParseError *parseError,
|
|
|
|
UErrorCode* status)
|
2000-07-20 23:47:59 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
UErrorCode tStatus = U_ZERO_ERROR;
|
|
|
|
UParseError tParseError;
|
|
|
|
|
|
|
|
if(parseError == NULL){
|
|
|
|
parseError = &tParseError;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(status==NULL){
|
|
|
|
status = &tStatus;
|
|
|
|
}
|
|
|
|
|
2000-07-20 23:47:59 +00:00
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
const UnicodeString pat((UChar*)pattern, len, len);
|
|
|
|
|
2001-08-28 01:13:38 +00:00
|
|
|
// Verify if the object passed is a DecimalFormat object
|
|
|
|
if(((NumberFormat*)format)->getDynamicClassID()!= DecimalFormat::getStaticClassID()){
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-20 23:47:59 +00:00
|
|
|
if(localized)
|
2001-08-16 00:55:16 +00:00
|
|
|
((DecimalFormat*)format)->applyLocalizedPattern(pat,*parseError, *status);
|
2000-07-20 23:47:59 +00:00
|
|
|
else
|
2001-08-16 00:55:16 +00:00
|
|
|
((DecimalFormat*)format)->applyPattern(pat,*parseError, *status);
|
2000-07-20 23:47:59 +00:00
|
|
|
}
|
|
|
|
|