1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2009-01-22 04:46:35 +00:00
|
|
|
* Copyright (C) 1996-2009, 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
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
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"
|
|
|
|
#include "unicode/fmtable.h"
|
|
|
|
#include "unicode/dcfmtsym.h"
|
2004-04-27 21:47:09 +00:00
|
|
|
#include "unicode/curramt.h"
|
2004-03-25 17:42:28 +00:00
|
|
|
#include "uassert.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "cpputils.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-02-10 02:16:19 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
U_NAMESPACE_USE
|
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)
|
|
|
|
{
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
2004-08-09 07:07:33 +00:00
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-12 20:15:13 +00:00
|
|
|
|
|
|
|
UNumberFormat *retVal = 0;
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
switch(style) {
|
|
|
|
case UNUM_DECIMAL:
|
2004-08-09 07:07:33 +00:00
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_CURRENCY:
|
2004-08-09 07:07:33 +00:00
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_PERCENT:
|
2004-08-09 07:07:33 +00:00
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createPercentInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_SCIENTIFIC:
|
2004-08-09 07:07:33 +00:00
|
|
|
if(locale == 0)
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createScientificInstance(*status);
|
|
|
|
else
|
|
|
|
retVal = (UNumberFormat*)NumberFormat::createScientificInstance(Locale(locale),
|
|
|
|
*status);
|
|
|
|
break;
|
2004-03-12 20:15:13 +00:00
|
|
|
|
|
|
|
case UNUM_PATTERN_DECIMAL: {
|
2003-06-23 22:15:00 +00:00
|
|
|
UParseError tErr;
|
2003-08-01 22:28:18 +00:00
|
|
|
/* UnicodeString can handle the case when patternLength = -1. */
|
|
|
|
const UnicodeString pat(pattern, patternLength);
|
2003-06-23 22:15:00 +00:00
|
|
|
DecimalFormatSymbols *syms = 0;
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
if(parseErr==NULL){
|
|
|
|
parseErr = &tErr;
|
|
|
|
}
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
if(locale == 0)
|
|
|
|
syms = new DecimalFormatSymbols(*status);
|
|
|
|
else
|
2004-03-12 20:15:13 +00:00
|
|
|
syms = new DecimalFormatSymbols(Locale(locale), *status);
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
if(syms == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
retVal = (UNumberFormat*)new DecimalFormat(pat, syms, *parseErr, *status);
|
|
|
|
if(retVal == 0) {
|
2003-06-23 22:15:00 +00:00
|
|
|
delete syms;
|
|
|
|
}
|
2004-08-09 07:07:33 +00:00
|
|
|
} break;
|
2004-03-12 20:15:13 +00:00
|
|
|
|
|
|
|
#if U_HAVE_RBNF
|
|
|
|
case UNUM_PATTERN_RULEBASED: {
|
|
|
|
UParseError tErr;
|
|
|
|
/* UnicodeString can handle the case when patternLength = -1. */
|
|
|
|
const UnicodeString pat(pattern, patternLength);
|
2003-06-23 22:15:00 +00:00
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
if(parseErr==NULL){
|
|
|
|
parseErr = &tErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
retVal = (UNumberFormat*)new RuleBasedNumberFormat(pat, Locale(locale), *parseErr, *status);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case UNUM_SPELLOUT:
|
2004-08-09 07:07:33 +00:00
|
|
|
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale(locale), *status);
|
|
|
|
break;
|
2004-03-12 20:15:13 +00:00
|
|
|
|
|
|
|
case UNUM_ORDINAL:
|
2004-08-09 07:07:33 +00:00
|
|
|
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_ORDINAL, Locale(locale), *status);
|
|
|
|
break;
|
2004-03-12 20:15:13 +00:00
|
|
|
|
|
|
|
case UNUM_DURATION:
|
2004-08-09 07:07:33 +00:00
|
|
|
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_DURATION, Locale(locale), *status);
|
|
|
|
break;
|
2009-01-22 04:46:35 +00:00
|
|
|
|
|
|
|
case UNUM_NUMBERING_SYSTEM:
|
|
|
|
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM, Locale(locale), *status);
|
|
|
|
break;
|
2004-03-12 20:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
2004-08-09 07:07:33 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
2003-06-23 22:15:00 +00:00
|
|
|
}
|
2004-08-09 07:07:33 +00:00
|
|
|
|
|
|
|
if(retVal == 0 && U_SUCCESS(*status)) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
2004-08-09 07:07:33 +00:00
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
return retVal;
|
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)
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
delete (NumberFormat*) fmt;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return 0;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
Format *res = 0;
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
|
|
|
res = ((const DecimalFormat*)fmt)->clone();
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-03-25 17:42:28 +00:00
|
|
|
U_ASSERT(((const NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
|
|
|
res = ((const RuleBasedNumberFormat*)fmt)->clone();
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
if(res == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UNumberFormat*) res;
|
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_format( const UNumberFormat* fmt,
|
2003-11-04 23:10:46 +00:00
|
|
|
int32_t number,
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar* result,
|
2003-11-04 23:10:46 +00:00
|
|
|
int32_t resultLength,
|
1999-08-16 21:50:52 +00:00
|
|
|
UFieldPosition *pos,
|
2003-11-04 23:10:46 +00:00
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
return unum_formatInt64(fmt, number, result, resultLength, pos, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
unum_formatInt64(const UNumberFormat* fmt,
|
|
|
|
int64_t number,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition *pos,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(pos != 0)
|
|
|
|
fp.setField(pos->field);
|
|
|
|
|
2004-04-15 18:15:17 +00:00
|
|
|
((const NumberFormat*)fmt)->format(number, res, fp);
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
if(pos != 0) {
|
|
|
|
pos->beginIndex = fp.getBeginIndex();
|
|
|
|
pos->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-11-16 01:14:40 +00:00
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(pos != 0)
|
|
|
|
fp.setField(pos->field);
|
|
|
|
|
2004-04-15 18:15:17 +00:00
|
|
|
((const NumberFormat*)fmt)->format(number, res, fp);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2004-04-15 18:15:17 +00:00
|
|
|
unum_formatDoubleCurrency(const UNumberFormat* fmt,
|
|
|
|
double number,
|
|
|
|
UChar* currency,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition* pos, /* ignored if 0 */
|
|
|
|
UErrorCode* status) {
|
|
|
|
if (U_FAILURE(*status)) return -1;
|
|
|
|
|
|
|
|
UnicodeString res;
|
|
|
|
if (!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldPosition fp;
|
|
|
|
if (pos != 0) {
|
|
|
|
fp.setField(pos->field);
|
|
|
|
}
|
2008-01-16 22:58:59 +00:00
|
|
|
CurrencyAmount *tempCurrAmnt = new CurrencyAmount(number, currency, *status);
|
|
|
|
// Check for null pointer.
|
|
|
|
if (tempCurrAmnt == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return -1;
|
2008-01-16 22:58:59 +00:00
|
|
|
}
|
|
|
|
Formattable n(tempCurrAmnt);
|
2004-04-15 18:15:17 +00:00
|
|
|
((const NumberFormat*)fmt)->format(n, res, fp, *status);
|
|
|
|
|
|
|
|
if (pos != 0) {
|
|
|
|
pos->beginIndex = fp.getBeginIndex();
|
|
|
|
pos->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.extract(result, resultLength, *status);
|
|
|
|
}
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
static void
|
|
|
|
parseRes(Formattable& res,
|
2004-04-15 18:15:17 +00:00
|
|
|
const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UBool parseCurrency,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
2003-11-04 23:10:46 +00:00
|
|
|
return;
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
ParsePosition pp;
|
|
|
|
|
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
2004-04-15 18:15:17 +00:00
|
|
|
if (parseCurrency) {
|
|
|
|
((const NumberFormat*)fmt)->parseCurrency(src, res, pp);
|
|
|
|
} else {
|
|
|
|
((const NumberFormat*)fmt)->parse(src, res, pp);
|
|
|
|
}
|
2003-06-23 22:15:00 +00:00
|
|
|
|
2009-02-19 08:41:08 +00:00
|
|
|
if(pp.getErrorIndex() != -1) {
|
|
|
|
*status = U_PARSE_ERROR;
|
|
|
|
if(parsePos != 0) {
|
2003-06-23 22:15:00 +00:00
|
|
|
*parsePos = pp.getErrorIndex();
|
|
|
|
}
|
2009-02-19 08:41:08 +00:00
|
|
|
} else if(parsePos != 0) {
|
|
|
|
*parsePos = pp.getIndex();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2003-11-04 23:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
unum_parse( const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
Formattable res;
|
2004-04-15 18:15:17 +00:00
|
|
|
parseRes(res, fmt, text, textLength, parsePos, FALSE, status);
|
2004-03-27 04:49:02 +00:00
|
|
|
return res.getLong(*status);
|
2003-11-04 23:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int64_t U_EXPORT2
|
|
|
|
unum_parseInt64( const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
Formattable res;
|
2004-04-15 18:15:17 +00:00
|
|
|
parseRes(res, fmt, text, textLength, parsePos, FALSE, status);
|
2004-03-27 04:49:02 +00:00
|
|
|
return res.getInt64(*status);
|
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_parseDouble( const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos /* 0 = start */,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2003-11-04 23:10:46 +00:00
|
|
|
Formattable res;
|
2004-04-15 18:15:17 +00:00
|
|
|
parseRes(res, fmt, text, textLength, parsePos, FALSE, status);
|
|
|
|
return res.getDouble(*status);
|
|
|
|
}
|
|
|
|
|
2007-08-19 08:59:28 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2004-04-15 18:15:17 +00:00
|
|
|
unum_parseDoubleCurrency(const UNumberFormat* fmt,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t* parsePos, /* 0 = start */
|
|
|
|
UChar* currency,
|
|
|
|
UErrorCode* status) {
|
|
|
|
Formattable res;
|
|
|
|
parseRes(res, fmt, text, textLength, parsePos, TRUE, status);
|
|
|
|
currency[0] = 0;
|
2004-04-27 21:47:09 +00:00
|
|
|
if (res.getType() == Formattable::kObject &&
|
|
|
|
res.getObject()->getDynamicClassID() == CurrencyAmount::getStaticClassID()) {
|
|
|
|
const CurrencyAmount* c = (const CurrencyAmount*) res.getObject();
|
|
|
|
u_strcpy(currency, c->getISOCurrency());
|
2004-04-15 18:15:17 +00:00
|
|
|
}
|
2004-03-27 04:49:02 +00:00
|
|
|
return res.getDouble(*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
return uloc_getAvailable(index);
|
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_countAvailable()
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
return uloc_countAvailable();
|
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_getAttribute(const UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr)
|
|
|
|
{
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
|
|
|
const DecimalFormat* df = (const DecimalFormat*) fmt;
|
2003-06-23 22:15:00 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UNUM_PARSE_INT_ONLY:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->isParseIntegerOnly();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_GROUPING_USED:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->isGroupingUsed();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_DECIMAL_ALWAYS_SHOWN:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->isDecimalSeparatorAlwaysShown();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_MAX_INTEGER_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMaximumIntegerDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_MIN_INTEGER_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMinimumIntegerDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_INTEGER_DIGITS:
|
|
|
|
// TBD: what should this return?
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMinimumIntegerDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_MAX_FRACTION_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMaximumFractionDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_MIN_FRACTION_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMinimumFractionDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_FRACTION_DIGITS:
|
|
|
|
// TBD: what should this return?
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMinimumFractionDigits();
|
|
|
|
|
2004-04-12 23:38:01 +00:00
|
|
|
case UNUM_SIGNIFICANT_DIGITS_USED:
|
|
|
|
return df->areSignificantDigitsUsed();
|
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
case UNUM_MAX_SIGNIFICANT_DIGITS:
|
|
|
|
return df->getMaximumSignificantDigits();
|
|
|
|
|
|
|
|
case UNUM_MIN_SIGNIFICANT_DIGITS:
|
|
|
|
return df->getMinimumSignificantDigits();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_MULTIPLIER:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getMultiplier();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_GROUPING_SIZE:
|
2004-03-25 17:42:28 +00:00
|
|
|
return df->getGroupingSize();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_ROUNDING_MODE:
|
2004-03-31 22:10:06 +00:00
|
|
|
return df->getRoundingMode();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_FORMAT_WIDTH:
|
2004-03-31 22:10:06 +00:00
|
|
|
return df->getFormatWidth();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
|
|
|
case UNUM_PADDING_POSITION:
|
2004-03-31 22:10:06 +00:00
|
|
|
return df->getPadPosition();
|
2003-06-23 22:15:00 +00:00
|
|
|
|
2004-07-18 10:22:23 +00:00
|
|
|
case UNUM_SECONDARY_GROUPING_SIZE:
|
|
|
|
return df->getSecondaryGroupingSize();
|
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
default:
|
2004-07-18 10:22:23 +00:00
|
|
|
/* enums out of sync? unsupported enum? */
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-03-25 17:42:28 +00:00
|
|
|
U_ASSERT(((const NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
2004-03-12 20:15:13 +00:00
|
|
|
if (attr == UNUM_LENIENT_PARSE) {
|
2004-06-10 23:49:07 +00:00
|
|
|
#if !UCONFIG_NO_COLLATION
|
2004-03-25 17:42:28 +00:00
|
|
|
return ((const RuleBasedNumberFormat*)fmt)->isLenient();
|
2004-06-10 23:49:07 +00:00
|
|
|
#endif
|
2004-03-12 20:15:13 +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)
|
|
|
|
{
|
2004-03-12 20:15:13 +00:00
|
|
|
if (((NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
2004-03-25 17:42:28 +00:00
|
|
|
DecimalFormat* df = (DecimalFormat*) fmt;
|
2003-06-23 22:15:00 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UNUM_PARSE_INT_ONLY:
|
2004-04-12 23:38:01 +00:00
|
|
|
df->setParseIntegerOnly(newValue!=0);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_GROUPING_USED:
|
2004-04-12 23:38:01 +00:00
|
|
|
df->setGroupingUsed(newValue!=0);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_DECIMAL_ALWAYS_SHOWN:
|
2004-04-12 23:38:01 +00:00
|
|
|
df->setDecimalSeparatorAlwaysShown(newValue!=0);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MAX_INTEGER_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMaximumIntegerDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MIN_INTEGER_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMinimumIntegerDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_INTEGER_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMinimumIntegerDigits(newValue);
|
|
|
|
df->setMaximumIntegerDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MAX_FRACTION_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMaximumFractionDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MIN_FRACTION_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMinimumFractionDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_FRACTION_DIGITS:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMinimumFractionDigits(newValue);
|
|
|
|
df->setMaximumFractionDigits(newValue);
|
|
|
|
break;
|
|
|
|
|
2004-04-12 23:38:01 +00:00
|
|
|
case UNUM_SIGNIFICANT_DIGITS_USED:
|
|
|
|
df->setSignificantDigitsUsed(newValue!=0);
|
|
|
|
break;
|
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
case UNUM_MAX_SIGNIFICANT_DIGITS:
|
|
|
|
df->setMaximumSignificantDigits(newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MIN_SIGNIFICANT_DIGITS:
|
|
|
|
df->setMinimumSignificantDigits(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_MULTIPLIER:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setMultiplier(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_GROUPING_SIZE:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setGroupingSize(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_ROUNDING_MODE:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setRoundingMode((DecimalFormat::ERoundingMode)newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_FORMAT_WIDTH:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setFormatWidth(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PADDING_POSITION:
|
2004-03-25 17:42:28 +00:00
|
|
|
/** The position at which padding will take place. */
|
|
|
|
df->setPadPosition((DecimalFormat::EPadPosition)newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_SECONDARY_GROUPING_SIZE:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setSecondaryGroupingSize(newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Shouldn't get here anyway */
|
|
|
|
break;
|
|
|
|
}
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-03-25 17:42:28 +00:00
|
|
|
U_ASSERT(((NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
2004-03-12 20:15:13 +00:00
|
|
|
if (attr == UNUM_LENIENT_PARSE) {
|
2004-06-10 23:49:07 +00:00
|
|
|
#if !UCONFIG_NO_COLLATION
|
2004-03-12 20:15:13 +00:00
|
|
|
((RuleBasedNumberFormat*)fmt)->setLenient((UBool)newValue);
|
2004-06-10 23:49:07 +00:00
|
|
|
#endif
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID() &&
|
2004-11-11 23:34:58 +00:00
|
|
|
attr == UNUM_ROUNDING_INCREMENT) {
|
2004-03-31 22:10:06 +00:00
|
|
|
return ((const DecimalFormat*)fmt)->getRoundingIncrement();
|
2003-06-23 22:15:00 +00:00
|
|
|
} else {
|
|
|
|
return -1.0;
|
|
|
|
}
|
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_setDoubleAttribute( UNumberFormat* fmt,
|
|
|
|
UNumberFormatAttribute attr,
|
|
|
|
double newValue)
|
|
|
|
{
|
2004-03-12 20:15:13 +00:00
|
|
|
if (((NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID() &&
|
2004-11-11 23:34:58 +00:00
|
|
|
attr == UNUM_ROUNDING_INCREMENT) {
|
2003-06-23 22:15:00 +00:00
|
|
|
((DecimalFormat*)fmt)->setRoundingIncrement(newValue);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return -1;
|
2004-11-12 07:07:41 +00:00
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
2004-11-12 07:07:41 +00:00
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
2004-11-12 07:07:41 +00:00
|
|
|
const DecimalFormat* df = (const DecimalFormat*) fmt;
|
|
|
|
switch(tag) {
|
|
|
|
case UNUM_POSITIVE_PREFIX:
|
|
|
|
df->getPositivePrefix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_POSITIVE_SUFFIX:
|
|
|
|
df->getPositiveSuffix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_PREFIX:
|
|
|
|
df->getNegativePrefix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_NEGATIVE_SUFFIX:
|
|
|
|
df->getNegativeSuffix(res);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_PADDING_CHARACTER:
|
|
|
|
res = df->getPadCharacterString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNUM_CURRENCY_CODE:
|
|
|
|
res = UnicodeString(df->getCurrency());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-11-12 07:07:41 +00:00
|
|
|
U_ASSERT(((const NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
|
|
|
const RuleBasedNumberFormat* rbnf = (const RuleBasedNumberFormat*)fmt;
|
|
|
|
if (tag == UNUM_DEFAULT_RULESET) {
|
|
|
|
res = rbnf->getDefaultRuleSetName();
|
|
|
|
} else if (tag == UNUM_PUBLIC_RULESETS) {
|
|
|
|
int32_t count = rbnf->getNumberOfRuleSetNames();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
res += rbnf->getRuleSetName(i);
|
|
|
|
res += (UChar)0x003b; // semicolon
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2003-06-23 22:15:00 +00:00
|
|
|
}
|
2004-11-12 07:07:41 +00:00
|
|
|
|
2003-06-23 22:15:00 +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)
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
int32_t len = (newValueLength == -1 ? u_strlen(newValue) : newValueLength);
|
|
|
|
const UnicodeString val((UChar*)newValue, len, len);
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
if (((NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
2004-03-25 17:42:28 +00:00
|
|
|
DecimalFormat* df = (DecimalFormat*) fmt;
|
2004-03-12 20:15:13 +00:00
|
|
|
switch(tag) {
|
|
|
|
case UNUM_POSITIVE_PREFIX:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setPositivePrefix(val);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_POSITIVE_SUFFIX:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setPositiveSuffix(val);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_NEGATIVE_PREFIX:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setNegativePrefix(val);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_NEGATIVE_SUFFIX:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setNegativeSuffix(val);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_PADDING_CHARACTER:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setPadCharacter(*newValue);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
case UNUM_CURRENCY_CODE:
|
2004-03-25 17:42:28 +00:00
|
|
|
df->setCurrency(newValue, *status);
|
2003-06-23 22:15:00 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
default:
|
2003-06-23 22:15:00 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
break;
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-03-25 17:42:28 +00:00
|
|
|
U_ASSERT(((NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
2004-03-12 20:15:13 +00:00
|
|
|
if (tag == UNUM_DEFAULT_RULESET) {
|
2004-11-11 23:34:58 +00:00
|
|
|
((RuleBasedNumberFormat*)fmt)->setDefaultRuleSet(newValue, *status);
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-11-11 23:34:58 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
2003-06-23 22:15:00 +00:00
|
|
|
}
|
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_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)
|
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
UnicodeString pat;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
pat.setTo(result, 0, resultLength);
|
|
|
|
}
|
2004-03-12 20:15:13 +00:00
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
|
|
|
const DecimalFormat* df = (const DecimalFormat*) fmt;
|
2004-03-12 20:15:13 +00:00
|
|
|
if(isPatternLocalized)
|
2004-03-25 17:42:28 +00:00
|
|
|
df->toLocalizedPattern(pat);
|
2004-03-12 20:15:13 +00:00
|
|
|
else
|
2004-03-25 17:42:28 +00:00
|
|
|
df->toPattern(pat);
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2004-03-25 17:42:28 +00:00
|
|
|
U_ASSERT(((const NumberFormat*)fmt)->getDynamicClassID() == RuleBasedNumberFormat::getStaticClassID());
|
|
|
|
pat = ((const RuleBasedNumberFormat*)fmt)->getRules();
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
2003-06-23 22:15:00 +00:00
|
|
|
return pat.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-05-25 01:10:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2004-03-27 07:21:32 +00:00
|
|
|
unum_getSymbol(const UNumberFormat *fmt,
|
2000-05-25 01:10:55 +00:00
|
|
|
UNumberFormatSymbol symbol,
|
|
|
|
UChar *buffer,
|
|
|
|
int32_t size,
|
2003-06-23 22:15:00 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2000-05-25 01:10:55 +00:00
|
|
|
|
2004-03-25 17:42:28 +00:00
|
|
|
if (((const NumberFormat*)fmt)->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
|
2004-03-12 20:15:13 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
return ((const DecimalFormat *)fmt)->
|
2002-10-15 00:36:11 +00:00
|
|
|
getDecimalFormatSymbols()->
|
|
|
|
getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol).
|
|
|
|
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,
|
2003-06-23 22:15:00 +00:00
|
|
|
UErrorCode *status)
|
2001-08-16 00:55:16 +00:00
|
|
|
{
|
2003-06-23 22:15:00 +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;
|
|
|
|
}
|
|
|
|
|
2004-03-12 20:15:13 +00:00
|
|
|
if (((NumberFormat*)fmt)->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-23 22:15:00 +00:00
|
|
|
DecimalFormatSymbols symbols(*((DecimalFormat *)fmt)->getDecimalFormatSymbols());
|
|
|
|
symbols.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol,
|
|
|
|
UnicodeString(value, length)); /* UnicodeString can handle the case when length = -1. */
|
|
|
|
((DecimalFormat *)fmt)->setDecimalFormatSymbols(symbols);
|
2001-08-16 00:55:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2003-06-23 22:15:00 +00:00
|
|
|
UErrorCode tStatus = U_ZERO_ERROR;
|
|
|
|
UParseError tParseError;
|
|
|
|
|
|
|
|
if(parseError == NULL){
|
|
|
|
parseError = &tParseError;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(status==NULL){
|
|
|
|
status = &tStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
|
|
|
|
const UnicodeString pat((UChar*)pattern, len, len);
|
|
|
|
|
|
|
|
// Verify if the object passed is a DecimalFormat object
|
2004-03-12 20:15:13 +00:00
|
|
|
if (((NumberFormat*)format)->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
|
|
|
|
if(localized) {
|
2003-06-23 22:15:00 +00:00
|
|
|
((DecimalFormat*)format)->applyLocalizedPattern(pat,*parseError, *status);
|
2004-03-12 20:15:13 +00:00
|
|
|
} else {
|
2003-06-23 22:15:00 +00:00
|
|
|
((DecimalFormat*)format)->applyPattern(pat,*parseError, *status);
|
2004-03-12 20:15:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-07-20 23:47:59 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 21:58:52 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
unum_getLocaleByType(const UNumberFormat *fmt,
|
|
|
|
ULocDataLocaleType type,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
if (fmt == NULL) {
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-25 17:42:28 +00:00
|
|
|
return ((const Format*)fmt)->getLocaleID(type, *status);
|
2003-11-14 21:58:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|