mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 15:42:14 +00:00
ICU-513 Don't use the deprecated API anymore.
X-SVN-Rev: 5756
This commit is contained in:
parent
49ddbebf51
commit
4e351c0c81
13 changed files with 488 additions and 368 deletions
|
@ -1777,6 +1777,7 @@ _uFmtErrorName[U_FMT_PARSE_ERROR_LIMIT - U_FMT_PARSE_ERROR_START] = {
|
|||
"U_MULTIPLE_EXPONENTIAL_SYMBOLS",
|
||||
"U_MALFORMED_EXPONENTIAL_PATTERN",
|
||||
"U_MULTIPLE_PERCENT_SYMBOLS",
|
||||
"U_MULTIPLE_PERMILL_SYMBOLS",
|
||||
"U_MULTIPLE_PAD_SPECIFIERS",
|
||||
"U_PATTERN_SYNTAX_ERROR",
|
||||
"U_ILLEGAL_PAD_POSITION",
|
||||
|
|
|
@ -443,6 +443,7 @@ enum UErrorCode {
|
|||
U_MULTIPLE_EXPONENTIAL_SYMBOLS,
|
||||
U_MALFORMED_EXPONENTIAL_PATTERN,
|
||||
U_MULTIPLE_PERCENT_SYMBOLS,
|
||||
U_MULTIPLE_PERMILL_SYMBOLS,
|
||||
U_MULTIPLE_PAD_SPECIFIERS,
|
||||
U_PATTERN_SYNTAX_ERROR,
|
||||
U_ILLEGAL_PAD_POSITION,
|
||||
|
|
|
@ -170,7 +170,7 @@ DecimalFormatSymbols::initialize(const UnicodeString* numberElements, const Unic
|
|||
fSymbols[kDecimalSeparatorSymbol];
|
||||
|
||||
fSymbols[kExponentialSymbol] = numberElements[7];
|
||||
fSymbols[kPermillSymbol] = numberElements[8];
|
||||
fSymbols[kPerMillSymbol] = numberElements[8];
|
||||
fSymbols[kPadEscapeSymbol] = (UChar)0x002a; // '*' Hard coded for now; get from resource later
|
||||
fSymbols[kInfinitySymbol] = numberElements[9];
|
||||
fSymbols[kNaNSymbol] = numberElements[10];
|
||||
|
@ -196,7 +196,7 @@ DecimalFormatSymbols::initialize() {
|
|||
(fSymbols[kIntlCurrencySymbol] = (UChar)0xa4).append((UChar)0xa4);
|
||||
fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e; // '.' monetary decimal separator
|
||||
fSymbols[kExponentialSymbol] = (UChar)0x45; // 'E' exponential
|
||||
fSymbols[kPermillSymbol] = (UChar)0x2030; // '%o' per mill
|
||||
fSymbols[kPerMillSymbol] = (UChar)0x2030; // '%o' per mill
|
||||
fSymbols[kPadEscapeSymbol] = (UChar)0x2a; // '*' pad escape symbol
|
||||
fSymbols[kInfinitySymbol] = (UChar)0x221e; // 'oo' infinite
|
||||
fSymbols[kNaNSymbol] = (UChar)0xfffd; // SUB NaN
|
||||
|
|
|
@ -44,9 +44,9 @@
|
|||
#include "unicode/unicode.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
// #define DEBUG
|
||||
//#define FMT_DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef FMT_DEBUG
|
||||
#include <stdio.h>
|
||||
static void debugout(UnicodeString s) {
|
||||
char buf[2000];
|
||||
|
@ -64,7 +64,7 @@ static void debugout(UnicodeString s) {
|
|||
// class DecimalFormat
|
||||
// *****************************************************************************
|
||||
|
||||
char DecimalFormat::fgClassID = 0; // Value is irrelevan
|
||||
const char DecimalFormat::fgClassID = 0; // Value is irrelevant
|
||||
UParseError DecimalFormat::fParseError;
|
||||
|
||||
// Constants for characters used in programmatic (unlocalized) patterns.
|
||||
|
@ -339,7 +339,7 @@ DecimalFormat::operator==(const Format& that) const
|
|||
|
||||
const DecimalFormat* other = (DecimalFormat*)&that;
|
||||
|
||||
#if DEBUG
|
||||
#ifdef FMT_DEBUG
|
||||
// This code makes it easy to determine why two format objects that should
|
||||
// be equal aren't.
|
||||
UBool first = TRUE;
|
||||
|
@ -542,8 +542,7 @@ DecimalFormat::format( double number,
|
|||
if (fieldPosition.getField() == NumberFormat::kIntegerField)
|
||||
fieldPosition.setBeginIndex(result.length());
|
||||
|
||||
UnicodeString nan;
|
||||
result += fSymbols->getNaN(nan);
|
||||
result += fSymbols->getSymbol(DecimalFormatSymbols::kNaNSymbol);
|
||||
|
||||
if (fieldPosition.getField() == NumberFormat::kIntegerField)
|
||||
fieldPosition.setEndIndex(result.length());
|
||||
|
@ -589,8 +588,7 @@ DecimalFormat::format( double number,
|
|||
if (fieldPosition.getField() == NumberFormat::kIntegerField)
|
||||
fieldPosition.setBeginIndex(result.length());
|
||||
|
||||
UnicodeString inf;
|
||||
result += fSymbols->getInfinity(inf);
|
||||
result += fSymbols->getSymbol(DecimalFormatSymbols::kInfinitySymbol);
|
||||
|
||||
if (fieldPosition.getField() == NumberFormat::kIntegerField)
|
||||
fieldPosition.setEndIndex(result.length());
|
||||
|
@ -691,12 +689,12 @@ DecimalFormat::subformat(UnicodeString& result,
|
|||
UBool isInteger) const
|
||||
{
|
||||
// Gets the localized zero Unicode character.
|
||||
UChar zero = fSymbols->getZeroDigit();
|
||||
UChar32 zero = fSymbols->getSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
|
||||
int32_t zeroDelta = zero - '0'; // '0' is the DigitList representation of zero
|
||||
UChar grouping = fSymbols->getGroupingSeparator();
|
||||
UChar decimal = fIsCurrencyFormat ?
|
||||
fSymbols->getMonetaryDecimalSeparator() :
|
||||
fSymbols->getDecimalSeparator();
|
||||
UnicodeString grouping(fSymbols->getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol));
|
||||
UnicodeString decimal(fIsCurrencyFormat ?
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol) :
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol));
|
||||
int32_t maxIntDig = getMaximumIntegerDigits();
|
||||
int32_t minIntDig = getMinimumIntegerDigits();
|
||||
|
||||
|
@ -783,8 +781,8 @@ DecimalFormat::subformat(UnicodeString& result,
|
|||
fieldPosition.setBeginIndex(result.length());
|
||||
}
|
||||
// Restores the digit character or pads the buffer with zeros.
|
||||
UChar c = ((i < digits.fCount) ?
|
||||
(UChar)(digits.fDigits[i] + zeroDelta) :
|
||||
UChar c = (UChar)((i < digits.fCount) ?
|
||||
(digits.fDigits[i] + zeroDelta) :
|
||||
zero);
|
||||
result += c;
|
||||
}
|
||||
|
@ -806,7 +804,7 @@ DecimalFormat::subformat(UnicodeString& result,
|
|||
// exponent digits. There is no maximum limit to the exponent
|
||||
// digits, since truncating the exponent would result in an
|
||||
// unacceptable inaccuracy.
|
||||
result += fSymbols->getExponentialSymbol();
|
||||
result += fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol);
|
||||
|
||||
// For zero values, we force the exponent to zero. We
|
||||
// must do this here, and not earlier, because the value
|
||||
|
@ -815,9 +813,9 @@ DecimalFormat::subformat(UnicodeString& result,
|
|||
exponent = 0;
|
||||
|
||||
if (exponent < 0) {
|
||||
result += fSymbols->getMinusSign();
|
||||
result += fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol);
|
||||
} else if (fExponentSignAlwaysShown) {
|
||||
result += fSymbols->getPlusSign();
|
||||
result += fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol);
|
||||
}
|
||||
|
||||
DigitList expDigits;
|
||||
|
@ -826,8 +824,8 @@ DecimalFormat::subformat(UnicodeString& result,
|
|||
result += (zero);
|
||||
for (i=0; i<expDigits.fDecimalAt; ++i)
|
||||
{
|
||||
UChar c = ((i < expDigits.fCount) ?
|
||||
(UChar)(expDigits.fDigits[i] + zeroDelta) : zero);
|
||||
UChar c = (UChar)((i < expDigits.fCount) ?
|
||||
(expDigits.fDigits[i] + zeroDelta) : zero);
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
|
@ -965,34 +963,33 @@ void DecimalFormat::addPadding(UnicodeString& result,
|
|||
if (fFormatWidth > 0) {
|
||||
int32_t len = fFormatWidth - result.length();
|
||||
if (len > 0) {
|
||||
UChar* padding = new UChar[sizeof(UChar) * len];
|
||||
UnicodeString padding;
|
||||
for (int32_t i=0; i<len; ++i) {
|
||||
padding[i] = fPad;
|
||||
padding += fPad;
|
||||
}
|
||||
switch (fPadPosition) {
|
||||
case kPadAfterPrefix:
|
||||
if (hasAffixes) {
|
||||
result.insert(isNegative ? fNegativePrefix.length()
|
||||
: fPositivePrefix.length(),
|
||||
padding, len);
|
||||
padding);
|
||||
break;
|
||||
} // else fall through to next case
|
||||
case kPadBeforePrefix:
|
||||
result.insert(0, padding, len);
|
||||
result.insert(0, padding);
|
||||
break;
|
||||
case kPadBeforeSuffix:
|
||||
if (hasAffixes) {
|
||||
result.insert(result.length() -
|
||||
(isNegative ? fNegativeSuffix.length()
|
||||
: fPositiveSuffix.length()),
|
||||
padding, len);
|
||||
padding);
|
||||
break;
|
||||
} // else fall through to next case
|
||||
case kPadAfterSuffix:
|
||||
result += padding;
|
||||
break;
|
||||
}
|
||||
delete []padding;
|
||||
fieldPosition.setBeginIndex(len + fieldPosition.getBeginIndex());
|
||||
fieldPosition.setEndIndex(len + fieldPosition.getEndIndex());
|
||||
}
|
||||
|
@ -1016,20 +1013,22 @@ DecimalFormat::parse(const UnicodeString& text,
|
|||
{
|
||||
int32_t backup = parsePosition.getIndex();
|
||||
int32_t i;
|
||||
int32_t padLen = fPad.length();
|
||||
|
||||
// Skip padding characters, if any
|
||||
if (fFormatWidth > 0) {
|
||||
i = parsePosition.getIndex();
|
||||
// Todo: Is this even tested?
|
||||
while (i < text.length() && text[(UTextOffset) i] == fPad) {
|
||||
++i;
|
||||
while (i < text.length() && !text.compare(i, padLen, fPad, 0, padLen)) {
|
||||
i += padLen;
|
||||
}
|
||||
parsePosition.setIndex(i);
|
||||
}
|
||||
|
||||
// special case NaN
|
||||
// If the text is composed of the representation of NaN, returns NaN.length
|
||||
int32_t nanLen = fSymbols->compareNaN(text, parsePosition.getIndex());
|
||||
UnicodeString nan(fSymbols->getSymbol(DecimalFormatSymbols::kNaNSymbol));
|
||||
int32_t nanLen = (text.compare(parsePosition.getIndex(), nan.length(), nan)
|
||||
? 0 : nan.length());
|
||||
if (nanLen) {
|
||||
parsePosition.setIndex(parsePosition.getIndex() + nanLen);
|
||||
result.setDouble(uprv_getNaN());
|
||||
|
@ -1046,8 +1045,8 @@ DecimalFormat::parse(const UnicodeString& text,
|
|||
}
|
||||
if (fFormatWidth < 0) {
|
||||
i = parsePosition.getIndex();
|
||||
while (i < text.length() && text[(UTextOffset) i] == fPad) {
|
||||
++i;
|
||||
while (i < text.length() && !text.compare(i, padLen, fPad, 0, padLen)) {
|
||||
i += padLen;
|
||||
}
|
||||
parsePosition.setIndex(i);
|
||||
}
|
||||
|
@ -1114,8 +1113,8 @@ is here if we change our minds.
|
|||
UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePosition,
|
||||
DigitList& digits, UBool* status) const
|
||||
{
|
||||
int32_t position = parsePosition.getIndex();
|
||||
int32_t oldStart = position;
|
||||
UTextOffset position = parsePosition.getIndex();
|
||||
UTextOffset oldStart = position;
|
||||
|
||||
// check for positivePrefix; take longest
|
||||
UBool gotPositive = text.compare(position,fPositivePrefix.length(),fPositivePrefix,0,
|
||||
|
@ -1141,7 +1140,9 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
|
|||
}
|
||||
|
||||
// process digits or Inf, find decimal position
|
||||
int32_t infLen = fSymbols->compareInfinity(text, position);
|
||||
UnicodeString inf(fSymbols->getSymbol(DecimalFormatSymbols::kInfinitySymbol));
|
||||
int32_t infLen = (text.compare(position, inf.length(), inf)
|
||||
? 0 : inf.length());
|
||||
position += infLen; // infLen is non-zero when it does equal to infinity
|
||||
status[fgStatusInfinite] = (UBool)infLen;
|
||||
if (!infLen)
|
||||
|
@ -1154,25 +1155,28 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
|
|||
// exponent as needed.
|
||||
|
||||
digits.fDecimalAt = digits.fCount = 0;
|
||||
UChar zero = fSymbols->getZeroDigit();
|
||||
UChar decimal = fIsCurrencyFormat ?
|
||||
fSymbols->getMonetaryDecimalSeparator() : fSymbols->getDecimalSeparator();
|
||||
UChar grouping = fSymbols->getGroupingSeparator();
|
||||
UChar exponentChar = fSymbols->getExponentialSymbol();
|
||||
UChar32 zero = fSymbols->getSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
|
||||
UnicodeString decimal(fIsCurrencyFormat
|
||||
? fSymbols->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol)
|
||||
: fSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol));
|
||||
UnicodeString grouping(fSymbols->getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol));
|
||||
UnicodeString exponentChar(fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol));
|
||||
UBool sawDecimal = FALSE;
|
||||
UBool sawDigit = FALSE;
|
||||
int32_t backup = -1;
|
||||
UChar ch;
|
||||
UChar32 ch;
|
||||
int32_t digit;
|
||||
int32_t textLength = text.length(); // One less pointer to follow
|
||||
int32_t groupingLen = grouping.length();
|
||||
int32_t decimalLen = decimal.length();
|
||||
|
||||
// We have to track digitCount ourselves, because digits.fCount will
|
||||
// pin when the maximum allowable digits is reached.
|
||||
int32_t digitCount = 0;
|
||||
|
||||
for (; position < textLength; ++position)
|
||||
for (; position < textLength; position += 1 + UTF_NEED_MULTIPLE_UCHAR(ch))
|
||||
{
|
||||
ch = text[(UTextOffset)position];
|
||||
ch = text.char32At(position);
|
||||
|
||||
/* We recognize all digit ranges, not only the Latin digit range
|
||||
* '0'..'9'. We do so by using the Character.digit() method,
|
||||
|
@ -1223,14 +1227,14 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
|
|||
}
|
||||
// else ignore leading zeros in integer part of number.
|
||||
}
|
||||
else if (ch == grouping && isGroupingUsed())
|
||||
else if (!text.compare(position, groupingLen, grouping) && isGroupingUsed())
|
||||
{
|
||||
// Ignore grouping characters, if we are using them, but require
|
||||
// that they be followed by a digit. Otherwise we backup and
|
||||
// reprocess them.
|
||||
backup = position;
|
||||
}
|
||||
else if (ch == decimal && !isParseIntegerOnly() && !sawDecimal)
|
||||
else if (!text.compare(position, decimalLen, decimal) && !isParseIntegerOnly() && !sawDecimal)
|
||||
{
|
||||
// If we're only parsing integers, or if we ALREADY saw the
|
||||
// decimal, then don't parse this one.
|
||||
|
@ -1238,7 +1242,9 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
|
|||
digits.fDecimalAt = digitCount; // Not digits.fCount!
|
||||
sawDecimal = TRUE;
|
||||
}
|
||||
else if (ch == exponentChar) // error code is set below if !sawDigit
|
||||
else if (!text.compare(position,
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol).length(),
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol))) // error code is set below if !sawDigit
|
||||
{
|
||||
// Parse sign, if present
|
||||
int32_t pos = position + 1; // position + exponentSep.length();
|
||||
|
@ -1246,12 +1252,15 @@ UBool DecimalFormat::subparse(const UnicodeString& text, ParsePosition& parsePos
|
|||
|
||||
if (pos < textLength)
|
||||
{
|
||||
ch = text[(UTextOffset) pos];
|
||||
if (ch == fSymbols->getPlusSign())
|
||||
if (!text.compare(pos,
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol).length(),
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol)))
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
else if (ch == fSymbols->getMinusSign())
|
||||
else if (!text.compare(pos,
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol).length(),
|
||||
fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol)))
|
||||
{
|
||||
++pos;
|
||||
exponentDigits.fIsPositive = FALSE;
|
||||
|
@ -1604,7 +1613,12 @@ UnicodeString DecimalFormat::getPadCharacterString() {
|
|||
* @see #setPadPosition
|
||||
*/
|
||||
void DecimalFormat::setPadCharacter(UnicodeString padChar) {
|
||||
fPad = padChar.length() > 0 ? padChar.charAt(0) : kPatternPadEscape;
|
||||
if (padChar.length() > 0) {
|
||||
fPad = padChar;
|
||||
}
|
||||
else {
|
||||
fPad = kPatternPadEscape;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1831,7 +1845,7 @@ void DecimalFormat::expandAffixes(void) {
|
|||
if (fNegSuffixPattern != 0) {
|
||||
expandAffix(*fNegSuffixPattern, fNegativeSuffix);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
#ifdef FMT_DEBUG
|
||||
UnicodeString s;
|
||||
s.append("[")
|
||||
.append(*fPosPrefixPattern).append("|").append(*fPosSuffixPattern)
|
||||
|
@ -1867,31 +1881,35 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
|
|||
switch (c) {
|
||||
case kCurrencySign:
|
||||
{
|
||||
UnicodeString s;
|
||||
if (i<pattern.length() &&
|
||||
pattern.charAt(i) == kCurrencySign) {
|
||||
++i;
|
||||
affix += fSymbols->getInternationalCurrencySymbol(s);
|
||||
affix += fSymbols->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);
|
||||
} else {
|
||||
affix += fSymbols->getCurrencySymbol(s);
|
||||
affix += fSymbols->getSymbol(DecimalFormatSymbols::kCurrencySymbol);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case kPatternPercent:
|
||||
c = fSymbols->getPercent();
|
||||
affix.append(fSymbols->getSymbol(DecimalFormatSymbols::kPercentSymbol));
|
||||
break;
|
||||
case kPatternPerMill:
|
||||
c = fSymbols->getPerMill();
|
||||
affix.append(fSymbols->getSymbol(DecimalFormatSymbols::kPerMillSymbol));
|
||||
break;
|
||||
case kPatternPlus:
|
||||
c = fSymbols->getPlusSign();
|
||||
affix.append(fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol));
|
||||
break;
|
||||
case kPatternMinus:
|
||||
c = fSymbols->getMinusSign();
|
||||
affix.append(fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol));
|
||||
break;
|
||||
default:
|
||||
affix.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
affix.append(c);
|
||||
else {
|
||||
affix.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1931,34 +1949,36 @@ void DecimalFormat::appendAffix(UnicodeString& buffer,
|
|||
affixPattern->extractBetween(pos, i, s);
|
||||
appendAffix(buffer, s, localized);
|
||||
}
|
||||
UChar c = affixPattern->charAt(++i);
|
||||
UChar32 c = affixPattern->char32At(++i);
|
||||
++i;
|
||||
if (c == kQuote) {
|
||||
buffer.append(c);
|
||||
buffer.append(c).append(c);
|
||||
// Fall through and append another kQuote below
|
||||
} else if (c == kCurrencySign &&
|
||||
i<affixPattern->length() &&
|
||||
affixPattern->charAt(i) == kCurrencySign) {
|
||||
affixPattern->char32At(i) == kCurrencySign) {
|
||||
++i;
|
||||
buffer.append(c);
|
||||
// Fall through and append another kCurrencySign below
|
||||
buffer.append(c).append(c);
|
||||
} else if (localized) {
|
||||
switch (c) {
|
||||
case kPatternPercent:
|
||||
c = fSymbols->getPercent();
|
||||
buffer.append(fSymbols->getSymbol(DecimalFormatSymbols::kPercentSymbol));
|
||||
break;
|
||||
case kPatternPerMill:
|
||||
c = fSymbols->getPerMill();
|
||||
buffer.append(fSymbols->getSymbol(DecimalFormatSymbols::kPerMillSymbol));
|
||||
break;
|
||||
case kPatternPlus:
|
||||
c = fSymbols->getPlusSign();
|
||||
buffer.append(fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol));
|
||||
break;
|
||||
case kPatternMinus:
|
||||
c = fSymbols->getMinusSign();
|
||||
buffer.append(fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol));
|
||||
break;
|
||||
default:
|
||||
buffer.append(c);
|
||||
}
|
||||
} else {
|
||||
buffer.append(c);
|
||||
}
|
||||
buffer.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1974,15 +1994,15 @@ DecimalFormat::appendAffix( UnicodeString& buffer,
|
|||
UBool localized) const {
|
||||
UBool needQuote;
|
||||
if(localized) {
|
||||
needQuote = affix.indexOf(fSymbols->getZeroDigit()) >= 0
|
||||
|| affix.indexOf(fSymbols->getGroupingSeparator()) >= 0
|
||||
|| affix.indexOf(fSymbols->getDecimalSeparator()) >= 0
|
||||
|| affix.indexOf(fSymbols->getPercent()) >= 0
|
||||
|| affix.indexOf(fSymbols->getPerMill()) >= 0
|
||||
|| affix.indexOf(fSymbols->getDigit()) >= 0
|
||||
|| affix.indexOf(fSymbols->getPatternSeparator()) >= 0
|
||||
|| affix.indexOf(fSymbols->getPlusSign()) >= 0
|
||||
|| affix.indexOf(fSymbols->getMinusSign()) >= 0
|
||||
needQuote = affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kZeroDigitSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kPercentSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kPerMillSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kDigitSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol)) >= 0
|
||||
|| affix.indexOf(fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol)) >= 0
|
||||
|| affix.indexOf(kCurrencySign) >= 0;
|
||||
}
|
||||
else {
|
||||
|
@ -2027,24 +2047,39 @@ UnicodeString&
|
|||
DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
|
||||
{
|
||||
result.remove();
|
||||
UChar zero = localized ? fSymbols->getZeroDigit() : kPatternZeroDigit;
|
||||
UChar digit = localized ? fSymbols->getDigit() : kPatternDigit;
|
||||
UChar group = localized ? fSymbols->getGroupingSeparator()
|
||||
: kPatternGroupingSeparator;
|
||||
UChar32 zero;
|
||||
UnicodeString digit;
|
||||
UnicodeString group;
|
||||
int32_t i;
|
||||
int32_t roundingDecimalPos = 0; // Pos of decimal in roundingDigits
|
||||
UnicodeString roundingDigits;
|
||||
int32_t padPos = (fFormatWidth > 0) ? fPadPosition : -1;
|
||||
UnicodeString padSpec;
|
||||
|
||||
if (localized) {
|
||||
digit = fSymbols->getSymbol(DecimalFormatSymbols::kDigitSymbol);
|
||||
group = fSymbols->getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
|
||||
zero = fSymbols->getSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
|
||||
}
|
||||
else {
|
||||
digit.append((UChar)kPatternDigit);
|
||||
group.append((UChar)kPatternGroupingSeparator);
|
||||
zero = (UChar32)kPatternZeroDigit;
|
||||
}
|
||||
if (fFormatWidth > 0) {
|
||||
padSpec.append((UChar)(localized ? fSymbols->getPadEscape() : kPatternPadEscape)).
|
||||
append(fPad);
|
||||
if (localized) {
|
||||
padSpec.append(fSymbols->getSymbol(DecimalFormatSymbols::kPadEscapeSymbol));
|
||||
}
|
||||
else {
|
||||
padSpec.append((UChar)kPatternPadEscape);
|
||||
}
|
||||
padSpec.append(fPad);
|
||||
}
|
||||
if (fRoundingIncrement != NULL) {
|
||||
for(i=0; i<fRoundingIncrement->fCount; ++i) {
|
||||
roundingDigits.append((UChar)fRoundingIncrement->fDigits[i]);
|
||||
}
|
||||
roundingDecimalPos = fRoundingIncrement->fDecimalAt;
|
||||
for(i=0; i<fRoundingIncrement->fCount; ++i) {
|
||||
roundingDigits.append((UChar)fRoundingIncrement->fDigits[i]);
|
||||
}
|
||||
roundingDecimalPos = fRoundingIncrement->fDecimalAt;
|
||||
}
|
||||
for (int32_t part=0; part<2; ++part) {
|
||||
if (padPos == kPadBeforePrefix) {
|
||||
|
@ -2077,11 +2112,15 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
|
|||
continue;
|
||||
}
|
||||
}
|
||||
result.append((UChar)(i<=getMinimumIntegerDigits() ? zero : digit));
|
||||
result.append((i<=getMinimumIntegerDigits() ? zero : digit));
|
||||
}
|
||||
if (getMaximumFractionDigits() > 0 || fDecimalSeparatorAlwaysShown) {
|
||||
result.append((UChar)(localized ? fSymbols->getDecimalSeparator() :
|
||||
kPatternDecimalSeparator));
|
||||
if (localized) {
|
||||
result.append(fSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol));
|
||||
}
|
||||
else {
|
||||
result.append((UChar)kPatternDecimalSeparator);
|
||||
}
|
||||
}
|
||||
int32_t pos = roundingDecimalPos;
|
||||
for (i = 0; i < getMaximumFractionDigits(); ++i) {
|
||||
|
@ -2091,14 +2130,22 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
|
|||
++pos;
|
||||
continue;
|
||||
}
|
||||
result.append((UChar)(i<getMinimumFractionDigits() ? zero : digit));
|
||||
result.append((i<getMinimumFractionDigits() ? zero : digit));
|
||||
}
|
||||
if (fUseExponentialNotation) {
|
||||
result.append((UChar)(localized ? fSymbols->getExponentialSymbol() :
|
||||
kPatternExponent));
|
||||
if (localized) {
|
||||
result.append(fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol));
|
||||
}
|
||||
else {
|
||||
result.append((UChar)kPatternExponent);
|
||||
}
|
||||
if (fExponentSignAlwaysShown) {
|
||||
result.append((UChar)(localized ? fSymbols->getPlusSign() :
|
||||
kPatternPlus));
|
||||
if (localized) {
|
||||
result.append(fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol));
|
||||
}
|
||||
else {
|
||||
result.append((UChar)kPatternPlus);
|
||||
}
|
||||
}
|
||||
for (i=0; i<fMinExponentDigits; ++i) {
|
||||
result.append(zero);
|
||||
|
@ -2134,8 +2181,10 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
|
|||
if ((fNegSuffixPattern == fPosSuffixPattern && // both null
|
||||
fNegativeSuffix == fPositiveSuffix)
|
||||
|| (fNegSuffixPattern != 0 && fPosSuffixPattern != 0 &&
|
||||
*fNegSuffixPattern == *fPosSuffixPattern)) {
|
||||
if (fNegPrefixPattern != NULL && fPosPrefixPattern != NULL) {
|
||||
*fNegSuffixPattern == *fPosSuffixPattern))
|
||||
{
|
||||
if (fNegPrefixPattern != NULL && fPosPrefixPattern != NULL)
|
||||
{
|
||||
int32_t length = fPosPrefixPattern->length();
|
||||
isDefault = fNegPrefixPattern->length() == (length+2) &&
|
||||
(*fNegPrefixPattern)[(UTextOffset)0] == kQuote &&
|
||||
|
@ -2143,18 +2192,23 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
|
|||
fNegPrefixPattern->compare(2, length, *fPosPrefixPattern, 0, length) == 0;
|
||||
}
|
||||
if (!isDefault &&
|
||||
fNegPrefixPattern == NULL && fPosPrefixPattern == NULL) {
|
||||
fNegPrefixPattern == NULL && fPosPrefixPattern == NULL)
|
||||
{
|
||||
int32_t length = fPositivePrefix.length();
|
||||
isDefault = fNegativePrefix.length() == (length+1) &&
|
||||
fNegativePrefix[(UTextOffset)0] == fSymbols->getMinusSign() &&
|
||||
fNegativePrefix.compare(fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol)) == 0 &&
|
||||
fNegativePrefix.compare(1, length, fPositivePrefix, 0, length) == 0;
|
||||
}
|
||||
}
|
||||
if (isDefault) {
|
||||
break; // Don't output default negative subpattern
|
||||
} else {
|
||||
result.append((UChar)(localized ? fSymbols->getPatternSeparator() :
|
||||
kPatternSeparator));
|
||||
if (localized) {
|
||||
result.append(fSymbols->getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol));
|
||||
}
|
||||
else {
|
||||
result.append((UChar)kPatternSeparator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
appendAffix(result, fNegSuffixPattern, fNegativeSuffix, localized);
|
||||
|
@ -2221,37 +2275,41 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
parseError.preContext[0] = parseError.postContext[0] = (UChar)0;
|
||||
|
||||
// Set the significant pattern symbols
|
||||
UChar zeroDigit = kPatternZeroDigit;
|
||||
UChar groupingSeparator = kPatternGroupingSeparator;
|
||||
UChar decimalSeparator = kPatternDecimalSeparator;
|
||||
UChar percent = kPatternPercent;
|
||||
UChar perMill = kPatternPerMill;
|
||||
UChar digit = kPatternDigit;
|
||||
UChar separator = kPatternSeparator;
|
||||
UChar exponent = kPatternExponent;
|
||||
UChar plus = kPatternPlus;
|
||||
UChar minus = kPatternMinus;
|
||||
UChar padEscape = kPatternPadEscape;
|
||||
UChar32 zeroDigit = kPatternZeroDigit;
|
||||
UnicodeString groupingSeparator ((UChar)kPatternGroupingSeparator);
|
||||
UnicodeString decimalSeparator ((UChar)kPatternDecimalSeparator);
|
||||
UnicodeString percent ((UChar)kPatternPercent);
|
||||
UnicodeString perMill ((UChar)kPatternPerMill);
|
||||
UnicodeString digit ((UChar)kPatternDigit);
|
||||
UnicodeString separator ((UChar)kPatternSeparator);
|
||||
UnicodeString exponent ((UChar)kPatternExponent);
|
||||
UnicodeString plus ((UChar)kPatternPlus);
|
||||
UnicodeString minus ((UChar)kPatternMinus);
|
||||
UnicodeString padEscape ((UChar)kPatternPadEscape);
|
||||
// Substitute with the localized symbols if necessary
|
||||
if (localized) {
|
||||
zeroDigit = fSymbols->getZeroDigit();
|
||||
groupingSeparator = fSymbols->getGroupingSeparator();
|
||||
decimalSeparator = fSymbols->getDecimalSeparator();
|
||||
percent = fSymbols->getPercent();
|
||||
perMill = fSymbols->getPerMill();
|
||||
digit = fSymbols->getDigit();
|
||||
separator = fSymbols->getPatternSeparator();
|
||||
exponent = fSymbols->getExponentialSymbol();
|
||||
plus = fSymbols->getPlusSign();
|
||||
minus = fSymbols->getMinusSign();
|
||||
padEscape = fSymbols->getPadEscape();
|
||||
zeroDigit = fSymbols->getSymbol(DecimalFormatSymbols::kZeroDigitSymbol).char32At(0);
|
||||
groupingSeparator = fSymbols->getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
|
||||
decimalSeparator = fSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
|
||||
percent = fSymbols->getSymbol(DecimalFormatSymbols::kPercentSymbol);
|
||||
perMill = fSymbols->getSymbol(DecimalFormatSymbols::kPerMillSymbol);
|
||||
digit = fSymbols->getSymbol(DecimalFormatSymbols::kDigitSymbol);
|
||||
separator = fSymbols->getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol);
|
||||
exponent = fSymbols->getSymbol(DecimalFormatSymbols::kExponentialSymbol);
|
||||
plus = fSymbols->getSymbol(DecimalFormatSymbols::kPlusSignSymbol);
|
||||
minus = fSymbols->getSymbol(DecimalFormatSymbols::kMinusSignSymbol);
|
||||
padEscape = fSymbols->getSymbol(DecimalFormatSymbols::kPadEscapeSymbol);
|
||||
}
|
||||
UChar nineDigit = (UChar)(zeroDigit + 9);
|
||||
int32_t digitLen = digit.length();
|
||||
int32_t groupSepLen = groupingSeparator.length();
|
||||
int32_t decimalSepLen = decimalSeparator.length();
|
||||
|
||||
int32_t pos = 0;
|
||||
UTextOffset pos = 0;
|
||||
int32_t patLen = pattern.length();
|
||||
// Part 0 is the positive pattern. Part 1, if present, is the negative
|
||||
// pattern.
|
||||
for (int32_t part=0; part<2 && pos<pattern.length(); ++part) {
|
||||
for (int32_t part=0; part<2 && pos<patLen; ++part) {
|
||||
// The subpart ranges from 0 to 4: 0=pattern proper, 1=prefix,
|
||||
// 2=suffix, 3=prefix in quote, 4=suffix in quote. Subpart 0 is
|
||||
// between the prefix and suffix, and consists of pattern
|
||||
|
@ -2273,7 +2331,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
int8_t groupingCount = -1;
|
||||
int8_t groupingCount2 = -1;
|
||||
int32_t padPos = -1;
|
||||
UChar padChar = 0;
|
||||
UnicodeString padChar;
|
||||
int32_t roundingPos = -1;
|
||||
DigitList roundingInc;
|
||||
int8_t expDigits = -1;
|
||||
|
@ -2285,9 +2343,11 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
|
||||
int32_t start = pos;
|
||||
UBool isPartDone = FALSE;
|
||||
UChar32 ch;
|
||||
|
||||
for (; !isPartDone && pos < pattern.length(); ++pos) {
|
||||
UChar ch = pattern[(UTextOffset) pos];
|
||||
for (; !isPartDone && pos < patLen; pos += UTF_NEED_MULTIPLE_UCHAR(ch)) {
|
||||
// Todo: account for surrogate pairs
|
||||
ch = pattern.char32At(pos);
|
||||
switch (subpart) {
|
||||
case 0: // Pattern proper subpart (between prefix & suffix)
|
||||
// Process the digits, decimal, and grouping characters. We
|
||||
|
@ -2299,7 +2359,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// of characters), as is the position of the decimal point,
|
||||
// if any (should be in the zero digits). If there is no
|
||||
// decimal point, then there should be no right digits.
|
||||
if (ch == digit) {
|
||||
if (pattern.compare(pos, digitLen, digit) == 0) {
|
||||
if (zeroDigitCount > 0) {
|
||||
++digitRightCount;
|
||||
} else {
|
||||
|
@ -2308,6 +2368,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (groupingCount >= 0 && decimalPos < 0) {
|
||||
++groupingCount;
|
||||
}
|
||||
pos += digitLen;
|
||||
} else if (ch >= zeroDigit && ch <= nineDigit) {
|
||||
if (digitRightCount > 0) {
|
||||
// Unexpected '0'
|
||||
|
@ -2326,7 +2387,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
if (roundingPos >= 0) {
|
||||
roundingInc.append((char)(ch - zeroDigit + '0'));
|
||||
}
|
||||
} else if (ch == groupingSeparator) {
|
||||
pos++;
|
||||
} else if (pattern.compare(pos, groupSepLen, groupingSeparator) == 0) {
|
||||
if (decimalPos >= 0) {
|
||||
// Grouping separator after decimal
|
||||
debug("Grouping separator after decimal")
|
||||
|
@ -2336,7 +2398,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
}
|
||||
groupingCount2 = groupingCount;
|
||||
groupingCount = 0;
|
||||
} else if (ch == decimalSeparator) {
|
||||
pos += groupSepLen;
|
||||
} else if (pattern.compare(pos, decimalSepLen, decimalSeparator) == 0) {
|
||||
if (decimalPos >= 0) {
|
||||
// Multiple decimal separators
|
||||
debug("Multiple decimal separators")
|
||||
|
@ -2348,8 +2411,9 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// even though it is illegal for this to be > 0
|
||||
// at this point. We check pattern syntax below.
|
||||
decimalPos = digitLeftCount + zeroDigitCount + digitRightCount;
|
||||
pos += decimalSepLen;
|
||||
} else {
|
||||
if (ch == exponent) {
|
||||
if (pattern.compare(pos, exponent.length(), exponent) == 0) {
|
||||
if (expDigits >= 0) {
|
||||
// Multiple exponential symbols
|
||||
debug("Multiple exponential symbols")
|
||||
|
@ -2365,16 +2429,19 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
return;
|
||||
}
|
||||
// Check for positive prefix
|
||||
if ((pos+1) < pattern.length()
|
||||
&& pattern[(UTextOffset) (pos+1)] == plus) {
|
||||
if ((pos+1) < patLen
|
||||
&& pattern.compare((UTextOffset) (pos+1), plus.length(), plus) == 0)
|
||||
{
|
||||
expSignAlways = TRUE;
|
||||
++pos;
|
||||
pos += plus.length();
|
||||
}
|
||||
// Use lookahead to parse out the exponential part of the
|
||||
// pattern, then jump into suffix subpart.
|
||||
expDigits = 0;
|
||||
while (++pos < pattern.length() &&
|
||||
pattern[(UTextOffset) pos] == zeroDigit) {
|
||||
pos += exponent.length() - 1;
|
||||
while (++pos < patLen &&
|
||||
pattern[(UTextOffset) pos] == zeroDigit)
|
||||
{
|
||||
++expDigits;
|
||||
}
|
||||
|
||||
|
@ -2390,7 +2457,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// Transition to suffix subpart
|
||||
subpart = 2; // suffix subpart
|
||||
affix = &suffix;
|
||||
sub0Limit = pos--;
|
||||
sub0Limit = pos;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -2399,25 +2466,53 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// Process the prefix / suffix characters
|
||||
// Process unquoted characters seen in prefix or suffix
|
||||
// subpart.
|
||||
if (ch == digit ||
|
||||
ch == groupingSeparator ||
|
||||
ch == decimalSeparator ||
|
||||
(ch >= zeroDigit && ch <= nineDigit)) {
|
||||
if (pattern.compare(pos, digitLen, digit) == 0) {
|
||||
// Any of these characters implicitly begins the
|
||||
// next subpart if we are in the prefix
|
||||
if (subpart == 1) { // prefix subpart
|
||||
subpart = 0; // pattern proper subpart
|
||||
sub0Start = pos--; // Reprocess this character
|
||||
sub0Start = pos; // Reprocess this character
|
||||
continue;
|
||||
}
|
||||
pos += digitLen;
|
||||
// Fall through to append(ch)
|
||||
} else if (pattern.compare(pos, groupSepLen, groupingSeparator) == 0) {
|
||||
// Any of these characters implicitly begins the
|
||||
// next subpart if we are in the prefix
|
||||
if (subpart == 1) { // prefix subpart
|
||||
subpart = 0; // pattern proper subpart
|
||||
sub0Start = pos; // Reprocess this character
|
||||
continue;
|
||||
}
|
||||
pos += groupSepLen;
|
||||
// Fall through to append(ch)
|
||||
} else if (pattern.compare(pos, decimalSepLen, decimalSeparator) == 0) {
|
||||
// Any of these characters implicitly begins the
|
||||
// next subpart if we are in the prefix
|
||||
if (subpart == 1) { // prefix subpart
|
||||
subpart = 0; // pattern proper subpart
|
||||
sub0Start = pos; // Reprocess this character
|
||||
continue;
|
||||
}
|
||||
pos += decimalSepLen;
|
||||
// Fall through to append(ch)
|
||||
} else if (ch >= zeroDigit && ch <= nineDigit) {
|
||||
// Any of these characters implicitly begins the
|
||||
// next subpart if we are in the prefix
|
||||
if (subpart == 1) { // prefix subpart
|
||||
subpart = 0; // pattern proper subpart
|
||||
sub0Start = pos; // Reprocess this character
|
||||
continue;
|
||||
}
|
||||
pos++;
|
||||
// Fall through to append(ch)
|
||||
} else if (ch == kCurrencySign) {
|
||||
// Use lookahead to determine if the currency sign is
|
||||
// doubled or not.
|
||||
UBool doubled = (pos + 1) < pattern.length() &&
|
||||
pattern[(UTextOffset) (pos+1)] == kCurrencySign;
|
||||
pos++;
|
||||
affix->append(kQuote); // Encode currency
|
||||
if (doubled) {
|
||||
if (pos < pattern.length() && pattern[pos] == kCurrencySign)
|
||||
{
|
||||
affix->append(kCurrencySign);
|
||||
++pos; // Skip over the doubled character
|
||||
}
|
||||
|
@ -2427,16 +2522,16 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// A quote outside quotes indicates either the opening
|
||||
// quote or two quotes, which is a quote literal. That is,
|
||||
// we have the first quote in 'do' or o''clock.
|
||||
if ((pos+1) < pattern.length() &&
|
||||
pattern[(UTextOffset) (pos+1)] == kQuote) {
|
||||
++pos;
|
||||
++pos;
|
||||
if (pos < pattern.length() && pattern[pos] == kQuote) {
|
||||
affix->append(kQuote); // Encode quote
|
||||
++pos;
|
||||
// Fall through to append(ch)
|
||||
} else {
|
||||
subpart += 2; // open quote
|
||||
continue;
|
||||
}
|
||||
} else if (ch == separator) {
|
||||
} else if (pattern.compare(pos, separator.length(), separator) == 0) {
|
||||
// Don't allow separators in the prefix, and don't allow
|
||||
// separators in the second pattern (part == 1).
|
||||
if (subpart == 1 || part == 1) {
|
||||
|
@ -2448,26 +2543,37 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
}
|
||||
sub2Limit = pos;
|
||||
isPartDone = TRUE; // Go to next part
|
||||
pos += separator.length();
|
||||
break;
|
||||
} else if (ch == percent || ch == perMill) {
|
||||
} else if (pattern.compare(pos, percent.length(), percent) == 0) {
|
||||
// Next handle characters which are appended directly.
|
||||
if (multiplier != 1) {
|
||||
// Too many percent/perMill characters
|
||||
debug("Too many percent/perMill characters")
|
||||
debug("Too many percent characters")
|
||||
status = U_MULTIPLE_PERCENT_SYMBOLS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
affix->append(kQuote); // Encode percent/perMill
|
||||
if (ch == percent) {
|
||||
multiplier = 100;
|
||||
ch = kPatternPercent; // Use unlocalized pattern char
|
||||
} else {
|
||||
multiplier = 1000;
|
||||
ch = kPatternPerMill; // Use unlocalized pattern char
|
||||
}
|
||||
multiplier = 100;
|
||||
ch = kPatternPercent; // Use unlocalized pattern char
|
||||
pos += percent.length();
|
||||
// Fall through to append(ch)
|
||||
} else if (ch == padEscape) {
|
||||
} else if (pattern.compare(pos, perMill.length(), perMill) == 0) {
|
||||
// Next handle characters which are appended directly.
|
||||
if (multiplier != 1) {
|
||||
// Too many percent/perMill characters
|
||||
debug("Too many perMill characters")
|
||||
status = U_MULTIPLE_PERMILL_SYMBOLS;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
return;
|
||||
}
|
||||
affix->append(kQuote); // Encode percent/perMill
|
||||
multiplier = 1000;
|
||||
ch = kPatternPerMill; // Use unlocalized pattern char
|
||||
pos += perMill.length();
|
||||
// Fall through to append(ch)
|
||||
} else if (pattern.compare(pos, padEscape.length(), padEscape) == 0) {
|
||||
if (padPos >= 0 || // Multiple pad specifiers
|
||||
(pos+1) == pattern.length()) { // Nothing after padEscape
|
||||
debug("Multiple pad specifiers")
|
||||
|
@ -2477,15 +2583,20 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
}
|
||||
padPos = pos;
|
||||
padChar = pattern[(UTextOffset) ++pos];
|
||||
pos += padEscape.length();
|
||||
continue;
|
||||
} else if (ch == minus) {
|
||||
} else if (pattern.compare(pos, minus.length(), minus) == 0) {
|
||||
affix->append(kQuote); // Encode minus
|
||||
ch = kPatternMinus;
|
||||
pos += minus.length();
|
||||
// Fall through to append(ch)
|
||||
} else if (ch == plus) {
|
||||
} else if (pattern.compare(pos, plus.length(), plus) == 0) {
|
||||
affix->append(kQuote); // Encode plus
|
||||
ch = kPatternPlus;
|
||||
pos += plus.length();
|
||||
// Fall through to append(ch)
|
||||
} else {
|
||||
pos++;
|
||||
}
|
||||
// Unquoted, non-special characters fall through to here, as
|
||||
// well as other code which needs to append something to the
|
||||
|
@ -2497,9 +2608,9 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
// A quote within quotes indicates either the closing
|
||||
// quote or two quotes, which is a quote literal. That is,
|
||||
// we have the second quote in 'do' or 'don''t'.
|
||||
pos++;
|
||||
if (ch == kQuote) {
|
||||
if ((pos+1) < pattern.length() &&
|
||||
pattern[(UTextOffset) (pos+1)] == kQuote) {
|
||||
if (pos < pattern.length() && pattern[pos] == kQuote) {
|
||||
++pos;
|
||||
affix->append(kQuote); // Encode quote
|
||||
// Fall through to append(ch)
|
||||
|
@ -2550,7 +2661,8 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
(decimalPos < digitLeftCount ||
|
||||
decimalPos > (digitLeftCount + zeroDigitCount))) ||
|
||||
groupingCount == 0 || groupingCount2 == 0 ||
|
||||
subpart > 2) { // subpart > 2 == unmatched quote
|
||||
subpart > 2)
|
||||
{ // subpart > 2 == unmatched quote
|
||||
debug("Syntax error")
|
||||
status = U_PATTERN_SYNTAX_ERROR;
|
||||
syntaxError(pattern,pos,parseError);
|
||||
|
@ -2690,7 +2802,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
|||
fNegPrefixPattern->append(kQuote).append(kPatternMinus)
|
||||
.append(*fPosPrefixPattern);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
#ifdef FMT_DEBUG
|
||||
UnicodeString s;
|
||||
s.append("\"").append(pattern).append("\"->");
|
||||
debugout(s);
|
||||
|
|
|
@ -66,13 +66,12 @@
|
|||
* This class only handles localized digits where the 10 digits are
|
||||
* contiguous in Unicode, from 0 to 9. Other digits sets (such as
|
||||
* superscripts) would need a different subclass.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
*/
|
||||
class U_I18N_API DecimalFormatSymbols {
|
||||
public:
|
||||
/**
|
||||
* Constants for specifying a number format symbol.
|
||||
* @draft
|
||||
* @stable
|
||||
*/
|
||||
enum ENumberFormatSymbol {
|
||||
/** The decimal separator */
|
||||
|
@ -100,7 +99,7 @@ public:
|
|||
/** The exponential symbol */
|
||||
kExponentialSymbol,
|
||||
/** Per mill symbol */
|
||||
kPermillSymbol,
|
||||
kPerMillSymbol,
|
||||
/** Escape padding character */
|
||||
kPadEscapeSymbol,
|
||||
/** Infinity symbol */
|
||||
|
@ -179,18 +178,19 @@ public:
|
|||
*/
|
||||
void setSymbol(ENumberFormatSymbol symbol, UnicodeString value);
|
||||
|
||||
#ifdef ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES
|
||||
/**
|
||||
* character used for zero. Different for Arabic, etc.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getZeroDigit(void) const;
|
||||
/**
|
||||
* character used for zero. Different for Arabic, etc.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setZeroDigit(UChar zeroDigit);
|
||||
|
||||
|
@ -198,14 +198,14 @@ public:
|
|||
* character used for thousands separator. Different for French, etc.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getGroupingSeparator(void) const;
|
||||
/**
|
||||
* character used for thousands separator. Different for French, etc.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setGroupingSeparator(UChar groupingSeparator);
|
||||
|
||||
|
@ -213,14 +213,14 @@ public:
|
|||
* character used for decimal sign. Different for French, etc.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getDecimalSeparator(void) const;
|
||||
/**
|
||||
* character used for decimal sign. Different for French, etc.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setDecimalSeparator(UChar decimalSeparator);
|
||||
|
||||
|
@ -228,14 +228,14 @@ public:
|
|||
* character used for per mill sign. Different for Arabic, etc.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getPerMill(void) const;
|
||||
/**
|
||||
* character used for per mill sign. Different for Arabic, etc.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setPerMill(UChar permill);
|
||||
|
||||
|
@ -243,14 +243,14 @@ public:
|
|||
* character used for percent sign. Different for Arabic, etc.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getPercent(void) const;
|
||||
/**
|
||||
* character used for percent sign. Different for Arabic, etc.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setPercent(UChar percent);
|
||||
|
||||
|
@ -258,14 +258,14 @@ public:
|
|||
* character used for a digit in a pattern.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getDigit(void) const;
|
||||
/**
|
||||
* character used for a digit in a pattern.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setDigit(UChar digit);
|
||||
|
||||
|
@ -274,7 +274,7 @@ public:
|
|||
* in a pattern.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getPatternSeparator(void) const;
|
||||
/**
|
||||
|
@ -282,47 +282,47 @@ public:
|
|||
* in a pattern.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setPatternSeparator(UChar patternSeparator);
|
||||
|
||||
/**
|
||||
* character used to represent infinity. Almost always left
|
||||
* unchanged.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UnicodeString& getInfinity(UnicodeString& result) const;
|
||||
/**
|
||||
* character used to represent infinity. Almost always left
|
||||
* unchanged.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setInfinity(const UnicodeString& infinity);
|
||||
/**
|
||||
* Checks to see if text at offset represents the inifinity string.
|
||||
* @return the number of characters used to represent infinity when
|
||||
* text starts with the inifinity string, otherwise it returns 0.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
int32_t compareInfinity(const UnicodeString& text, UTextOffset offset) const;
|
||||
|
||||
/**
|
||||
* character used to represent NaN (Not A Number). Almost always left
|
||||
* unchanged.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UnicodeString& getNaN(UnicodeString& result) const;
|
||||
/**
|
||||
* character used to represent NaN. Almost always left
|
||||
* unchanged.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setNaN(const UnicodeString& NaN);
|
||||
/**
|
||||
* Checks to see if text at offset represents the NaN string.
|
||||
* @return the number of characters used to represent NaN when
|
||||
* text starts with the NaN string, otherwise it returns 0.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
int32_t compareNaN(const UnicodeString& text, UTextOffset offset) const;
|
||||
|
||||
|
@ -330,14 +330,14 @@ public:
|
|||
* character used to represent plus sign
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getPlusSign(void) const;
|
||||
/**
|
||||
* character used to represent plus sign
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setPlusSign(UChar minusSign);
|
||||
|
||||
|
@ -347,7 +347,7 @@ public:
|
|||
* minusSign to the positive format.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getMinusSign(void) const;
|
||||
/**
|
||||
|
@ -356,7 +356,7 @@ public:
|
|||
* minusSign to the positive format.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setMinusSign(UChar minusSign);
|
||||
|
||||
|
@ -365,7 +365,7 @@ public:
|
|||
* unchanged.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getExponentialSymbol(void) const;
|
||||
/**
|
||||
|
@ -373,18 +373,18 @@ public:
|
|||
* unchanged.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setExponentialSymbol(UChar exponential);
|
||||
|
||||
/**
|
||||
* The string denoting the local currency.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UnicodeString& getCurrencySymbol(UnicodeString& result) const;
|
||||
/**
|
||||
* The string denoting the local currency.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setCurrencySymbol(const UnicodeString& currency);
|
||||
/**
|
||||
|
@ -392,18 +392,18 @@ public:
|
|||
* @return the number of characters used to represent Currency Symbol when
|
||||
* text starts with the Currency Symbol string, otherwise it returns
|
||||
* 0.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
int32_t compareCurrencySymbol(const UnicodeString& text, UTextOffset offset) const;
|
||||
|
||||
/**
|
||||
* The international string denoting the local currency.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UnicodeString& getInternationalCurrencySymbol(UnicodeString& result) const;
|
||||
/**
|
||||
* The international string denoting the local currency.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setInternationalCurrencySymbol(const UnicodeString& currency);
|
||||
/**
|
||||
|
@ -412,7 +412,7 @@ public:
|
|||
* @return the number of characters used to represent International
|
||||
* Currency Symbol when text starts with the International Currency
|
||||
* Symbol string, otherwise it returns 0.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
int32_t compareInternationalCurrencySymbol(const UnicodeString& text, UTextOffset offset) const;
|
||||
|
||||
|
@ -420,14 +420,14 @@ public:
|
|||
* The monetary decimal separator.
|
||||
* This function returns only the first code unit of the symbol string,
|
||||
* unlike getSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getMonetaryDecimalSeparator(void) const;
|
||||
/**
|
||||
* The monetary decimal separator.
|
||||
* This function can set only a one-code unit symbol,
|
||||
* unlike setSymbol().
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setMonetaryDecimalSeparator(UChar sep);
|
||||
|
||||
|
@ -443,7 +443,7 @@ public:
|
|||
* @see DecimalFormat#getFormatWidth
|
||||
* @see DecimalFormat#getPadPosition
|
||||
* @see DecimalFormat#getPadCharacter
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and getSymbol() for a replacement.
|
||||
*/
|
||||
UChar getPadEscape(void) const;
|
||||
|
||||
|
@ -458,10 +458,10 @@ public:
|
|||
* @see DecimalFormat#setFormatWidth
|
||||
* @see DecimalFormat#setPadPosition
|
||||
* @see DecimalFormat#setPadCharacter
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and setSymbol() for a replacement.
|
||||
*/
|
||||
void setPadEscape(UChar c);
|
||||
|
||||
#endif
|
||||
private:
|
||||
/**
|
||||
* Initializes the symbols from the LocaleElements resource bundle.
|
||||
|
@ -505,6 +505,7 @@ DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, UnicodeString value)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES
|
||||
// -------------------------------------
|
||||
|
||||
inline UChar
|
||||
|
@ -811,6 +812,6 @@ inline UChar DecimalFormatSymbols::getPadEscape(void) const {
|
|||
inline void DecimalFormatSymbols::setPadEscape(UChar c) {
|
||||
fSymbols[kPadEscapeSymbol] = c;
|
||||
}
|
||||
|
||||
#endif /* ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES */
|
||||
#endif // _DCFMTSYM
|
||||
//eof
|
||||
|
|
|
@ -991,7 +991,7 @@ public:
|
|||
virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
static char fgClassID;
|
||||
static const char fgClassID;
|
||||
static UParseError fParseError;
|
||||
/**
|
||||
* Do real work of constructing a new DecimalFormat.
|
||||
|
@ -1110,7 +1110,7 @@ private:
|
|||
/*transient*/ double fRoundingDouble;
|
||||
ERoundingMode fRoundingMode;
|
||||
|
||||
UChar fPad;
|
||||
UnicodeString fPad;
|
||||
int32_t fFormatWidth;
|
||||
EPadPosition fPadPosition;
|
||||
|
||||
|
|
|
@ -597,6 +597,7 @@ unum_toPattern( const UNumberFormat* fmt,
|
|||
/* The maximum size for a textual number format symbol. */
|
||||
#define UNFSYMBOLSMAXSIZE 10
|
||||
|
||||
#ifdef ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES
|
||||
/** The UNumberFormatSymbols struct
|
||||
* @deprecated remove after 2000-dec-31. See UNumberFormatSymbol and unum_getSymbol() for a replacement.
|
||||
*/
|
||||
|
@ -663,6 +664,7 @@ U_CAPI void
|
|||
unum_setSymbols( UNumberFormat* fmt,
|
||||
const UNumberFormatSymbols* symbolsToSet,
|
||||
UErrorCode *status);
|
||||
#endif /* ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES */
|
||||
|
||||
/**
|
||||
* Constants for specifying a number format symbol.
|
||||
|
|
|
@ -583,6 +583,7 @@ unum_toPattern( const UNumberFormat* fmt,
|
|||
return pat.extract(result, resultLength, *status);
|
||||
}
|
||||
|
||||
#ifdef ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES
|
||||
U_CAPI void
|
||||
unum_getSymbols(const UNumberFormat* fmt,
|
||||
UNumberFormatSymbols *syms)
|
||||
|
@ -667,6 +668,9 @@ unum_setSymbols( UNumberFormat* fmt,
|
|||
((DecimalFormat*)fmt)->adoptDecimalFormatSymbols(syms);
|
||||
}
|
||||
|
||||
#endif /* ICU_DECIMALFORMATSYMBOLS_USE_DEPRECATES */
|
||||
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
unum_getSymbol(UNumberFormat *fmt,
|
||||
UNumberFormatSymbol symbol,
|
||||
|
|
|
@ -516,7 +516,6 @@ static void TestSecondaryGrouping(void) {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
UNumberFormat *f = NULL, *g= NULL;
|
||||
UNumberFormat *us = unum_open(UNUM_DECIMAL,NULL,0, "en_US", NULL,&status);
|
||||
UNumberFormatSymbols usSymbols;
|
||||
UFieldPosition pos;
|
||||
UChar resultBuffer[512];
|
||||
int32_t l = 1876543210L;
|
||||
|
@ -525,9 +524,6 @@ static void TestSecondaryGrouping(void) {
|
|||
int32_t i;
|
||||
UBool expectGroup = FALSE, isGroup = FALSE;
|
||||
|
||||
unum_getSymbols(us, &usSymbols);
|
||||
CHECK(status, "DecimalFormatSymbols ct");
|
||||
|
||||
u_uastrcpy(buffer, "#,##,###");
|
||||
f = unum_open(UNUM_IGNORE,buffer, -1, "en_US",NULL, &status);
|
||||
CHECK(status, "DecimalFormat ct");
|
||||
|
|
|
@ -40,6 +40,7 @@ static void TestNumberFormat()
|
|||
{
|
||||
UChar *result=NULL;
|
||||
UChar temp1[512];
|
||||
UChar temp2[512];
|
||||
|
||||
UChar temp[5];
|
||||
|
||||
|
@ -59,7 +60,7 @@ static void TestNumberFormat()
|
|||
int32_t i;
|
||||
|
||||
UNumberFormatAttribute attr;
|
||||
UNumberFormatSymbols symbols1, symbols2;
|
||||
UNumberFormatSymbol symType = UNUM_DECIMAL_SEPARATOR_SYMBOL;
|
||||
int32_t newvalue;
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UNumberFormatStyle style= UNUM_DEFAULT;
|
||||
|
@ -352,7 +353,16 @@ uprv_free(result);
|
|||
uprv_free(result);
|
||||
|
||||
/*getting the symbols of cur_def */
|
||||
unum_getSymbols(cur_def, &symbols1);
|
||||
/*set the symbols of cur_frpattern to cur_def */
|
||||
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
|
||||
status=U_ZERO_ERROR;
|
||||
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
|
||||
unum_setSymbol(cur_frpattern, symType, temp1, -1, &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Error in get/set symbols: %s\n", myErrorName(status));
|
||||
}
|
||||
}
|
||||
|
||||
/*format to check the result */
|
||||
resultlength=0;
|
||||
|
@ -369,33 +379,22 @@ uprv_free(result);
|
|||
log_err("Error in formatting using unum_format(.....): %s\n", myErrorName(status));
|
||||
}
|
||||
|
||||
|
||||
/*set the symbols of cur_frpattern to cur_def */
|
||||
unum_setSymbols(cur_frpattern, &symbols1, &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Fail: error in unum_setSymbols: %s\n", myErrorName(status));
|
||||
}
|
||||
unum_applyPattern(cur_frpattern, FALSE, result, u_strlen(result),NULL,NULL);
|
||||
unum_getSymbols(cur_frpattern, &symbols2);
|
||||
if((symbols1.decimalSeparator != symbols2.decimalSeparator) ||
|
||||
(symbols1.groupingSeparator != symbols2.groupingSeparator) ||
|
||||
(symbols1.patternSeparator != symbols2.patternSeparator) ||
|
||||
(symbols1.percent != symbols2.percent) ||
|
||||
(symbols1.zeroDigit != symbols2.zeroDigit) ||
|
||||
(symbols1.digit != symbols2.digit) ||
|
||||
(symbols1.minusSign != symbols2.minusSign) ||
|
||||
(symbols1.plusSign != symbols2.plusSign) ||
|
||||
(u_strcmp(symbols1.currency,symbols2.currency)!=0) ||
|
||||
(u_strcmp(symbols1.intlCurrency,symbols2.intlCurrency)!=0) ||
|
||||
(symbols1.monetarySeparator != symbols2.monetarySeparator) ||
|
||||
(symbols1.exponential != symbols2.exponential) ||
|
||||
(symbols1.perMill != symbols2.perMill) ||
|
||||
(symbols1.padEscape != symbols2.padEscape) ||
|
||||
(u_strcmp(symbols1.infinity,symbols2.infinity)!=0) ||
|
||||
(u_strcmp(symbols1.naN,symbols2.naN)!=0))
|
||||
log_err("Fail: error in setting and getting symbols\n");
|
||||
else
|
||||
log_verbose("Pass: get and set symbols successful\n");
|
||||
|
||||
for (symType = UNUM_DECIMAL_SEPARATOR_SYMBOL; symType < UNUM_FORMAT_SYMBOL_COUNT; symType++) {
|
||||
status=U_ZERO_ERROR;
|
||||
unum_getSymbol(cur_def, symType, temp1, sizeof(temp1), &status);
|
||||
unum_getSymbol(cur_frpattern, symType, temp2, sizeof(temp2), &status);
|
||||
if(U_FAILURE(status) || u_strcmp(temp1, temp2) != 0)
|
||||
{
|
||||
log_err("Fail: error in getting symbols\n");
|
||||
}
|
||||
else
|
||||
log_verbose("Pass: get and set symbols successful\n");
|
||||
}
|
||||
|
||||
/*format and check with the previous result */
|
||||
|
||||
|
|
|
@ -214,12 +214,16 @@ NumberFormatTest::TestExponential(void)
|
|||
logln((UnicodeString)" -parse-> " + a);
|
||||
// Use epsilon comparison as necessary
|
||||
if ((useEpsilon &&
|
||||
(uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
|
||||
(uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
|
||||
(!useEpsilon && a != valParse[v+ival]))
|
||||
errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
|
||||
{
|
||||
errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
|
||||
errln((UnicodeString)" should be (" + s.length() + " chars) -> " + valParse[v+ival]);
|
||||
}
|
||||
}
|
||||
for (v=0; v<lval_length; ++v)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,8 @@ UBool
|
|||
NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg)
|
||||
{
|
||||
if(U_FAILURE(status)) {
|
||||
errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
|
||||
errln(UnicodeString("FAIL: ", "") + msg
|
||||
+ UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), ""));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -201,7 +202,7 @@ void NumberFormatRegressionTest::Test4087245 (void)
|
|||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
logln(UnicodeString("format(") + n + ") = " +
|
||||
df->format(n, buf1, pos));
|
||||
symbols->setDecimalSeparator(0x70); // change value of field
|
||||
symbols->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, UnicodeString((UChar)0x70)); // change value of field
|
||||
logln(UnicodeString("format(") + n + ") = " +
|
||||
df->format(n, buf2, pos));
|
||||
if(buf1 != buf2)
|
||||
|
@ -675,8 +676,8 @@ void NumberFormatRegressionTest::Test4087244 (void) {
|
|||
}
|
||||
DecimalFormat *df = (DecimalFormat*) nf;
|
||||
const DecimalFormatSymbols *sym = df->getDecimalFormatSymbols();
|
||||
UChar decSep = sym->getDecimalSeparator();
|
||||
UChar monSep = sym->getMonetaryDecimalSeparator();
|
||||
UnicodeString decSep = sym->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
|
||||
UnicodeString monSep = sym->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
|
||||
if (decSep == monSep) {
|
||||
errln("ERROR in test: want decimal sep != monetary sep");
|
||||
return;
|
||||
|
@ -686,8 +687,10 @@ void NumberFormatRegressionTest::Test4087244 (void) {
|
|||
UnicodeString str;
|
||||
FieldPosition pos;
|
||||
df->format(1.23, str, pos);
|
||||
UnicodeString monStr("1x23"); monStr[(UTextOffset)1] = monSep;
|
||||
UnicodeString decStr("1x23"); decStr[(UTextOffset)1] = decSep;
|
||||
UnicodeString monStr("1x23");
|
||||
monStr.replace((UTextOffset)1, 1, monSep);
|
||||
UnicodeString decStr("1x23");
|
||||
decStr.replace((UTextOffset)1, 1, decSep);
|
||||
if (str.indexOf(monStr) >= 0 && str.indexOf(decStr) < 0) {
|
||||
logln(UnicodeString("OK: 1.23 -> \"") + str + "\" contains \"" +
|
||||
monStr + "\" and not \"" + decStr + '"');
|
||||
|
@ -1117,28 +1120,27 @@ void NumberFormatRegressionTest::Test4061302(void)
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols *fmt = new DecimalFormatSymbols(status);
|
||||
failure(status, "new DecimalFormatSymbols");
|
||||
UnicodeString currency;
|
||||
currency= fmt->getCurrencySymbol(currency);
|
||||
UnicodeString intlCurrency;
|
||||
intlCurrency = fmt->getInternationalCurrencySymbol(intlCurrency);
|
||||
UChar monDecSeparator = fmt->getMonetaryDecimalSeparator();
|
||||
UnicodeString currency(fmt->getSymbol(DecimalFormatSymbols::kCurrencySymbol));
|
||||
UnicodeString intlCurrency(fmt->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
|
||||
UnicodeString monDecSeparator(fmt->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
|
||||
if (currency == UnicodeString("") ||
|
||||
intlCurrency == UnicodeString("") ||
|
||||
monDecSeparator == 0x0000) {
|
||||
monDecSeparator == UnicodeString(""))
|
||||
{
|
||||
errln("getCurrencySymbols failed, got empty string.");
|
||||
}
|
||||
UnicodeString monDecSeparatorStr;
|
||||
monDecSeparatorStr.append(monDecSeparator);
|
||||
logln((UnicodeString)"Before set ==> Currency : " + currency +(UnicodeString)" Intl Currency : " + intlCurrency + (UnicodeString)" Monetary Decimal Separator : " + monDecSeparatorStr);
|
||||
fmt->setCurrencySymbol(UnicodeString("XYZ"));
|
||||
fmt->setInternationalCurrencySymbol(UnicodeString("ABC"));
|
||||
fmt->setMonetaryDecimalSeparator(0x002A/*'*'*/);
|
||||
currency = fmt->getCurrencySymbol(currency);
|
||||
intlCurrency = fmt->getInternationalCurrencySymbol(intlCurrency);
|
||||
monDecSeparator = fmt->getMonetaryDecimalSeparator();
|
||||
fmt->setSymbol(DecimalFormatSymbols::kCurrencySymbol, UnicodeString("XYZ"));
|
||||
fmt->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, UnicodeString("ABC"));
|
||||
fmt->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UnicodeString((UChar)0x002A/*'*'*/));
|
||||
currency = fmt->getSymbol(DecimalFormatSymbols::kCurrencySymbol);
|
||||
intlCurrency = fmt->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);
|
||||
monDecSeparator = fmt->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
|
||||
if (currency != UnicodeString("XYZ") ||
|
||||
intlCurrency != UnicodeString("ABC") ||
|
||||
monDecSeparator != 0x002A/*'*'*/) {
|
||||
monDecSeparator != UnicodeString((UChar)0x002A/*'*'*/)) {
|
||||
errln("setCurrencySymbols failed.");
|
||||
}
|
||||
monDecSeparatorStr.remove();
|
||||
|
@ -1399,7 +1401,6 @@ void NumberFormatRegressionTest::Test4122840(void)
|
|||
UnicodeString foo(fo, 1, 1);
|
||||
|
||||
//if (pattern.indexOf("\u00A4") == -1 ) {
|
||||
UnicodeString temp;
|
||||
if (pattern.indexOf(foo) == -1 ) {
|
||||
errln(UnicodeString("Currency format for ") + UnicodeString(locales[i].getName()) +
|
||||
" does not contain generic currency symbol:" +
|
||||
|
@ -1424,22 +1425,23 @@ void NumberFormatRegressionTest::Test4122840(void)
|
|||
UChar ba[] = { 0x002E/*'.'*/ };
|
||||
UnicodeString bar(ba, 1, 1);
|
||||
|
||||
if (symbols->getCurrencySymbol(temp).indexOf(bar) == -1) {
|
||||
if (symbols->getSymbol(DecimalFormatSymbols::kCurrencySymbol).indexOf(bar) == -1) {
|
||||
// {sfb} Also, switch the decimal separator to the monetary decimal
|
||||
// separator to mimic the behavior of a currency format
|
||||
symbols->setDecimalSeparator(symbols->getMonetaryDecimalSeparator());
|
||||
symbols->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol,
|
||||
symbols->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
|
||||
|
||||
UnicodeString buf(pattern);
|
||||
for (int j = 0; j < buf.length(); j++) {
|
||||
if (buf[j] == 0x00a4 ) {
|
||||
if(buf[j + 1] == 0x00a4) {
|
||||
// {sfb} added to support double currency marker (intl currency sign)
|
||||
buf.replace(j, /*j+*/2, symbols->getInternationalCurrencySymbol(temp));
|
||||
j += symbols->getInternationalCurrencySymbol(temp).length() - 1 + 1;
|
||||
buf.replace(j, /*j+*/2, symbols->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
|
||||
j += symbols->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol).length();
|
||||
}
|
||||
else {
|
||||
buf.replace(j, /*j+*/1, symbols->getCurrencySymbol(temp));
|
||||
j += symbols->getCurrencySymbol(temp).length() - 1;
|
||||
buf.replace(j, /*j+*/1, symbols->getSymbol(DecimalFormatSymbols::kCurrencySymbol));
|
||||
j += symbols->getSymbol(DecimalFormatSymbols::kCurrencySymbol).length() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1448,10 +1450,10 @@ void NumberFormatRegressionTest::Test4122840(void)
|
|||
failure(status, "new DecimalFormat");
|
||||
|
||||
UnicodeString result2;
|
||||
result2 = fmt2->format(1.111, result2, pos);
|
||||
fmt2->format(1.111, result2, pos);
|
||||
|
||||
if (result1 != result2) {
|
||||
errln("Results for " + (temp=locales[i].getName()) + " differ: " +
|
||||
errln("Results for " + (UnicodeString)(locales[i].getName()) + " differ: " +
|
||||
result1 + " vs " + result2);
|
||||
}
|
||||
|
||||
|
@ -1632,54 +1634,54 @@ void NumberFormatRegressionTest::Test4145457() {
|
|||
}
|
||||
|
||||
DecimalFormat *nf = (DecimalFormat*)nff;
|
||||
DecimalFormatSymbols *sym = (DecimalFormatSymbols*) nf->getDecimalFormatSymbols();
|
||||
sym->setDecimalSeparator(/*'\''*/0x0027);
|
||||
nf->setDecimalFormatSymbols(*sym);
|
||||
double pi = 3.14159;
|
||||
DecimalFormatSymbols *sym = (DecimalFormatSymbols*) nf->getDecimalFormatSymbols();
|
||||
sym->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, (UChar)/*'\''*/0x0027);
|
||||
nf->setDecimalFormatSymbols(*sym);
|
||||
double pi = 3.14159;
|
||||
|
||||
UnicodeString PATS [] = {
|
||||
UnicodeString("#.00 'num''ber'"), UnicodeString("''#.00''")
|
||||
};
|
||||
|
||||
UnicodeString PATS [] = {
|
||||
UnicodeString("#.00 'num''ber'"), UnicodeString("''#.00''")
|
||||
};
|
||||
|
||||
for (int32_t i=0; i<2; ++i) {
|
||||
nf->applyPattern(PATS[i], status);
|
||||
failure(status, "nf->applyPattern");
|
||||
UnicodeString out;
|
||||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
out = nf->format(pi, out, pos);
|
||||
UnicodeString pat;
|
||||
pat = nf->toPattern(pat);
|
||||
Formattable num;
|
||||
ParsePosition pp(0);
|
||||
nf->parse(out, num, pp);
|
||||
double val = num.getDouble();
|
||||
for (int32_t i=0; i<2; ++i) {
|
||||
nf->applyPattern(PATS[i], status);
|
||||
failure(status, "nf->applyPattern");
|
||||
UnicodeString out;
|
||||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
out = nf->format(pi, out, pos);
|
||||
UnicodeString pat;
|
||||
pat = nf->toPattern(pat);
|
||||
Formattable num;
|
||||
ParsePosition pp(0);
|
||||
nf->parse(out, num, pp);
|
||||
double val = num.getDouble();
|
||||
|
||||
nf->applyPattern(pat, status);
|
||||
failure(status, "nf->applyPattern");
|
||||
UnicodeString out2;
|
||||
out2 = nf->format(pi, out2, pos);
|
||||
UnicodeString pat2;
|
||||
pat2 = nf->toPattern(pat2);
|
||||
nf->parse(out2, num, pp);
|
||||
double val2 = num.getDouble();
|
||||
nf->applyPattern(pat, status);
|
||||
failure(status, "nf->applyPattern");
|
||||
UnicodeString out2;
|
||||
out2 = nf->format(pi, out2, pos);
|
||||
UnicodeString pat2;
|
||||
pat2 = nf->toPattern(pat2);
|
||||
nf->parse(out2, num, pp);
|
||||
double val2 = num.getDouble();
|
||||
|
||||
if (pat != pat2)
|
||||
errln("Fail with \"" + PATS[i] + "\": Patterns should concur, \"" +
|
||||
pat + "\" vs. \"" + pat2 + "\"");
|
||||
else
|
||||
logln("Ok \"" + PATS[i] + "\" toPattern() -> \"" + pat + '"');
|
||||
|
||||
if (val == val2 && out == out2) {
|
||||
logln(UnicodeString("Ok ") + pi + " x \"" + PATS[i] + "\" -> \"" +
|
||||
out + "\" -> " + val + " -> \"" +
|
||||
out2 + "\" -> " + val2);
|
||||
}
|
||||
else {
|
||||
errln(UnicodeString("Fail ") + pi + " x \"" + PATS[i] + "\" -> \"" +
|
||||
out + "\" -> " + val + " -> \"" +
|
||||
out2 + "\" -> " + val2);
|
||||
}
|
||||
if (pat != pat2)
|
||||
errln("Fail with \"" + PATS[i] + "\": Patterns should concur, \"" +
|
||||
pat + "\" vs. \"" + pat2 + "\"");
|
||||
else
|
||||
logln("Ok \"" + PATS[i] + "\" toPattern() -> \"" + pat + '"');
|
||||
|
||||
if (val == val2 && out == out2) {
|
||||
logln(UnicodeString("Ok ") + pi + " x \"" + PATS[i] + "\" -> \"" +
|
||||
out + "\" -> " + val + " -> \"" +
|
||||
out2 + "\" -> " + val2);
|
||||
}
|
||||
else {
|
||||
errln(UnicodeString("Fail ") + pi + " x \"" + PATS[i] + "\" -> \"" +
|
||||
out + "\" -> " + val + " -> \"" +
|
||||
out2 + "\" -> " + val2);
|
||||
}
|
||||
}
|
||||
/*}
|
||||
catch (ParseException e) {
|
||||
errln("Fail: " + e);
|
||||
|
@ -1986,6 +1988,7 @@ void NumberFormatRegressionTest::Test4179818(void) {
|
|||
void NumberFormatRegressionTest::Test4212072(void) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols sym(Locale::US, status);
|
||||
/*
|
||||
failure(status, "DecimalFormatSymbols ct");
|
||||
DecimalFormat fmt(UnicodeString("#"), sym, status);
|
||||
failure(status, "DecimalFormat ct");
|
||||
|
@ -1993,7 +1996,7 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
UnicodeString s;
|
||||
FieldPosition pos;
|
||||
|
||||
sym.setMinusSign(0x5e);
|
||||
sym.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, (UChar)0x5e);
|
||||
fmt.setDecimalFormatSymbols(sym);
|
||||
s.remove();
|
||||
if (fmt.format((int32_t)-1, s, pos) != UNICODE_STRING("^1", 2)) {
|
||||
|
@ -2005,11 +2008,11 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
errln(UnicodeString("FAIL: (minus=^).getNegativePrefix -> ") +
|
||||
s + ", exp ^");
|
||||
}
|
||||
sym.setMinusSign(0x2d);
|
||||
sym.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, (UChar)0x2d);
|
||||
|
||||
fmt.applyPattern(UnicodeString("#%"), status);
|
||||
failure(status, "applyPattern percent");
|
||||
sym.setPercent(0x5e);
|
||||
sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, (UChar)0x5e);
|
||||
fmt.setDecimalFormatSymbols(sym);
|
||||
s.remove();
|
||||
if (fmt.format(0.25, s, pos) != UNICODE_STRING("25^", 3)) {
|
||||
|
@ -2021,11 +2024,11 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
errln(UnicodeString("FAIL: (percent=^).getPositiveSuffix -> ") +
|
||||
s + ", exp ^");
|
||||
}
|
||||
sym.setPercent(0x25);
|
||||
sym.setSymbol(DecimalFormatSymbols::kPercentSymbol, (UChar)0x25);
|
||||
|
||||
fmt.applyPattern(str("#\\u2030"), status);
|
||||
failure(status, "applyPattern permill");
|
||||
sym.setPerMill(0x5e);
|
||||
sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, (UChar)0x5e);
|
||||
fmt.setDecimalFormatSymbols(sym);
|
||||
s.remove();
|
||||
if (fmt.format(0.25, s, pos) != UNICODE_STRING("250^", 4)) {
|
||||
|
@ -2037,11 +2040,11 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
errln(UnicodeString("FAIL: (permill=^).getPositiveSuffix -> ") +
|
||||
s + ", exp ^");
|
||||
}
|
||||
sym.setPerMill(0x2030);
|
||||
sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, (UChar)0x2030);
|
||||
|
||||
fmt.applyPattern(str("\\u00A4#.00"), status);
|
||||
failure(status, "applyPattern currency");
|
||||
sym.setCurrencySymbol("usd");
|
||||
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "usd");
|
||||
fmt.setDecimalFormatSymbols(sym);
|
||||
s.remove();
|
||||
if (fmt.format(12.5, s, pos) != UnicodeString("usd12.50")) {
|
||||
|
@ -2053,11 +2056,11 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
errln(UnicodeString("FAIL: (currency=usd).getPositivePrefix -> ") +
|
||||
s + ", exp usd");
|
||||
}
|
||||
sym.setCurrencySymbol("$");
|
||||
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "$");
|
||||
|
||||
fmt.applyPattern(str("\\u00A4\\u00A4#.00"), status);
|
||||
failure(status, "applyPattern intl currency");
|
||||
sym.setInternationalCurrencySymbol("DOL");
|
||||
sym.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, "DOL");
|
||||
fmt.setDecimalFormatSymbols(sym);
|
||||
s.remove();
|
||||
if (fmt.format(12.5, s, pos) != UnicodeString("DOL12.50")) {
|
||||
|
@ -2069,8 +2072,8 @@ void NumberFormatRegressionTest::Test4212072(void) {
|
|||
errln(UnicodeString("FAIL: (intlcurrency=DOL).getPositivePrefix -> ") +
|
||||
s + ", exp DOL");
|
||||
}
|
||||
sym.setInternationalCurrencySymbol("USD");
|
||||
|
||||
sym.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, "USD");
|
||||
*/
|
||||
// Since the pattern logic has changed, make sure that patterns round
|
||||
// trip properly. Test stream in/out integrity too.
|
||||
int32_t n;
|
||||
|
|
|
@ -32,13 +32,13 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
|||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
DecimalFormatSymbols fr(Locale::FRENCH, status);
|
||||
DecimalFormatSymbols fr(Locale::getFrench(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("ERROR: Couldn't create French DecimalFormatSymbols");
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols en(Locale::ENGLISH, status);
|
||||
DecimalFormatSymbols en(Locale::getEnglish(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("ERROR: Couldn't create English DecimalFormatSymbols");
|
||||
}
|
||||
|
@ -49,75 +49,71 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
|||
|
||||
// just do some VERY basic tests to make sure that get/set work
|
||||
|
||||
UChar zero = en.getZeroDigit();
|
||||
fr.setZeroDigit(zero);
|
||||
if(fr.getZeroDigit() != en.getZeroDigit()) {
|
||||
UnicodeString zero = en.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol) != en.getSymbol(DecimalFormatSymbols::kZeroDigitSymbol)) {
|
||||
errln("ERROR: get/set ZeroDigit failed");
|
||||
}
|
||||
|
||||
UChar group = en.getGroupingSeparator();
|
||||
fr.setGroupingSeparator(group);
|
||||
if(fr.getGroupingSeparator() != en.getGroupingSeparator()) {
|
||||
UnicodeString group = en.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, group);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol)) {
|
||||
errln("ERROR: get/set GroupingSeparator failed");
|
||||
}
|
||||
|
||||
UChar decimal = en.getDecimalSeparator();
|
||||
fr.setDecimalSeparator(decimal);
|
||||
if(fr.getDecimalSeparator() != en.getDecimalSeparator()) {
|
||||
UnicodeString decimal = en.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, decimal);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol)) {
|
||||
errln("ERROR: get/set DecimalSeparator failed");
|
||||
}
|
||||
|
||||
UChar perMill = en.getPerMill();
|
||||
fr.setPerMill(perMill);
|
||||
if(fr.getPerMill() != en.getPerMill()) {
|
||||
UnicodeString perMill = en.getSymbol(DecimalFormatSymbols::kPerMillSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kPerMillSymbol, perMill);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kPerMillSymbol) != en.getSymbol(DecimalFormatSymbols::kPerMillSymbol)) {
|
||||
errln("ERROR: get/set PerMill failed");
|
||||
}
|
||||
|
||||
UChar percent = en.getPercent();
|
||||
fr.setPercent(percent);
|
||||
if(fr.getPercent() != en.getPercent()) {
|
||||
UnicodeString percent = en.getSymbol(DecimalFormatSymbols::kPercentSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kPercentSymbol, percent);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kPercentSymbol) != en.getSymbol(DecimalFormatSymbols::kPercentSymbol)) {
|
||||
errln("ERROR: get/set Percent failed");
|
||||
}
|
||||
|
||||
UChar digit = en.getDigit();
|
||||
fr.setDigit(digit);
|
||||
if(fr.getPercent() != en.getPercent()) {
|
||||
UnicodeString digit(en.getSymbol(DecimalFormatSymbols::kDigitSymbol));
|
||||
fr.setSymbol(DecimalFormatSymbols::kDigitSymbol, digit);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kDigitSymbol) != en.getSymbol(DecimalFormatSymbols::kDigitSymbol)) {
|
||||
errln("ERROR: get/set Percent failed");
|
||||
}
|
||||
|
||||
UChar patternSeparator = en.getPatternSeparator();
|
||||
fr.setPatternSeparator(patternSeparator);
|
||||
if(fr.getPatternSeparator() != en.getPatternSeparator()) {
|
||||
UnicodeString patternSeparator = en.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, patternSeparator);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol) != en.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol)) {
|
||||
errln("ERROR: get/set PatternSeparator failed");
|
||||
}
|
||||
|
||||
UnicodeString infinity;
|
||||
infinity = en.getInfinity(infinity);
|
||||
fr.setInfinity(infinity);
|
||||
UnicodeString infinity2;
|
||||
infinity2 = fr.getInfinity(infinity2);
|
||||
UnicodeString infinity(en.getSymbol(DecimalFormatSymbols::kInfinitySymbol));
|
||||
fr.setSymbol(DecimalFormatSymbols::kInfinitySymbol, infinity);
|
||||
UnicodeString infinity2(fr.getSymbol(DecimalFormatSymbols::kInfinitySymbol));
|
||||
if(infinity != infinity2) {
|
||||
errln("ERROR: get/set Infinity failed");
|
||||
}
|
||||
|
||||
UnicodeString nan;
|
||||
nan = en.getNaN(infinity);
|
||||
fr.setNaN(nan);
|
||||
UnicodeString nan2;
|
||||
nan2 = fr.getNaN(nan2);
|
||||
UnicodeString nan(en.getSymbol(DecimalFormatSymbols::kNaNSymbol));
|
||||
fr.setSymbol(DecimalFormatSymbols::kNaNSymbol, nan);
|
||||
UnicodeString nan2(fr.getSymbol(DecimalFormatSymbols::kNaNSymbol));
|
||||
if(nan != nan2) {
|
||||
errln("ERROR: get/set NaN failed");
|
||||
}
|
||||
|
||||
UChar minusSign = en.getMinusSign();
|
||||
fr.setMinusSign(minusSign);
|
||||
if(fr.getMinusSign() != en.getMinusSign()) {
|
||||
UnicodeString minusSign = en.getSymbol(DecimalFormatSymbols::kMinusSignSymbol);
|
||||
fr.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, minusSign);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kMinusSignSymbol) != en.getSymbol(DecimalFormatSymbols::kMinusSignSymbol)) {
|
||||
errln("ERROR: get/set MinusSign failed");
|
||||
}
|
||||
|
||||
UChar exponential = en.getExponentialSymbol();
|
||||
fr.setExponentialSymbol(exponential);
|
||||
if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
|
||||
UnicodeString exponential(en.getSymbol(DecimalFormatSymbols::kExponentialSymbol));
|
||||
fr.setSymbol(DecimalFormatSymbols::kExponentialSymbol, exponential);
|
||||
if(fr.getSymbol(DecimalFormatSymbols::kExponentialSymbol) != en.getSymbol(DecimalFormatSymbols::kExponentialSymbol)) {
|
||||
errln("ERROR: get/set Exponential failed");
|
||||
}
|
||||
|
||||
|
@ -152,7 +148,7 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
|||
}
|
||||
|
||||
|
||||
DecimalFormatSymbols sym(Locale::US, status);
|
||||
DecimalFormatSymbols sym(Locale::getUS(), status);
|
||||
|
||||
UnicodeString customDecSeperator("S");
|
||||
Verify(34.5, (UnicodeString)"00.00", sym, (UnicodeString)"34.50");
|
||||
|
@ -166,6 +162,7 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
|
|||
Verify(3456.5, (UnicodeString)"0,000.##", sym, (UnicodeString)"3|456S5");
|
||||
|
||||
}
|
||||
|
||||
void IntlTestDecimalFormatSymbols::Verify(double value, const UnicodeString& pattern, DecimalFormatSymbols sym, const UnicodeString& expected){
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormat *df = new DecimalFormat(pattern, sym, status);
|
||||
|
@ -176,7 +173,7 @@ void IntlTestDecimalFormatSymbols::Verify(double value, const UnicodeString& pat
|
|||
FieldPosition pos(FieldPosition::DONT_CARE);
|
||||
buffer = df->format(value, buffer, pos);
|
||||
if(buffer != expected){
|
||||
errln((UnicodeString)"ERROR: format failed after setSymbols()\n Expected" +
|
||||
errln((UnicodeString)"ERROR: format failed after setSymbols()\n Expected " +
|
||||
expected + ", Got " + buffer);
|
||||
}
|
||||
delete df;
|
||||
|
|
Loading…
Add table
Reference in a new issue