ICU-7391 changed ref to pointer in APIs taking FieldPositionIterator, cleaned whitespace

X-SVN-Rev: 27433
This commit is contained in:
Doug Felt 2010-01-28 19:39:24 +00:00
parent 79d3710ae3
commit bd8eb26d17
12 changed files with 557 additions and 532 deletions

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2009, International Business Machines Corporation and *
* Copyright (C) 1997-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
@ -144,7 +144,7 @@ DateFormat::format(const Formattable& obj,
UnicodeString&
DateFormat::format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
if (U_FAILURE(status)) return appendTo;
@ -180,7 +180,7 @@ DateFormat::format(const Formattable& obj,
UnicodeString&
DateFormat::format(Calendar& /* unused cal */,
UnicodeString& appendTo,
FieldPositionIterator& /* unused posIter */,
FieldPositionIterator* /* unused posIter */,
UErrorCode& status) const {
if (U_SUCCESS(status)) {
status = U_UNSUPPORTED_ERROR;
@ -206,7 +206,7 @@ DateFormat::format(UDate date, UnicodeString& appendTo, FieldPosition& fieldPosi
//----------------------------------------------------------------------
UnicodeString&
DateFormat::format(UDate date, UnicodeString& appendTo, FieldPositionIterator& posIter,
DateFormat::format(UDate date, UnicodeString& appendTo, FieldPositionIterator* posIter,
UErrorCode& status) const {
if (fCalendar != NULL) {
fCalendar->setTime(date, status);

View file

@ -32,11 +32,11 @@
* 02/22/99 stephen Removed character literals for EBCDIC safety
* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
* 06/28/99 stephen Fixed bugs in toPattern().
* 06/29/99 stephen Fixed operator= to copy fFormatWidth, fPad,
* 06/29/99 stephen Fixed operator= to copy fFormatWidth, fPad,
* fPadPosition
********************************************************************************
*/
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
@ -67,8 +67,8 @@
U_NAMESPACE_BEGIN
/* For currency parsing purose,
* Need to remember all prefix patterns and suffix patterns of
* every currency format pattern,
* Need to remember all prefix patterns and suffix patterns of
* every currency format pattern,
* including the pattern of default currecny style
* and plural currency style. And the patterns are set through applyPattern.
*/
@ -82,8 +82,8 @@ struct AffixPatternsForCurrency : public UMemory {
// positive suffix pattern
UnicodeString posSuffixPatternForCurrency;
int8_t patternType;
AffixPatternsForCurrency(const UnicodeString& negPrefix,
AffixPatternsForCurrency(const UnicodeString& negPrefix,
const UnicodeString& negSuffix,
const UnicodeString& posPrefix,
const UnicodeString& posSuffix,
@ -97,7 +97,7 @@ struct AffixPatternsForCurrency : public UMemory {
};
/* affix for currency formatting when the currency sign in the pattern
* equals to 3, such as the pattern contains 3 currency sign or
* equals to 3, such as the pattern contains 3 currency sign or
* the formatter style is currency plural format style.
*/
struct AffixesForCurrency : public UMemory {
@ -109,7 +109,7 @@ struct AffixesForCurrency : public UMemory {
UnicodeString posPrefixForCurrency;
// positive suffix
UnicodeString posSuffixForCurrency;
int32_t formatWidth;
AffixesForCurrency(const UnicodeString& negPrefix,
@ -138,9 +138,9 @@ static UBool U_CALLCONV decimfmtAffixPatternValueComparator(UHashTok val1, UHash
static UBool
U_CALLCONV decimfmtAffixValueComparator(UHashTok val1, UHashTok val2) {
const AffixesForCurrency* affix_1 =
const AffixesForCurrency* affix_1 =
(AffixesForCurrency*)val1.pointer;
const AffixesForCurrency* affix_2 =
const AffixesForCurrency* affix_2 =
(AffixesForCurrency*)val2.pointer;
return affix_1->negPrefixForCurrency == affix_2->negPrefixForCurrency &&
affix_1->negSuffixForCurrency == affix_2->negSuffixForCurrency &&
@ -151,17 +151,17 @@ U_CALLCONV decimfmtAffixValueComparator(UHashTok val1, UHashTok val2) {
static UBool
U_CALLCONV decimfmtAffixPatternValueComparator(UHashTok val1, UHashTok val2) {
const AffixPatternsForCurrency* affix_1 =
const AffixPatternsForCurrency* affix_1 =
(AffixPatternsForCurrency*)val1.pointer;
const AffixPatternsForCurrency* affix_2 =
const AffixPatternsForCurrency* affix_2 =
(AffixPatternsForCurrency*)val2.pointer;
return affix_1->negPrefixPatternForCurrency ==
return affix_1->negPrefixPatternForCurrency ==
affix_2->negPrefixPatternForCurrency &&
affix_1->negSuffixPatternForCurrency ==
affix_1->negSuffixPatternForCurrency ==
affix_2->negSuffixPatternForCurrency &&
affix_1->posPrefixPatternForCurrency ==
affix_1->posPrefixPatternForCurrency ==
affix_2->posPrefixPatternForCurrency &&
affix_1->posSuffixPatternForCurrency ==
affix_1->posSuffixPatternForCurrency ==
affix_2->posSuffixPatternForCurrency &&
affix_1->patternType == affix_2->patternType;
}
@ -233,12 +233,12 @@ inline int32_t _max(int32_t a, int32_t b) { return (a<b) ? b : a; }
//------------------------------------------------------------------------------
// Constructs a DecimalFormat instance in the default locale.
DecimalFormat::DecimalFormat(UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -270,9 +270,9 @@ DecimalFormat::DecimalFormat(UErrorCode& status)
DecimalFormat::DecimalFormat(const UnicodeString& pattern,
UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -306,9 +306,9 @@ DecimalFormat::DecimalFormat(const UnicodeString& pattern,
DecimalFormatSymbols* symbolsToAdopt,
UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -334,15 +334,15 @@ DecimalFormat::DecimalFormat(const UnicodeString& pattern,
status = U_ILLEGAL_ARGUMENT_ERROR;
construct(status, parseError, &pattern, symbolsToAdopt);
}
DecimalFormat::DecimalFormat( const UnicodeString& pattern,
DecimalFormatSymbols* symbolsToAdopt,
UParseError& parseErr,
UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -371,14 +371,14 @@ DecimalFormat::DecimalFormat( const UnicodeString& pattern,
// Constructs a DecimalFormat instance with the specified number format
// pattern and the number format symbols in the default locale. The
// created instance owns the clone of the symbols.
DecimalFormat::DecimalFormat(const UnicodeString& pattern,
const DecimalFormatSymbols& symbols,
UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -407,15 +407,15 @@ DecimalFormat::DecimalFormat(const UnicodeString& pattern,
// Constructs a DecimalFormat instance with the specified number format
// pattern, the number format symbols, and the number format style.
// The created instance owns the clone of the symbols.
DecimalFormat::DecimalFormat(const UnicodeString& pattern,
DecimalFormatSymbols* symbolsToAdopt,
NumberFormat::EStyles style,
UErrorCode& status)
: NumberFormat(),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fPosPrefixPattern(0),
fPosSuffixPattern(0),
fNegPrefixPattern(0),
fNegSuffixPattern(0),
fCurrencyChoice(0),
fMultiplier(0),
@ -518,7 +518,7 @@ DecimalFormat::construct(UErrorCode& status,
}
// the pattern used in format is not fixed until formatting,
// in which, the number is known and
// in which, the number is known and
// will be used to pick the right pattern based on plural count.
// Here, set the pattern as the pattern of plural count == "other".
// For most locale, the patterns are probably the same for all
@ -528,13 +528,13 @@ DecimalFormat::construct(UErrorCode& status,
patternUsed = &currencyPluralPatternForOther;
// TODO: not needed?
setCurrencyForSymbols();
} else {
patternUsed = pattern;
}
if (patternUsed->indexOf(kCurrencySign) != -1) {
// initialize for currency, not only for plural format,
// initialize for currency, not only for plural format,
// but also for mix parsing
if (fCurrencyPluralInfo == NULL) {
fCurrencyPluralInfo = new CurrencyPluralInfo(fSymbols->getLocale(), status);
@ -548,7 +548,7 @@ DecimalFormat::construct(UErrorCode& status,
if (patternUsed->indexOf(fgTripleCurrencySign) != -1) {
setupCurrencyAffixes(*patternUsed, TRUE, TRUE, status);
}
}
}
applyPatternWithoutExpandAffix(*patternUsed,FALSE, parseErr, status);
@ -599,7 +599,7 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
UCURR_SYMBOL_NAME);
fAffixPatternsForCurrency->put("default", affixPtn, status);
}
// save the unique currency plural patterns of this locale.
Hashtable* pluralPtn = fCurrencyPluralInfo->fPluralCountToCurrencyUnitPattern;
const UHashElement* element = NULL;
@ -626,7 +626,7 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
void
DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
UBool setupForCurrentPattern,
UBool setupForPluralPattern,
UErrorCode& status) {
@ -655,7 +655,7 @@ DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
}
}
}
delete keywords;
delete keywords;
}
}
@ -685,7 +685,7 @@ DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
}
}
}
delete keywords;
delete keywords;
}
}
}
@ -770,7 +770,7 @@ DecimalFormat::operator=(const DecimalFormat& rhs)
if(rhs.fRoundingIncrement == NULL) {
delete fRoundingIncrement;
fRoundingIncrement = NULL;
}
}
else if(fRoundingIncrement == NULL) {
fRoundingIncrement = new DigitList(*rhs.fRoundingIncrement);
}
@ -796,7 +796,7 @@ DecimalFormat::operator=(const DecimalFormat& rhs)
fMinExponentDigits = rhs.fMinExponentDigits;
// if (fDigitList == NULL)
// fDigitList = new DigitList();
/* sfb 990629 */
fFormatWidth = rhs.fFormatWidth;
fPad = rhs.fPad;
@ -816,7 +816,7 @@ DecimalFormat::operator=(const DecimalFormat& rhs)
UErrorCode status = U_ZERO_ERROR;
deleteHashForAffixPattern();
fAffixPatternsForCurrency = initHashForAffixPattern(status);
copyHashForAffixPattern(rhs.fAffixPatternsForCurrency,
copyHashForAffixPattern(rhs.fAffixPatternsForCurrency,
fAffixPatternsForCurrency, status);
}
if (rhs.fAffixesForCurrency) {
@ -986,7 +986,7 @@ DecimalFormat::operator==(const Format& that) const
#endif
return (NumberFormat::operator==(that) &&
((fCurrencySignCount == fgCurrencySignCountInPluralFormat) ?
((fCurrencySignCount == fgCurrencySignCountInPluralFormat) ?
(fAffixPatternsForCurrency->equals(*other->fAffixPatternsForCurrency)) :
(((fPosPrefixPattern == other->fPosPrefixPattern && // both null
fPositivePrefix == other->fPositivePrefix)
@ -1036,7 +1036,7 @@ DecimalFormat::clone() const
}
//------------------------------------------------------------------------------
UnicodeString&
DecimalFormat::format(int32_t number,
UnicodeString& appendTo,
@ -1044,18 +1044,18 @@ DecimalFormat::format(int32_t number,
{
return format((int64_t)number, appendTo, fieldPosition);
}
UnicodeString&
DecimalFormat::format(int32_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
return format((int64_t)number, appendTo, posIter, status);
}
//------------------------------------------------------------------------------
UnicodeString&
DecimalFormat::format(int64_t number,
UnicodeString& appendTo,
@ -1068,7 +1068,7 @@ DecimalFormat::format(int64_t number,
UnicodeString&
DecimalFormat::format(int64_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
FieldPositionIteratorHandler handler(posIter, status);
@ -1107,7 +1107,7 @@ DecimalFormat::_format(int64_t number,
return subformat(appendTo, handler, digits, TRUE);
}
//------------------------------------------------------------------------------
UnicodeString&
@ -1122,7 +1122,7 @@ DecimalFormat::format( double number,
UnicodeString&
DecimalFormat::format( double number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
FieldPositionIteratorHandler handler(posIter, status);
@ -1204,7 +1204,7 @@ DecimalFormat::_format( double number,
return subformat(appendTo, handler, digits, FALSE);
}
/**
* Round a double value to the nearest integer according to the
* given mode.
@ -1242,8 +1242,8 @@ double DecimalFormat::round(double a, ERoundingMode mode, UBool isNegative) {
UnicodeString&
DecimalFormat::format(const StringPiece &number,
UnicodeString& toAppendTo,
FieldPositionIterator &fieldPositions,
UnicodeString &toAppendTo,
FieldPositionIterator *posIter,
UErrorCode &status) const
{
// TODO: implement it.
@ -1650,7 +1650,7 @@ void DecimalFormat::addPadding(UnicodeString& appendTo,
}
//------------------------------------------------------------------------------
void
DecimalFormat::parse(const UnicodeString& text,
Formattable& result,
@ -1693,7 +1693,7 @@ void DecimalFormat::parse(const UnicodeString& text,
int32_t i = backup = parsePosition.getIndex();
// Handle NaN as a special case:
// Skip padding characters, if around prefix
if (fFormatWidth > 0 && (fPadPosition == kPadBeforePrefix ||
fPadPosition == kPadAfterPrefix)) {
@ -1713,7 +1713,7 @@ void DecimalFormat::parse(const UnicodeString& text,
result.setDouble(uprv_getNaN());
return;
}
// NaN parse failed; start over
i = backup;
@ -1724,12 +1724,12 @@ void DecimalFormat::parse(const UnicodeString& text,
DigitList digits;
if (fCurrencySignCount > fgCurrencySignCountZero) {
if (!parseForCurrency(text, parsePosition, digits,
if (!parseForCurrency(text, parsePosition, digits,
status, currency)) {
return;
}
} else {
if (!subparse(text,
if (!subparse(text,
fNegPrefixPattern, fNegSuffixPattern,
fPosPrefixPattern, fPosSuffixPattern,
FALSE, UCURR_SYMBOL_NAME,
@ -1814,13 +1814,13 @@ DecimalFormat::parseForCurrency(const UnicodeString& text,
DigitList tmpDigitList;
UBool found;
if (fStyle == NumberFormat::kPluralCurrencyStyle) {
found = subparse(text,
found = subparse(text,
fNegPrefixPattern, fNegSuffixPattern,
fPosPrefixPattern, fPosSuffixPattern,
TRUE, UCURR_LONG_NAME,
tmpPos, tmpDigitList, tmpStatus, currency);
} else {
found = subparse(text,
found = subparse(text,
fNegPrefixPattern, fNegSuffixPattern,
fPosPrefixPattern, fPosSuffixPattern,
TRUE, UCURR_SYMBOL_NAME,
@ -1848,10 +1848,10 @@ DecimalFormat::parseForCurrency(const UnicodeString& text,
UBool tmpStatus[fgStatusLength];
ParsePosition tmpPos(origPos);
DigitList tmpDigitList;
UBool result = subparse(text,
UBool result = subparse(text,
&affixPtn->negPrefixPatternForCurrency,
&affixPtn->negSuffixPatternForCurrency,
&affixPtn->posPrefixPatternForCurrency,
&affixPtn->negSuffixPatternForCurrency,
&affixPtn->posPrefixPatternForCurrency,
&affixPtn->posSuffixPatternForCurrency,
TRUE, affixPtn->patternType,
tmpPos, tmpDigitList, tmpStatus, currency);
@ -1883,11 +1883,11 @@ DecimalFormat::parseForCurrency(const UnicodeString& text,
// set currencySignCount to 0 so that compareAffix function will
// fall to compareSimpleAffix path, not compareComplexAffix path.
// ?? TODO: is it right? need "false"?
UBool result = subparse(text,
UBool result = subparse(text,
&fNegativePrefix, &fNegativeSuffix,
&fPositivePrefix, &fPositiveSuffix,
FALSE, UCURR_SYMBOL_NAME,
tmpPos_2, tmpDigitList_2, tmpStatus_2,
tmpPos_2, tmpDigitList_2, tmpStatus_2,
currency);
if (result) {
if (tmpPos_2.getIndex() > maxPosIndex) {
@ -1942,7 +1942,7 @@ is here if we change our minds.
* currency parsing mode, any currency is parsed, not just the
* currency that this formatter is set to.
*/
UBool DecimalFormat::subparse(const UnicodeString& text,
UBool DecimalFormat::subparse(const UnicodeString& text,
const UnicodeString* negPrefix,
const UnicodeString* negSuffix,
const UnicodeString* posPrefix,
@ -1969,7 +1969,7 @@ UBool DecimalFormat::subparse(const UnicodeString& text,
negMatch = -1;
} else if (negMatch > posMatch) {
posMatch = -1;
}
}
}
if (posMatch >= 0) {
position += posMatch;
@ -2034,7 +2034,7 @@ UBool DecimalFormat::subparse(const UnicodeString& text,
* from 0 to 9 in 'digit'. First try using the locale digit,
* which may or MAY NOT be a standard Unicode digit range. If
* this fails, try using the standard Unicode digit ranges by
* calling Character.digit(). If this also fails, digit will
* calling Character.digit(). If this also fails, digit will
* have a value outside the range 0..9.
*/
digit = ch - zero;
@ -2188,7 +2188,7 @@ UBool DecimalFormat::subparse(const UnicodeString& text,
negMatch = -1;
} else if (negMatch > posMatch) {
posMatch = -1;
}
}
}
// Fail if neither or both
@ -2260,12 +2260,12 @@ int32_t DecimalFormat::compareAffix(const UnicodeString& text,
const UnicodeString *patternToCompare;
if (fCurrencyChoice != NULL || currency != NULL ||
(fCurrencySignCount > fgCurrencySignCountZero && currencyParsing)) {
if (affixPat != NULL) {
return compareComplexAffix(*affixPat, text, pos, type, currency);
}
}
if (isNegative) {
if (isPrefix) {
patternToCompare = &fNegativePrefix;
@ -2407,7 +2407,7 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
(fCurrencyChoice != NULL && *getCurrency() != 0) ||
fCurrencySignCount > fgCurrencySignCountZero);
for (int32_t i=0;
for (int32_t i=0;
i<affixPat.length() && pos >= 0; ) {
UChar32 c = affixPat.char32At(i);
i += U16_LENGTH(c);
@ -2422,7 +2422,7 @@ int32_t DecimalFormat::compareComplexAffix(const UnicodeString& affixPat,
switch (c) {
case kCurrencySign: {
// since the currency names in choice format is saved
// the same way as other currency names,
// the same way as other currency names,
// do not need to do currency choice parsing here.
// the general currency parsing parse against all names,
// including names in choice format.
@ -2571,20 +2571,20 @@ DecimalFormat::setDecimalFormatSymbols(const DecimalFormatSymbols& symbols)
{
adoptDecimalFormatSymbols(new DecimalFormatSymbols(symbols));
}
const CurrencyPluralInfo*
const CurrencyPluralInfo*
DecimalFormat::getCurrencyPluralInfo(void) const
{
return fCurrencyPluralInfo;
}
void
void
DecimalFormat::adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt)
{
if (toAdopt != NULL) {
delete fCurrencyPluralInfo;
delete fCurrencyPluralInfo;
fCurrencyPluralInfo = toAdopt;
// re-set currency affix patterns and currency affixes.
if (fCurrencySignCount > fgCurrencySignCountZero) {
@ -2598,10 +2598,10 @@ DecimalFormat::adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt)
setupCurrencyAffixes(fFormatPattern, FALSE, TRUE, status);
}
}
}
}
}
void
void
DecimalFormat::setCurrencyPluralInfo(const CurrencyPluralInfo& info)
{
adoptCurrencyPluralInfo(info.clone());
@ -2630,7 +2630,7 @@ DecimalFormat::setCurrencyForSymbols() {
UErrorCode ec = U_ZERO_ERROR;
const UChar* c = NULL;
const char* loc = fSymbols->getLocale().getName();
UChar intlCurrencySymbol[4];
UChar intlCurrencySymbol[4];
ucurr_forLocale(loc, intlCurrencySymbol, 4, &ec);
UnicodeString currencySymbol;
@ -2650,17 +2650,17 @@ DecimalFormat::setCurrencyForSymbols() {
//------------------------------------------------------------------------------
// Gets the positive prefix of the number pattern.
UnicodeString&
DecimalFormat::getPositivePrefix(UnicodeString& result) const
{
result = fPositivePrefix;
return result;
}
//------------------------------------------------------------------------------
// Sets the positive prefix of the number pattern.
void
DecimalFormat::setPositivePrefix(const UnicodeString& newValue)
{
@ -2785,7 +2785,7 @@ void DecimalFormat::setRoundingIncrement(double newValue) {
fRoundingDouble = newValue;
return;
}
}
}
// These statements are executed if newValue is less than 0.0
// or fRoundingIncrement could not be created.
delete fRoundingIncrement;
@ -2995,16 +2995,16 @@ void DecimalFormat::setExponentSignAlwaysShown(UBool expSignAlways) {
//------------------------------------------------------------------------------
// Gets the grouping size of the number pattern. For example, thousand or 10
// thousand groupings.
int32_t
DecimalFormat::getGroupingSize() const
{
return fGroupingSize;
}
//------------------------------------------------------------------------------
// Gets the grouping size of the number pattern.
void
DecimalFormat::setGroupingSize(int32_t newValue)
{
@ -3070,9 +3070,9 @@ DecimalFormat::toLocalizedPattern(UnicodeString& result) const
* called any time the symbols or the affix patterns change in order to keep
* the expanded affix strings up to date.
* This method also will be called before formatting if format currency
* plural names, since the plural name is not a static one, it is
* plural names, since the plural name is not a static one, it is
* based on the currency plural count, the affix will be known only
* after the currency plural count is know.
* after the currency plural count is know.
* In which case, the parameter
* 'pluralCount' will be a non-null currency plural count.
* In all other cases, the 'pluralCount' is null, which means it is not needed.
@ -3110,7 +3110,7 @@ void DecimalFormat::expandAffixes(const UnicodeString* pluralCount) {
* after kQuote are recognized: PATTERN_PERCENT, PATTERN_PER_MILLE,
* PATTERN_MINUS, and kCurrencySign. If kCurrencySign is doubled (kQuote +
* kCurrencySign + kCurrencySign), it is interpreted as an international
* currency sign. If CURRENCY_SIGN is tripled, it is interpreted as
* currency sign. If CURRENCY_SIGN is tripled, it is interpreted as
* currency plural long names, such as "US Dollars".
* Any other character after a kQuote represents itself.
* kQuote must be followed by another character; kQuote may not occur by
@ -3185,12 +3185,12 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
// For other cases, pluralCount == null,
// and plural names are not needed.
int32_t len;
// TODO: num of char in plural count
// TODO: num of char in plural count
char pluralCountChar[10];
if (pluralCount->length() >= 10) {
break;
}
pluralCount->extract(0, pluralCount->length(), pluralCountChar);
pluralCount->extract(0, pluralCount->length(), pluralCountChar);
UBool isChoiceFormat;
const UChar* s = ucurr_getPluralName(currencyUChars,
fSymbols != NULL ? fSymbols->getLocale().getName() :
@ -3205,7 +3205,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
int32_t len;
UBool isChoiceFormat;
// If fSymbols is NULL, use default locale
const UChar* s = ucurr_getName(currencyUChars,
const UChar* s = ucurr_getName(currencyUChars,
fSymbols != NULL ? fSymbols->getLocale().getName() : Locale::getDefault().getName(),
UCURR_SYMBOL_NAME, &isChoiceFormat, &len, &ec);
if (isChoiceFormat) {
@ -3306,7 +3306,7 @@ int32_t DecimalFormat::appendAffix(UnicodeString& buf, double number,
FieldPositionHandler& handler,
UBool isNegative, UBool isPrefix) const {
// plural format precedes choice format
if (fCurrencyChoice != 0 &&
if (fCurrencyChoice != 0 &&
fCurrencySignCount != fgCurrencySignCountInPluralFormat) {
const UnicodeString* affixPat;
if (isPrefix) {
@ -3322,7 +3322,7 @@ int32_t DecimalFormat::appendAffix(UnicodeString& buf, double number,
}
// else someone called a function that reset the pattern.
}
const UnicodeString* affix;
if (fCurrencySignCount == fgCurrencySignCountInPluralFormat) {
UnicodeString pluralCount = fCurrencyPluralInfo->getPluralRules()->select(number);
@ -3333,10 +3333,10 @@ int32_t DecimalFormat::appendAffix(UnicodeString& buf, double number,
oneSet = (AffixesForCurrency*)fAffixesForCurrency->get(pluralCount);
}
if (isPrefix) {
affix = isNegative ? &oneSet->negPrefixForCurrency :
affix = isNegative ? &oneSet->negPrefixForCurrency :
&oneSet->posPrefixForCurrency;
} else {
affix = isNegative ? &oneSet->negSuffixForCurrency :
affix = isNegative ? &oneSet->negSuffixForCurrency :
&oneSet->posSuffixForCurrency;
}
} else {
@ -3517,7 +3517,7 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
// so they can not be synthesized,
// instead, get them directly.
// but it might not be the actual pattern used in formatting.
// the actual pattern used in formatting depends on the
// the actual pattern used in formatting depends on the
// formatted number's plural count.
result = fFormatPattern;
return result;
@ -3686,7 +3686,7 @@ DecimalFormat::toPattern(UnicodeString& result, UBool localized) const
// end up with ",###".
if (add>1 && isGroupingPosition(maxDig)) {
result.insert(sub0Start, group);
--add;
--add;
}
}
}
@ -3755,7 +3755,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern, UErrorCode& status)
void
DecimalFormat::applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UParseError& parseError,
UErrorCode& status)
{
applyPattern(pattern, FALSE, parseError, status);
@ -3859,10 +3859,10 @@ DecimalFormat::applyPatternWithoutExpandAffix(const UnicodeString& pattern,
DigitList roundingInc;
int8_t expDigits = -1;
UBool expSignAlways = FALSE;
// The affix is either the prefix or the suffix.
UnicodeString* affix = &prefix;
int32_t start = pos;
UBool isPartDone = FALSE;
UChar32 ch;
@ -4023,7 +4023,7 @@ DecimalFormat::applyPatternWithoutExpandAffix(const UnicodeString& pattern,
if ((pos+1) < pattern.length() && pattern[pos+1] == kCurrencySign) {
affix->append(kCurrencySign);
++pos; // Skip over the doubled character
if ((pos+1) < pattern.length() &&
if ((pos+1) < pattern.length() &&
pattern[pos+1] == kCurrencySign) {
affix->append(kCurrencySign);
++pos; // Skip over the doubled character
@ -4390,7 +4390,7 @@ DecimalFormat::expandAffixAdjustWidth(const UnicodeString* pluralCount) {
expandAffixes(pluralCount);
if (fFormatWidth > 0) {
// Finish computing format width (see above)
// TODO: how to handle fFormatWidth,
// TODO: how to handle fFormatWidth,
// need to save in f(Plural)AffixesForCurrecy?
fFormatWidth += fPositivePrefix.length() + fPositiveSuffix.length();
}
@ -4402,12 +4402,12 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
UBool localized,
UParseError& parseError,
UErrorCode& status)
{
{
// do the following re-set first. since they change private data by
// apply pattern again.
if (pattern.indexOf(kCurrencySign) != -1) {
if (fCurrencyPluralInfo == NULL) {
// initialize currencyPluralInfo if needed
if (fCurrencyPluralInfo == NULL) {
// initialize currencyPluralInfo if needed
fCurrencyPluralInfo = new CurrencyPluralInfo(fSymbols->getLocale(), status);
}
if (fAffixPatternsForCurrency == NULL) {
@ -4424,7 +4424,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
void
DecimalFormat::applyPatternInternally(const UnicodeString& pluralCount,
DecimalFormat::applyPatternInternally(const UnicodeString& pluralCount,
const UnicodeString& pattern,
UBool localized,
UParseError& parseError,
@ -4480,7 +4480,7 @@ int32_t DecimalFormat::getMaximumSignificantDigits() const {
void DecimalFormat::setMinimumSignificantDigits(int32_t min) {
if (min < 1) {
min = 1;
min = 1;
}
// pin max sig dig to >= min
int32_t max = _max(fMaxSignificantDigits, min);
@ -4507,7 +4507,7 @@ void DecimalFormat::setSignificantDigitsUsed(UBool useSignificantDigits) {
fUseSignificantDigits = useSignificantDigits;
}
void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
UErrorCode& ec) {
// If we are a currency format, then modify our affixes to
// encode the currency symbol for the given currency in our
@ -4516,7 +4516,7 @@ void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
// Note: The code is ordered so that this object is *not changed*
// until we are sure we are going to succeed.
// NULL or empty currency is *legal* and indicates no currency.
UBool isCurr = (theCurrency && *theCurrency);
@ -4526,7 +4526,7 @@ void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
rounding = ucurr_getRoundingIncrement(theCurrency, &ec);
frac = ucurr_getDefaultFractionDigits(theCurrency, &ec);
}
NumberFormat::setCurrency(theCurrency, ec);
if (U_FAILURE(ec)) return;
@ -4623,7 +4623,7 @@ DecimalFormat::initHashForAffixPattern(UErrorCode& status) {
}
void
DecimalFormat::deleteHashForAffix(Hashtable*& table)
DecimalFormat::deleteHashForAffix(Hashtable*& table)
{
if ( table == NULL ) {
return;
@ -4643,7 +4643,7 @@ DecimalFormat::deleteHashForAffix(Hashtable*& table)
void
DecimalFormat::deleteHashForAffixPattern()
DecimalFormat::deleteHashForAffixPattern()
{
if ( fAffixPatternsForCurrency == NULL ) {
return;

View file

@ -67,23 +67,26 @@ FieldPositionOnlyHandler::isRecording(void) {
// utility subclass FieldPositionIteratorHandler
FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator& posIter,
FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator* posIter,
UErrorCode& _status)
: iter(posIter), vec(NULL), status(_status) {
if (U_SUCCESS(status)) {
if (iter && U_SUCCESS(status)) {
vec = new UVector32(status);
}
}
FieldPositionIteratorHandler::~FieldPositionIteratorHandler() {
// setData adopts the vec regardless of status, so it's safe to null it
iter.setData(vec, status);
if (iter) {
iter->setData(vec, status);
}
// if iter is null, we never allocated vec, so no need to free it
vec = NULL;
}
void
FieldPositionIteratorHandler::addAttribute(int32_t id, int32_t start, int32_t limit) {
if (U_SUCCESS(status) && start < limit) {
if (iter && U_SUCCESS(status) && start < limit) {
int32_t size = vec->size();
vec->addElement(id, status);
vec->addElement(start, status);
@ -115,4 +118,3 @@ FieldPositionIteratorHandler::isRecording(void) {
U_NAMESPACE_END
#endif /* !UCONFIG_NO_FORMATTING */

View file

@ -45,7 +45,7 @@ class FieldPositionOnlyHandler : public FieldPositionHandler {
// utility subclass FieldPositionIteratorHandler
class FieldPositionIteratorHandler : public FieldPositionHandler {
FieldPositionIterator& iter;
FieldPositionIterator* iter; // can be NULL
UVector32* vec;
UErrorCode status;
@ -57,7 +57,7 @@ class FieldPositionIteratorHandler : public FieldPositionHandler {
void *operator new[](size_t s);
public:
FieldPositionIteratorHandler(FieldPositionIterator& posIter, UErrorCode& status);
FieldPositionIteratorHandler(FieldPositionIterator* posIter, UErrorCode& status);
~FieldPositionIteratorHandler();
virtual void addAttribute(int32_t id, int32_t start, int32_t limit);

View file

@ -103,8 +103,8 @@ static const UChar * const gLastResortNumberPatterns[] =
gLastResortPluralCurrencyPat,
};
// Static hashtable cache of NumberingSystem objects used by NumberFormat
static UHashtable * NumberingSystem_cache = NULL;
// Static hashtable cache of NumberingSystem objects used by NumberFormat
static UHashtable * NumberingSystem_cache = NULL;
static UMTX nscacheMutex = NULL;
@ -112,10 +112,10 @@ static UMTX nscacheMutex = NULL;
static U_NAMESPACE_QUALIFIER ICULocaleService* gService = NULL;
#endif
/**
* Release all static memory held by Number Format.
*/
U_CDECL_BEGIN
/**
* Release all static memory held by Number Format.
*/
U_CDECL_BEGIN
static void U_CALLCONV
deleteNumberingSystem(void *obj) {
delete (U_NAMESPACE_QUALIFIER NumberingSystem *)obj;
@ -128,14 +128,14 @@ static UBool U_CALLCONV numfmt_cleanup(void) {
gService = NULL;
}
#endif
if (NumberingSystem_cache) {
// delete NumberingSystem_cache;
uhash_close(NumberingSystem_cache);
NumberingSystem_cache = NULL;
if (NumberingSystem_cache) {
// delete NumberingSystem_cache;
uhash_close(NumberingSystem_cache);
NumberingSystem_cache = NULL;
}
return TRUE;
}
return TRUE;
}
U_CDECL_END
// *****************************************************************************
@ -163,7 +163,7 @@ UBool SimpleNumberFormatFactory::visible(void) const {
}
const UnicodeString *
SimpleNumberFormatFactory::getSupportedIDs(int32_t &count, UErrorCode& status) const
SimpleNumberFormatFactory::getSupportedIDs(int32_t &count, UErrorCode& status) const
{
if (U_SUCCESS(status)) {
count = 1;
@ -259,7 +259,7 @@ NumberFormat::operator==(const Format& that) const
if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
debug("fCurrency !=");
}
if (!first) { printf(" ]"); }
if (!first) { printf(" ]"); }
#endif
return ((this == &that) ||
@ -280,7 +280,7 @@ NumberFormat::operator==(const Format& that) const
UnicodeString&
NumberFormat::format(double /* unused number */,
UnicodeString& toAppendTo,
FieldPositionIterator& /* unused posIter */,
FieldPositionIterator* /* unused posIter */,
UErrorCode& status) const
{
if (!U_FAILURE(status)) {
@ -296,7 +296,7 @@ NumberFormat::format(double /* unused number */,
UnicodeString&
NumberFormat::format(int32_t /* unused number */,
UnicodeString& toAppendTo,
FieldPositionIterator& /* unused posIter */,
FieldPositionIterator* /* unused posIter */,
UErrorCode& status) const
{
if (!U_FAILURE(status)) {
@ -312,7 +312,7 @@ NumberFormat::format(int32_t /* unused number */,
UnicodeString&
NumberFormat::format(int64_t /* unused number */,
UnicodeString& toAppendTo,
FieldPositionIterator& /* unused posIter */,
FieldPositionIterator* /* unused posIter */,
UErrorCode& status) const
{
if (!U_FAILURE(status)) {
@ -328,7 +328,7 @@ NumberFormat::format(int64_t /* unused number */,
UnicodeString&
NumberFormat::format(const StringPiece & /* unused decimal number */,
UnicodeString& toAppendTo,
FieldPositionIterator& /* unused posIter */,
FieldPositionIterator* /* unused posIter */,
UErrorCode& status) const
{
if (!U_FAILURE(status)) {
@ -341,7 +341,7 @@ NumberFormat::format(const StringPiece & /* unused decimal number */,
// Formats the number object and save the format
// result in the toAppendTo string buffer.
// utility to save/restore state, used in two overloads
// utility to save/restore state, used in two overloads
// of format(const Formattable&...) below.
class ArgExtractor {
@ -362,7 +362,7 @@ ArgExtractor::number(void) const {
return num;
}
ArgExtractor::ArgExtractor(const NumberFormat& nf, const Formattable& obj, UErrorCode& status)
ArgExtractor::ArgExtractor(const NumberFormat& nf, const Formattable& obj, UErrorCode& status)
: ncnf((NumberFormat*) &nf), num(&obj), setCurr(FALSE) {
const UObject* o = obj.getObject(); // most commonly o==NULL
@ -424,7 +424,7 @@ NumberFormat::format(const Formattable& obj,
UnicodeString&
NumberFormat::format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
if (U_FAILURE(status)) return appendTo;
@ -452,7 +452,7 @@ NumberFormat::format(const Formattable& obj,
// -------------------------------------
UnicodeString&
UnicodeString&
NumberFormat::format(int64_t number,
UnicodeString& appendTo,
FieldPosition& pos) const
@ -587,7 +587,7 @@ NumberFormat::createCurrencyInstance(UErrorCode& status)
NumberFormat* U_EXPORT2
NumberFormat::createCurrencyInstance(const Locale& inLocale, UErrorCode& status)
{
{
return createInstance(inLocale, kCurrencyStyle, status);
}
@ -661,7 +661,7 @@ private:
Hashtable* _ids;
public:
NFFactory(NumberFormatFactory* delegate)
NFFactory(NumberFormatFactory* delegate)
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
, _delegate(delegate)
, _ids(NULL)
@ -693,7 +693,7 @@ public:
protected:
/**
* Return the set of ids that this factory supports (visible or
* Return the set of ids that this factory supports (visible or
* otherwise). This can be called often and might need to be
* cached if it is expensive to create.
*/
@ -744,7 +744,7 @@ public:
// -------------------------------------
static ICULocaleService*
static ICULocaleService*
getNumberFormatService(void)
{
UBool needInit;
@ -1002,7 +1002,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
case kCurrencyStyle:
case kIsoCurrencyStyle: // do not support plural formatting here
case kPluralCurrencyStyle:
case kPluralCurrencyStyle:
f = new Win32NumberFormat(desiredLocale, curr, status);
if (U_SUCCESS(status)) {
@ -1011,7 +1011,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
delete f;
break;
default:
break;
}
@ -1025,8 +1025,8 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
UResourceBundle *numberPatterns = ures_getByKey(resource, DecimalFormat::fgNumberPatterns, NULL, &status);
NumberingSystem *ns = NULL;
UBool deleteSymbols = TRUE;
UHashtable * cache = NULL;
int32_t hashKey;
UHashtable * cache = NULL;
int32_t hashKey;
UBool getCache = FALSE;
UBool deleteNS = FALSE;
@ -1042,7 +1042,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
else {
// If not all the styled patterns exists for the NumberFormat in this locale,
// sets the status code to failure and returns nil.
if (ures_getSize(numberPatterns) < (int32_t)(sizeof(gLastResortNumberPatterns)/sizeof(gLastResortNumberPatterns[0])) -2 ) { //minus 2: ISO and plural
if (ures_getSize(numberPatterns) < (int32_t)(sizeof(gLastResortNumberPatterns)/sizeof(gLastResortNumberPatterns[0])) -2 ) { //minus 2: ISO and plural
status = U_INVALID_FORMAT_ERROR;
goto cleanup;
}
@ -1051,18 +1051,18 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
symbolsToAdopt = new DecimalFormatSymbols(desiredLocale, status);
int32_t patLen = 0;
/* for ISOCURRENCYSTYLE and PLURALCURRENCYSTYLE,
* the pattern is the same as the pattern of CURRENCYSTYLE
* but by replacing the single currency sign with
* double currency sign or triple currency sign.
*/
int styleInNumberPattern = ((style == kIsoCurrencyStyle ||
int styleInNumberPattern = ((style == kIsoCurrencyStyle ||
style == kPluralCurrencyStyle) ?
kCurrencyStyle : style);
const UChar *patResStr = ures_getStringByIndex(numberPatterns, (int32_t)styleInNumberPattern, &patLen, &status);
// Creates the specified decimal format style of the desired locale.
pattern.setTo(TRUE, patResStr, patLen);
}
@ -1075,74 +1075,74 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
pattern.setTo(currPattern, u_strlen(currPattern));
}
}
// Use numbering system cache hashtable
// Use numbering system cache hashtable
UMTX_CHECK(&nscacheMutex, (UBool)(cache != NumberingSystem_cache), getCache);
if (getCache) {
umtx_lock(&nscacheMutex);
cache = NumberingSystem_cache;
umtx_unlock(&nscacheMutex);
umtx_lock(&nscacheMutex);
cache = NumberingSystem_cache;
umtx_unlock(&nscacheMutex);
}
// Check cache we got, create if non-existant
status = U_ZERO_ERROR;
if (cache == NULL) {
cache = uhash_open(uhash_hashLong,
uhash_compareLong,
NULL,
&status);
if (cache == NULL || U_FAILURE(status)) {
// cache not created - out of memory
cache = NULL;
}
else {
// cache created
// Check cache we got, create if non-existant
status = U_ZERO_ERROR;
if (cache == NULL) {
cache = uhash_open(uhash_hashLong,
uhash_compareLong,
NULL,
&status);
if (cache == NULL || U_FAILURE(status)) {
// cache not created - out of memory
cache = NULL;
}
else {
// cache created
uhash_setValueDeleter(cache, deleteNumberingSystem);
// set final NumberingSystem_cache value
UHashtable* h = NULL;
// set final NumberingSystem_cache value
UHashtable* h = NULL;
UMTX_CHECK(&nscacheMutex, (UBool)(h != NumberingSystem_cache), getCache);
if (getCache) {
umtx_lock(&nscacheMutex);
h = NumberingSystem_cache;
umtx_lock(&nscacheMutex);
h = NumberingSystem_cache;
umtx_unlock(&nscacheMutex);
}
if (h == NULL) {
if (h == NULL) {
umtx_lock(&nscacheMutex);
NumberingSystem_cache = h = cache;
cache = NULL;
NumberingSystem_cache = h = cache;
cache = NULL;
ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup);
umtx_unlock(&nscacheMutex);
}
if(cache != NULL) {
uhash_close(cache);
}
cache = h;
}
}
// Get cached numbering system
if (cache != NULL) {
hashKey = desiredLocale.hashCode();
umtx_lock(&nscacheMutex);
ns = (NumberingSystem *)uhash_iget(cache, hashKey);
if (ns == NULL) {
ns = NumberingSystem::createInstance(desiredLocale,status);
uhash_iput(cache, hashKey, (void*)ns, &status);
}
if(cache != NULL) {
uhash_close(cache);
}
cache = h;
}
}
// Get cached numbering system
if (cache != NULL) {
hashKey = desiredLocale.hashCode();
umtx_lock(&nscacheMutex);
ns = (NumberingSystem *)uhash_iget(cache, hashKey);
if (ns == NULL) {
ns = NumberingSystem::createInstance(desiredLocale,status);
uhash_iput(cache, hashKey, (void*)ns, &status);
}
umtx_unlock(&nscacheMutex);
}
else {
}
else {
ns = NumberingSystem::createInstance(desiredLocale,status);
deleteNS = TRUE;
}
// check results of getting a numbering system
if ((ns == NULL) || (U_FAILURE(status))) {
}
// check results of getting a numbering system
if ((ns == NULL) || (U_FAILURE(status))) {
goto cleanup;
}
@ -1152,7 +1152,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
UnicodeString nsRuleSetName;
Locale nsLoc;
URBNFRuleSetTag desiredRulesType = URBNF_NUMBERING_SYSTEM;
nsDesc.setTo(ns->getDescription());
int32_t firstSlash = nsDesc.indexOf(gSlash);
int32_t lastSlash = nsDesc.lastIndexOf(gSlash);
@ -1162,7 +1162,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
nsDesc.extract(0,firstSlash,nsLocID,ULOC_FULLNAME_CAPACITY,US_INV);
nsRuleSetGroup.setTo(nsDesc,firstSlash+1,lastSlash-firstSlash-1);
nsRuleSetName.setTo(nsDesc,lastSlash+1);
nsLoc = Locale::createFromName(nsLocID);
UnicodeString SpelloutRules = UNICODE_STRING_SIMPLE("SpelloutRules");
@ -1206,7 +1206,7 @@ cleanup:
if (deleteNS && ns) {
delete ns;
}
if (U_FAILURE(status)) {
/* If f exists, then it will delete the symbols */
if (f==NULL) {

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2009, International Business Machines Corporation and *
* Copyright (C) 1997-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
@ -124,7 +124,7 @@ static const int8_t kDateFieldsCount = 13;
static const UDateFormatField kTimeFields[] = {
UDAT_HOUR_OF_DAY1_FIELD,
UDAT_HOUR_OF_DAY1_FIELD,
UDAT_HOUR_OF_DAY1_FIELD,
UDAT_MINUTE_FIELD,
UDAT_SECOND_FIELD,
UDAT_FRACTIONAL_SECOND_FIELD,
@ -500,7 +500,7 @@ void SimpleDateFormat::construct(EStyle timeStyle,
// use Formattable::adoptString() so that we can use fastCopyFrom()
// instead of Formattable::setString()'s unaware, safe, deep string clone
// see Jitterbug 2296
currentBundle = ures_getByIndex(dateTimePatterns, (int32_t)timeStyle, NULL, &status);
if (U_FAILURE(status)) {
status = U_INVALID_FORMAT_ERROR;
@ -522,9 +522,9 @@ void SimpleDateFormat::construct(EStyle timeStyle,
ures_close(currentBundle);
return;
}
}
}
ures_close(currentBundle);
UnicodeString *tempus1 = new UnicodeString(TRUE, resStr, resStrLen);
// NULL pointer check
if (tempus1 == NULL) {
@ -532,7 +532,7 @@ void SimpleDateFormat::construct(EStyle timeStyle,
return;
}
timeDateArray[0].adoptString(tempus1);
currentBundle = ures_getByIndex(dateTimePatterns, (int32_t)dateStyle, NULL, &status);
if (U_FAILURE(status)) {
status = U_INVALID_FORMAT_ERROR;
@ -541,20 +541,20 @@ void SimpleDateFormat::construct(EStyle timeStyle,
switch (ures_getType(currentBundle)) {
case URES_STRING: {
resStr = ures_getString(currentBundle, &resStrLen, &status);
break;
break;
}
case URES_ARRAY: {
resStr = ures_getStringByIndex(currentBundle, 0, &resStrLen, &status);
ovrStr = ures_getStringByIndex(currentBundle, 1, &ovrStrLen, &status);
fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
break;
break;
}
default: {
status = U_INVALID_FORMAT_ERROR;
ures_close(currentBundle);
return;
}
}
}
ures_close(currentBundle);
UnicodeString *tempus2 = new UnicodeString(TRUE, resStr, resStrLen);
@ -587,20 +587,20 @@ void SimpleDateFormat::construct(EStyle timeStyle,
switch (ures_getType(currentBundle)) {
case URES_STRING: {
resStr = ures_getString(currentBundle, &resStrLen, &status);
break;
break;
}
case URES_ARRAY: {
resStr = ures_getStringByIndex(currentBundle, 0, &resStrLen, &status);
ovrStr = ures_getStringByIndex(currentBundle, 1, &ovrStrLen, &status);
fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
break;
break;
}
default: {
status = U_INVALID_FORMAT_ERROR;
ures_close(currentBundle);
return;
}
}
}
fPattern.setTo(TRUE, resStr, resStrLen);
ures_close(currentBundle);
}
@ -613,24 +613,24 @@ void SimpleDateFormat::construct(EStyle timeStyle,
switch (ures_getType(currentBundle)) {
case URES_STRING: {
resStr = ures_getString(currentBundle, &resStrLen, &status);
break;
break;
}
case URES_ARRAY: {
resStr = ures_getStringByIndex(currentBundle, 0, &resStrLen, &status);
ovrStr = ures_getStringByIndex(currentBundle, 1, &ovrStrLen, &status);
fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
break;
break;
}
default: {
status = U_INVALID_FORMAT_ERROR;
ures_close(currentBundle);
return;
}
}
}
fPattern.setTo(TRUE, resStr, resStrLen);
ures_close(currentBundle);
}
// and if it includes _neither_, that's an error
else
status = U_INVALID_FORMAT_ERROR;
@ -691,7 +691,7 @@ SimpleDateFormat::initialize(const Locale& locale,
fNumberFormat->setMinimumFractionDigits(0); // To prevent "Jan 1.00, 1997.00"
initNumberFormatters(locale,status);
}
else if (U_SUCCESS(status))
{
@ -702,7 +702,7 @@ SimpleDateFormat::initialize(const Locale& locale,
/* Initialize the fields we use to disambiguate ambiguous years. Separate
* so we can call it from readObject().
*/
void SimpleDateFormat::initializeDefaultCentury()
void SimpleDateFormat::initializeDefaultCentury()
{
if(fCalendar) {
fHaveDefaultCentury = fCalendar->haveDefaultCentury();
@ -719,7 +719,7 @@ void SimpleDateFormat::initializeDefaultCentury()
/* Define one-century window into which to disambiguate dates using
* two-digit years. Make public in JDK 1.2.
*/
void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status)
void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status)
{
if(U_FAILURE(status)) {
return;
@ -728,7 +728,7 @@ void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& s
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
fCalendar->setTime(startDate, status);
if(U_SUCCESS(status)) {
fHaveDefaultCentury = TRUE;
@ -736,7 +736,7 @@ void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& s
fDefaultCenturyStartYear = fCalendar->get(UCAL_YEAR, status);
}
}
//----------------------------------------------------------------------
UnicodeString&
@ -750,8 +750,8 @@ SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo, FieldPosition&
//----------------------------------------------------------------------
UnicodeString&
SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo,
FieldPositionIterator& posIter, UErrorCode& status) const
SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo,
FieldPositionIterator* posIter, UErrorCode& status) const
{
FieldPositionIteratorHandler handler(posIter, status);
return _format(cal, appendTo, handler, status);
@ -779,11 +779,11 @@ SimpleDateFormat::_format(Calendar& cal, UnicodeString& appendTo, FieldPositionH
UBool inQuote = FALSE;
UChar prevCh = 0;
int32_t count = 0;
// loop through the pattern string character by character
for (int32_t i = 0; i < fPattern.length() && U_SUCCESS(status); ++i) {
UChar ch = fPattern[i];
// Use subFormat() to format a repeated pattern character
// when a different pattern or non-pattern character is seen
if (ch != prevCh && count > 0) {
@ -799,8 +799,8 @@ SimpleDateFormat::_format(Calendar& cal, UnicodeString& appendTo, FieldPositionH
} else {
inQuote = ! inQuote;
}
}
else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
}
else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
|| (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) {
// ch is a date-time pattern character to be interpreted
// by subFormat(); count the number of times it is repeated
@ -841,10 +841,10 @@ SimpleDateFormat::fgCalendarFieldToLevel[] =
/*wW*/ 20, 30,
/*dDEF*/ 30, 20, 30, 30,
/*ahHm*/ 40, 50, 50, 60,
/*sS..*/ 70, 80,
/*z?Y*/ 0, 0, 10,
/*sS..*/ 70, 80,
/*z?Y*/ 0, 0, 10,
/*eug*/ 30, 10, 0,
/*A*/ 40
/*A*/ 40
};
@ -1299,7 +1299,7 @@ SimpleDateFormat::initNumberFormatters(const Locale &locale,UErrorCode &status)
}
}
umtx_unlock(&LOCK);
processOverrideString(locale,fDateOverride,kOvrStrDate,status);
processOverrideString(locale,fTimeOverride,kOvrStrTime,status);
@ -1386,7 +1386,7 @@ SimpleDateFormat::processOverrideString(const Locale &locale, const UnicodeStrin
return;
}
}
// Now that we have an appropriate number formatter, fill in the appropriate spaces in the
// number formatters table.
@ -1426,7 +1426,7 @@ SimpleDateFormat::processOverrideString(const Locale &locale, const UnicodeStrin
start = delimiterPosition + 1;
}
}
}
//---------------------------------------------------------------------
void
SimpleDateFormat::subFormat(UnicodeString &appendTo,
@ -1467,7 +1467,7 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
currentNumberFormat = getNumberFormat(patternCharIndex);
switch (patternCharIndex) {
// for any "G" symbol, write out the appropriate era string
// "GGGG" is wide era name, "GGGGG" is narrow era name, anything else is abbreviated name
case UDAT_ERA_FIELD:
@ -1491,9 +1491,9 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
case UDAT_YEAR_WOY_FIELD:
if(count == 2)
zeroPaddingNumber(currentNumberFormat, appendTo, value, 2, 2);
else
else
zeroPaddingNumber(currentNumberFormat, appendTo, value, count, maxIntCount);
break;
break;
// for "MMMM", write out the whole month name, for "MMM", write out the month
// abbreviation, for "M" or "MM", write out the month as a number with the
@ -1503,20 +1503,20 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
if ( isHebrewCalendar ) {
HebrewCalendar *hc = (HebrewCalendar*)&cal;
if (hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value == 6 && count >= 3 )
value = 13; // Show alternate form for Adar II in leap years in Hebrew calendar.
value = 13; // Show alternate form for Adar II in leap years in Hebrew calendar.
if (!hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value >= 6 && count < 3 )
value--; // Adjust the month number down 1 in Hebrew non-leap years, i.e. Adar is 6, not 7.
}
if (count == 5)
if (count == 5)
_appendSymbol(appendTo, value, fSymbols->fNarrowMonths,
fSymbols->fNarrowMonthsCount);
else if (count == 4)
else if (count == 4)
_appendSymbol(appendTo, value, fSymbols->fMonths,
fSymbols->fMonthsCount);
else if (count == 3)
else if (count == 3)
_appendSymbol(appendTo, value, fSymbols->fShortMonths,
fSymbols->fShortMonthsCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, value + 1, count, maxIntCount);
break;
@ -1525,24 +1525,24 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
// appropriate number of digits
// for "LLLLL", use the narrow form
case UDAT_STANDALONE_MONTH_FIELD:
if (count == 5)
if (count == 5)
_appendSymbol(appendTo, value, fSymbols->fStandaloneNarrowMonths,
fSymbols->fStandaloneNarrowMonthsCount);
else if (count == 4)
else if (count == 4)
_appendSymbol(appendTo, value, fSymbols->fStandaloneMonths,
fSymbols->fStandaloneMonthsCount);
else if (count == 3)
else if (count == 3)
_appendSymbol(appendTo, value, fSymbols->fStandaloneShortMonths,
fSymbols->fStandaloneShortMonthsCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, value + 1, count, maxIntCount);
break;
// for "k" and "kk", write out the hour, adjusting midnight to appear as "24"
case UDAT_HOUR_OF_DAY1_FIELD:
if (value == 0)
if (value == 0)
zeroPaddingNumber(currentNumberFormat,appendTo, cal.getMaximum(UCAL_HOUR_OF_DAY) + 1, count, maxIntCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
break;
@ -1582,10 +1582,10 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
}
// fall through, do not break here
case UDAT_DAY_OF_WEEK_FIELD:
if (count == 5)
if (count == 5)
_appendSymbol(appendTo, value, fSymbols->fNarrowWeekdays,
fSymbols->fNarrowWeekdaysCount);
else if (count == 4)
else if (count == 4)
_appendSymbol(appendTo, value, fSymbols->fWeekdays,
fSymbols->fWeekdaysCount);
else
@ -1607,10 +1607,10 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
if (U_FAILURE(status)) {
return;
}
if (count == 5)
if (count == 5)
_appendSymbol(appendTo, value, fSymbols->fStandaloneNarrowWeekdays,
fSymbols->fStandaloneNarrowWeekdaysCount);
else if (count == 4)
else if (count == 4)
_appendSymbol(appendTo, value, fSymbols->fStandaloneWeekdays,
fSymbols->fStandaloneWeekdaysCount);
else // count == 3
@ -1627,9 +1627,9 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
// for "h" and "hh", write out the hour, adjusting noon and midnight to show up
// as "12"
case UDAT_HOUR1_FIELD:
if (value == 0)
if (value == 0)
zeroPaddingNumber(currentNumberFormat,appendTo, cal.getLeastMaximum(UCAL_HOUR) + 1, count, maxIntCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
break;
@ -1639,9 +1639,9 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
// If we don't have a localized time zone name,
// then the time zone shows up as "GMT+hh:mm" or "GMT-hh:mm" (where "hh:mm" is the
// offset from GMT) regardless of how many z's were in the pattern symbol
case UDAT_TIMEZONE_FIELD:
case UDAT_TIMEZONE_FIELD:
case UDAT_TIMEZONE_GENERIC_FIELD:
case UDAT_TIMEZONE_SPECIAL_FIELD:
case UDAT_TIMEZONE_SPECIAL_FIELD:
{
UnicodeString zoneString;
const ZoneStringFormat *zsf = fSymbols->getZoneStringFormat();
@ -1695,24 +1695,24 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
break;
case UDAT_QUARTER_FIELD:
if (count >= 4)
if (count >= 4)
_appendSymbol(appendTo, value/3, fSymbols->fQuarters,
fSymbols->fQuartersCount);
else if (count == 3)
else if (count == 3)
_appendSymbol(appendTo, value/3, fSymbols->fShortQuarters,
fSymbols->fShortQuartersCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, (value/3) + 1, count, maxIntCount);
break;
case UDAT_STANDALONE_QUARTER_FIELD:
if (count >= 4)
if (count >= 4)
_appendSymbol(appendTo, value/3, fSymbols->fStandaloneQuarters,
fSymbols->fStandaloneQuartersCount);
else if (count == 3)
else if (count == 3)
_appendSymbol(appendTo, value/3, fSymbols->fStandaloneShortQuarters,
fSymbols->fStandaloneShortQuartersCount);
else
else
zeroPaddingNumber(currentNumberFormat,appendTo, (value/3) + 1, count, maxIntCount);
break;
@ -1740,7 +1740,7 @@ SimpleDateFormat::getNumberFormat(UDateFormatField index) const {
//----------------------------------------------------------------------
void
SimpleDateFormat::zeroPaddingNumber(NumberFormat *currentNumberFormat,UnicodeString &appendTo,
SimpleDateFormat::zeroPaddingNumber(NumberFormat *currentNumberFormat,UnicodeString &appendTo,
int32_t value, int32_t minDigits, int32_t maxDigits) const
{
if (currentNumberFormat!=NULL) {
@ -1911,7 +1911,7 @@ SimpleDateFormat::parse(const UnicodeString& text, Calendar& cal, ParsePosition&
// quoted characters and non-alphabetic unquoted
// characters.
else {
abutPat = -1; // End of any abutting fields
// Handle quotes. Two consecutive quotes is a quote
@ -2137,7 +2137,7 @@ ExitParse:
// If any Calendar calls failed, we pretend that we
// couldn't parse the string, when in reality this isn't quite accurate--
// we did parse it; the Calendar calls just failed.
if (U_FAILURE(status)) {
if (U_FAILURE(status)) {
parsePos.setErrorIndex(pos);
parsePos.setIndex(start);
}
@ -2193,7 +2193,7 @@ int32_t SimpleDateFormat::matchQuarterString(const UnicodeString& text,
lcase.fastCopyFrom(data[i]).foldCase();
int32_t length = lcase.length();
if (length > bestMatchLength &&
lcaseText.compareBetween(0, length, lcase, 0, length) == 0)
{
@ -2232,7 +2232,7 @@ int32_t SimpleDateFormat::matchQuarterString(const UnicodeString& text,
}
}
}
return -start;
}
@ -2273,7 +2273,7 @@ int32_t SimpleDateFormat::matchString(const UnicodeString& text,
lcase.fastCopyFrom(data[i]).foldCase();
int32_t length = lcase.length();
if (length > bestMatchLength &&
lcaseText.compareBetween(0, length, lcase, 0, length) == 0)
{
@ -2318,7 +2318,7 @@ int32_t SimpleDateFormat::matchString(const UnicodeString& text,
}
}
}
return -start;
}
@ -2471,7 +2471,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
}
cal.set(UCAL_YEAR, value);
// Delayed checking for adjustment of Hebrew month numbers in non-leap years.
// Delayed checking for adjustment of Hebrew month numbers in non-leap years.
if (saveHebrewMonth >= 0) {
HebrewCalendar *hc = (HebrewCalendar*)&cal;
if (!hc->isLeapYear(value) && saveHebrewMonth >= 6) {
@ -2515,7 +2515,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
}
} else {
saveHebrewMonth = value;
}
}
} else {
// Don't want to parse the month if it is a string
// while pattern uses numeric style: M or MM.
@ -2561,7 +2561,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
case UDAT_HOUR_OF_DAY1_FIELD:
// [We computed 'value' above.]
if (value == cal.getMaximum(UCAL_HOUR_OF_DAY) + 1)
if (value == cal.getMaximum(UCAL_HOUR_OF_DAY) + 1)
value = 0;
cal.set(UCAL_HOUR_OF_DAY, value);
return pos.getIndex();
@ -2636,7 +2636,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
case UDAT_HOUR1_FIELD:
// [We computed 'value' above.]
if (value == cal.getLeastMaximum(UCAL_HOUR)+1)
if (value == cal.getLeastMaximum(UCAL_HOUR)+1)
value = 0;
cal.set(UCAL_HOUR, value);
return pos.getIndex();
@ -2768,7 +2768,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
if (parsed) {
// offset was successfully parsed as either a long GMT string or RFC822 zone offset
// string. Create normalized zone ID for the offset.
UnicodeString tzID(gGmt);
formatRFC822TZ(tzID, offset);
//TimeZone *customTZ = TimeZone::createTimeZone(tzID);
@ -2941,21 +2941,21 @@ void SimpleDateFormat::translatePattern(const UnicodeString& originalPattern,
// an error if a particular "pattern character" doesn't appear in "from".
// Depending on the values of "from" and "to" this can convert from generic
// to localized patterns or localized to generic.
if (U_FAILURE(status))
if (U_FAILURE(status))
return;
translatedPattern.remove();
UBool inQuote = FALSE;
for (int32_t i = 0; i < originalPattern.length(); ++i) {
UChar c = originalPattern[i];
if (inQuote) {
if (c == QUOTE)
if (c == QUOTE)
inQuote = FALSE;
}
else {
if (c == QUOTE)
if (c == QUOTE)
inQuote = TRUE;
else if ((c >= 0x0061 /*'a'*/ && c <= 0x007A) /*'z'*/
else if ((c >= 0x0061 /*'a'*/ && c <= 0x007A) /*'z'*/
|| (c >= 0x0041 /*'A'*/ && c <= 0x005A /*'Z'*/)) {
int32_t ci = from.indexOf(c);
if (ci == -1) {
@ -3042,7 +3042,7 @@ void SimpleDateFormat::adoptCalendar(Calendar* calendarToAdopt)
{
UErrorCode status = U_ZERO_ERROR;
DateFormat::adoptCalendar(calendarToAdopt);
delete fSymbols;
delete fSymbols;
fSymbols=NULL;
initializeSymbols(fLocale, fCalendar, status); // we need new symbols
initializeDefaultCentury(); // we need a new century (possibly)
@ -3059,7 +3059,7 @@ SimpleDateFormat::isFieldUnitIgnored(UCalendarDateFields field) const {
UBool
SimpleDateFormat::isFieldUnitIgnored(const UnicodeString& pattern,
SimpleDateFormat::isFieldUnitIgnored(const UnicodeString& pattern,
UCalendarDateFields field) {
int32_t fieldLevel = fgCalendarFieldToLevel[field];
int32_t level;
@ -3084,8 +3084,8 @@ SimpleDateFormat::isFieldUnitIgnored(const UnicodeString& pattern,
} else {
inQuote = ! inQuote;
}
}
else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
}
else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
|| (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) {
prevCh = ch;
++count;
@ -3110,7 +3110,7 @@ SimpleDateFormat::getSmpFmtLocale(void) const {
//----------------------------------------------------------------------
int32_t
int32_t
SimpleDateFormat::checkIntSuffix(const UnicodeString& text, int32_t start,
int32_t patLoc, UBool isNegative) const {
// local variables
@ -3129,7 +3129,7 @@ SimpleDateFormat::checkIntSuffix(const UnicodeString& text, int32_t start,
}
// get the suffix
if (fNumberFormat->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
if (fNumberFormat->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
if (isNegative) {
suf = ((DecimalFormat*)fNumberFormat)->getNegativeSuffix(suf);
}
@ -3137,7 +3137,7 @@ SimpleDateFormat::checkIntSuffix(const UnicodeString& text, int32_t start,
suf = ((DecimalFormat*)fNumberFormat)->getPositiveSuffix(suf);
}
}
// check for suffix
if (suf.length() <= 0) {
return start;
@ -3167,8 +3167,8 @@ SimpleDateFormat::checkIntSuffix(const UnicodeString& text, int32_t start,
//----------------------------------------------------------------------
int32_t
SimpleDateFormat::compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
SimpleDateFormat::compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t pos) const {
int32_t start = pos;
for (int32_t i=0; i<affix.length(); ) {
@ -3228,7 +3228,7 @@ SimpleDateFormat::compareSimpleAffix(const UnicodeString& affix,
//----------------------------------------------------------------------
int32_t
int32_t
SimpleDateFormat::skipRuleWhiteSpace(const UnicodeString& text, int32_t pos) const {
while (pos < text.length()) {
UChar32 c = text.char32At(pos);
@ -3242,7 +3242,7 @@ SimpleDateFormat::skipRuleWhiteSpace(const UnicodeString& text, int32_t pos) con
//----------------------------------------------------------------------
int32_t
int32_t
SimpleDateFormat::skipUWhiteSpace(const UnicodeString& text, int32_t pos) const {
while (pos < text.length()) {
UChar32 c = text.char32At(pos);

View file

@ -240,14 +240,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call. Field values
* are defined in UDateFormatField.
* are defined in UDateFormatField. Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft ICU 4.4
*/
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
* Formats a date into a date/time string. This is an abstract method which
@ -299,14 +299,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call. Field values
* are defined in UDateFormatField.
* are defined in UDateFormatField. Can be NULL.
* @param status error status.
* @return Reference to 'appendTo' parameter.
* @draft ICU 4.4
*/
virtual UnicodeString& format(Calendar& cal,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
* Formats a UDate into a date/time string.
@ -347,14 +347,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call. Field values
* are defined in UDateFormatField.
* are defined in UDateFormatField. Can be NULL.
* @param status error status.
* @return Reference to 'appendTo' parameter.
* @draft ICU 4.4
*/
UnicodeString& format(UDate date,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
* Formats a UDate into a date/time string. If there is a problem, you won't

View file

@ -20,16 +20,16 @@
* 07/20/98 stephen Changed documentation
********************************************************************************
*/
#ifndef DECIMFMT_H
#define DECIMFMT_H
#include "unicode/utypes.h"
/**
* \file
* \file
* \brief C++ API: Formats decimal numbers.
*/
#if !UCONFIG_NO_FORMATTING
#include "unicode/dcfmtsym.h"
@ -69,11 +69,11 @@ class FieldPositionHandler;
* // Normally we would have a GUI with a menu for this
* int32_t locCount;
* const Locale* locales = NumberFormat::getAvailableLocales(locCount);
*
*
* double myNumber = -1234.56;
* UErrorCode success = U_ZERO_ERROR;
* NumberFormat* form;
*
*
* // Print out a number with the localized number, currency and percent
* // format for each locale.
* UnicodeString countryName;
@ -102,7 +102,7 @@ class FieldPositionHandler;
* cout << locales[i].getDisplayName(displayName) << ": " << pattern;
* cout << " -> " << form->format(myNumber,str) << endl;
* form->parse(form->format(myNumber,str), fmtable, success);
* delete form;
* delete form;
* }
* }
* }
@ -119,8 +119,8 @@ class FieldPositionHandler;
* UErrorCode success = U_ZERO_ERROR;
* UnicodeString str;
* Formattable fmtable;
* for (int j=NumberFormat::kNumberStyle;
* j<=NumberFormat::kPluralCurrencyStyle;
* for (int j=NumberFormat::kNumberStyle;
* j<=NumberFormat::kPluralCurrencyStyle;
* ++j) {
* NumberFormat* format = NumberFormat::createInstance(locale, j, success);
* str.remove();
@ -138,7 +138,7 @@ class FieldPositionHandler;
* digits. The symbols are stored in a DecimalFormatSymbols
* object. When using the NumberFormat factory methods, the
* pattern and symbols are read from ICU's locale data.
*
*
* <p><strong>Special Pattern Characters</strong>
*
* <p>Many characters in a pattern are taken literally; they are matched during
@ -318,7 +318,7 @@ class FieldPositionHandler;
* </pre>
* The first subpattern is for positive numbers. The second (optional)
* subpattern is for negative numbers.
*
*
* <p>Not indicated in the BNF syntax above:
*
* <ul><li>The grouping separator ',' can occur inside the integer and
@ -333,7 +333,7 @@ class FieldPositionHandler;
* locales they differ. For example, the pattern
* &quot;#,##,###&quot; formats the number 123456789 as
* &quot;12,34,56,789&quot;.</li>
*
*
* <li>The pad specifier <code>padSpec</code> may appear before the prefix,
* after the prefix, before the suffix, after the suffix, or not at all.
*
@ -354,7 +354,7 @@ class FieldPositionHandler;
*
* <p>For currency parsing, the formatter is able to parse every currency
* style formats no matter which style the formatter is constructed with.
* For example, a formatter instance gotten from
* For example, a formatter instance gotten from
* NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
* formats such as "USD1.00" and "3.00 US dollars".
*
@ -752,7 +752,7 @@ public:
* @param pattern a non-localized pattern string
* @param symbolsToAdopt the set of symbols to be used. The caller should not
* delete this object after making this call.
* @param parseError Output param to receive errors occured during parsing
* @param parseError Output param to receive errors occured during parsing
* @param status Output param set to success/failure code. If the
* pattern is invalid this will be set to a failure code.
* @stable ICU 2.0
@ -784,7 +784,7 @@ public:
/**
* Copy constructor.
*
*
* @param source the DecimalFormat object to be copied from.
* @stable ICU 2.0
*/
@ -846,13 +846,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(double number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -878,13 +879,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(int32_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -910,13 +912,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(int64_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -930,13 +933,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(const StringPiece &number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -1035,7 +1039,7 @@ public:
ParsePosition& parsePosition) const;
// Declare here again to get rid of function hiding problems.
/**
/**
* Parse the given string using this object's choices.
*
* @param text The text to be parsed.
@ -1043,8 +1047,8 @@ public:
* @param status Output parameter filled in with success or failure status.
* @stable ICU 2.0
*/
virtual void parse(const UnicodeString& text,
Formattable& result,
virtual void parse(const UnicodeString& text,
Formattable& result,
UErrorCode& status) const;
/**
@ -1097,7 +1101,7 @@ public:
/**
* Returns the currency plural format information,
* Returns the currency plural format information,
* which is generally not changed by the programmer or user.
* @return desired CurrencyPluralInfo
* @stable ICU 4.4
@ -1105,7 +1109,7 @@ public:
virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
/**
* Sets the currency plural format information,
* Sets the currency plural format information,
* which is generally not changed by the programmer or user.
* @param toAdopt CurrencyPluralInfo to be adopted.
* @stable ICU 4.4
@ -1113,7 +1117,7 @@ public:
virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
/**
* Sets the currency plural format information,
* Sets the currency plural format information,
* which is generally not changed by the programmer or user.
* @param info Currency Plural Info.
* @stable ICU 4.4
@ -1545,7 +1549,7 @@ public:
* @stable ICU 2.0
*/
virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
/**
* Apply the given pattern to this Format object. A pattern is a
* short-hand specification for the various formatting properties.
@ -1568,7 +1572,7 @@ public:
* these are presumed to be set in the positive pattern.
*
* @param pattern The pattern to be applied.
* @param parseError Struct to recieve information on position
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
@ -1585,7 +1589,7 @@ public:
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @stable ICU 2.0
*/
*/
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
@ -1612,7 +1616,7 @@ public:
* these are presumed to be set in the positive pattern.
*
* @param pattern The localized pattern to be applied.
* @param parseError Struct to recieve information on position
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
@ -1640,7 +1644,7 @@ public:
* Sets the maximum number of digits allowed in the integer portion of a
* number. This override limits the integer digit count to 309.
*
* @param newValue the new value of the maximum number of digits
* @param newValue the new value of the maximum number of digits
* allowed in the integer portion of a number.
* @see NumberFormat#setMaximumIntegerDigits
* @stable ICU 2.0
@ -1650,8 +1654,8 @@ public:
/**
* Sets the minimum number of digits allowed in the integer portion of a
* number. This override limits the integer digit count to 309.
*
* @param newValue the new value of the minimum number of digits
*
* @param newValue the new value of the minimum number of digits
* allowed in the integer portion of a number.
* @see NumberFormat#setMinimumIntegerDigits
* @stable ICU 2.0
@ -1662,7 +1666,7 @@ public:
* Sets the maximum number of digits allowed in the fraction portion of a
* number. This override limits the fraction digit count to 340.
*
* @param newValue the new value of the maximum number of digits
* @param newValue the new value of the maximum number of digits
* allowed in the fraction portion of a number.
* @see NumberFormat#setMaximumFractionDigits
* @stable ICU 2.0
@ -1673,7 +1677,7 @@ public:
* Sets the minimum number of digits allowed in the fraction portion of a
* number. This override limits the fraction digit count to 340.
*
* @param newValue the new value of the minimum number of digits
* @param newValue the new value of the minimum number of digits
* allowed in the fraction portion of a number.
* @see NumberFormat#setMinimumFractionDigits
* @stable ICU 2.0
@ -1704,7 +1708,7 @@ public:
* to one. If the maximum significant digits count is less than
* <code>min</code>, then it is set to <code>min</code>. This
* value has no effect unless areSignificantDigits() returns true.
* @param min the fewest significant digits to be shown
* @param min the fewest significant digits to be shown
* @stable ICU 3.0
*/
void setMinimumSignificantDigits(int32_t min);
@ -1716,7 +1720,7 @@ public:
* than <code>max</code>, then it is set to <code>max</code>.
* This value has no effect unless areSignificantDigits() returns
* true.
* @param max the most significant digits to be shown
* @param max the most significant digits to be shown
* @stable ICU 3.0
*/
void setMaximumSignificantDigits(int32_t max);
@ -1824,7 +1828,7 @@ private:
* Does the real work of applying a pattern.
* @param pattern The pattern to be applied.
* @param localized If true, the pattern is localized; else false.
* @param parseError Struct to recieve information on position
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
@ -1835,8 +1839,8 @@ private:
UParseError& parseError,
UErrorCode& status);
/*
* similar to applyPattern, but without re-gen affix for currency
/*
* similar to applyPattern, but without re-gen affix for currency
*/
void applyPatternInternally(const UnicodeString& pluralCount,
const UnicodeString& pattern,
@ -1858,7 +1862,7 @@ private:
*/
void expandAffixAdjustWidth(const UnicodeString* pluralCount);
/**
* Do the work of formatting a number, either a double or a long.
*
@ -1885,7 +1889,7 @@ private:
fgStatusLength // Leave last in list.
} StatusFlags;
UBool subparse(const UnicodeString& text,
UBool subparse(const UnicodeString& text,
const UnicodeString* negPrefix,
const UnicodeString* negSuffix,
const UnicodeString* posPrefix,
@ -1897,11 +1901,11 @@ private:
UChar* currency) const;
// Mixed style parsing for currency.
// It parses against the current currency pattern
// It parses against the current currency pattern
// using complex affix comparison
// parses against the currency plural patterns using complex affix comparison,
// and parses against the current pattern using simple affix comparison.
UBool parseForCurrency(const UnicodeString& text,
UBool parseForCurrency(const UnicodeString& text,
ParsePosition& parsePosition,
DigitList& digits,
UBool* status,
@ -1917,15 +1921,15 @@ private:
UBool currencyParsing,
int8_t type,
UChar* currency) const;
static int32_t compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t pos);
static int32_t skipRuleWhiteSpace(const UnicodeString& text, int32_t pos);
static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
int32_t compareComplexAffix(const UnicodeString& affixPat,
const UnicodeString& input,
int32_t pos,
@ -1943,10 +1947,10 @@ private:
*/
inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
int32_t appendAffix(UnicodeString& buf,
int32_t appendAffix(UnicodeString& buf,
double number,
FieldPositionHandler& handler,
UBool isNegative,
UBool isNegative,
UBool isPrefix) const;
/**
@ -1969,7 +1973,7 @@ private:
const UnicodeString* pluralCount) const;
void expandAffixes(const UnicodeString* pluralCount);
static double round(double a, ERoundingMode mode, UBool isNegative);
void addPadding(UnicodeString& appendTo,
@ -1982,7 +1986,7 @@ private:
// similar to setCurrency without re-compute the affixes for currency.
// If currency changes, the affix pattern for currency is not changed,
// but the affix will be changed. So, affixes need to be
// but the affix will be changed. So, affixes need to be
// re-computed in setCurrency(), but not in setCurrencyInternally().
virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
@ -1994,13 +1998,13 @@ private:
// set up the currency affixes used in currency plural formatting.
// It sets up both fAffixesForCurrency for currency pattern if the current
// pattern contains 3 currency signs,
// pattern contains 3 currency signs,
// and it sets up fPluralAffixesForCurrency for currency plural patterns.
void setupCurrencyAffixes(const UnicodeString& pattern,
void setupCurrencyAffixes(const UnicodeString& pattern,
UBool setupForCurrentPattern,
UBool setupForPluralPattern,
UErrorCode& status);
// hashtable operations
Hashtable* initHashForAffixPattern(UErrorCode& status);
Hashtable* initHashForAffix(UErrorCode& status);
@ -2099,8 +2103,8 @@ private:
/* For currency parsing purose,
* Need to remember all prefix patterns and suffix patterns of
* every currency format pattern,
* Need to remember all prefix patterns and suffix patterns of
* every currency format pattern,
* including the pattern of default currecny style
* and plural currency style. And the patterns are set through applyPattern.
*/
@ -2116,8 +2120,8 @@ private:
// positive suffix pattern
UnicodeString posSuffixPatternForCurrency;
int8_t patternType;
AffixPatternsForCurrency(const UnicodeString& negPrefix,
AffixPatternsForCurrency(const UnicodeString& negPrefix,
const UnicodeString& negSuffix,
const UnicodeString& posPrefix,
const UnicodeString& posSuffix,
@ -2130,9 +2134,9 @@ private:
}
};
*/
/* affix for currency formatting when the currency sign in the pattern
* equals to 3, such as the pattern contains 3 currency sign or
* equals to 3, such as the pattern contains 3 currency sign or
* the formatter style is currency plural format style.
*/
/* This is not needed in the class declaration, so it is moved into decimfmp.cpp
@ -2145,7 +2149,7 @@ private:
UnicodeString posPrefixForCurrency;
// positive suffix
UnicodeString posSuffixForCurrency;
int32_t formatWidth;
AffixesForCurrency(const UnicodeString& negPrefix,
@ -2163,7 +2167,7 @@ private:
// Affix pattern set for currency.
// It is a set of AffixPatternsForCurrency,
// each element of the set saves the negative prefix pattern,
// negative suffix pattern, positive prefix pattern,
// negative suffix pattern, positive prefix pattern,
// and positive suffix pattern of a pattern.
// It is used for currency mixed style parsing.
// It is actually is a set.
@ -2200,13 +2204,13 @@ protected:
*/
virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
/** number of integer digits
/** number of integer digits
* @stable ICU 2.4
*/
*/
static const int32_t kDoubleIntegerDigits;
/** number of fraction digits
/** number of fraction digits
* @stable ICU 2.4
*/
*/
static const int32_t kDoubleFractionDigits;
/**

View file

@ -25,10 +25,10 @@
#include "unicode/utypes.h"
/**
* \file
* \file
* \brief C++ API: Abstract base class for all number formats.
*/
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
@ -109,16 +109,16 @@ class StringEnumeration;
* fraction from 0.53 is displayed as 53%.
* <P>
* Starting from ICU 4.2, you can use createInstance() by passing in a 'style'
* as parameter to get the correct instance.
* For example,
* as parameter to get the correct instance.
* For example,
* use createInstance(...kNumberStyle...) to get the normal number format,
* createInstance(...kPercentStyle...) to get a format for displaying
* createInstance(...kPercentStyle...) to get a format for displaying
* percentage,
* createInstance(...kScientificStyle...) to get a format for displaying
* createInstance(...kScientificStyle...) to get a format for displaying
* scientific number,
* createInstance(...kCurrencyStyle...) to get the currency number format,
* createInstance(...kCurrencyStyle...) to get the currency number format,
* in which the currency is represented by its symbol, for example, "$3.00".
* createInstance(...kIsoCurrencyStyle...) to get the currency number format,
* createInstance(...kIsoCurrencyStyle...) to get the currency number format,
* in which the currency is represented by its ISO code, for example "USD3.00".
* createInstance(...kPluralCurrencyStyle...) to get the currency number format,
* in which the currency is represented by its full name in plural format,
@ -264,14 +264,15 @@ public:
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* of fields generated by this format call. Can be
* NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -369,13 +370,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(double number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
* Format a long number. Concrete subclasses must implement
@ -402,13 +404,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(int32_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
* Format an int64 number. (Not abstract to retain compatibility
@ -435,13 +438,14 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(int64_t number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -455,16 +459,17 @@ public:
* Result is appended to existing contents.
* @param posIter On return, can be used to iterate over positions
* of fields generated by this format call.
* Can be NULL.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @draft 4.4
*/
virtual UnicodeString& format(const StringPiece &number,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
// TODO: do we also want a format of a decimal number that takes a
// TODO: do we also want a format of a decimal number that takes a
// FieldPosition parameter?
/**

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 1997-2010, International Business Machines Corporation and others. All Rights Reserved.
* Copyright (C) 1997-2010, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File SMPDTFMT.H
@ -26,10 +27,10 @@
#include "unicode/utypes.h"
/**
* \file
* \file
* \brief C++ API: Format and parse dates in a language-independent manner.
*/
#if !UCONFIG_NO_FORMATTING
#include "unicode/datefmt.h"
@ -406,7 +407,7 @@ public:
*/
virtual UnicodeString& format( Calendar& cal,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -455,7 +456,7 @@ public:
*/
virtual UnicodeString& format( const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -486,7 +487,7 @@ public:
*/
UnicodeString& format(UDate date,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const;
/**
@ -726,10 +727,10 @@ public:
/**
* This is for ICU internal use only. Please do not use.
* Check whether the 'field' is smaller than all the fields covered in
* pattern, return TRUE if it is. The sequence of calendar field,
* pattern, return TRUE if it is. The sequence of calendar field,
* from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
* @param field the calendar field need to check against
* @return TRUE if the 'field' is smaller than all the fields
* @return TRUE if the 'field' is smaller than all the fields
* covered in pattern. FALSE otherwise.
* @internal ICU 4.0
*/
@ -739,15 +740,15 @@ public:
/**
* This is for ICU internal use only. Please do not use.
* Check whether the 'field' is smaller than all the fields covered in
* pattern, return TRUE if it is. The sequence of calendar field,
* pattern, return TRUE if it is. The sequence of calendar field,
* from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
* @param pattern the pattern to check against
* @param field the calendar field need to check against
* @return TRUE if the 'field' is smaller than all the fields
* @return TRUE if the 'field' is smaller than all the fields
* covered in pattern. FALSE otherwise.
* @internal ICU 4.0
*/
static UBool isFieldUnitIgnored(const UnicodeString& pattern,
static UBool isFieldUnitIgnored(const UnicodeString& pattern,
UCalendarDateFields field);
@ -790,7 +791,7 @@ private:
*/
SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
/**
/**
* Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
*/
UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler,
@ -977,8 +978,8 @@ private:
* @param pos offset into input at which to begin matching
* @return length of input that matches, or -1 if match failure
*/
int32_t compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t pos) const;
/**
@ -1059,7 +1060,7 @@ private:
*/
UnicodeString fTimeOverride;
/**
* The original locale used (for reloading symbols)
*/
@ -1125,13 +1126,13 @@ private:
// unexpectedly success parsing input GMT string without second field.
// See #6880 about this issue.
// TODO: SimpleDateFormat should provide an option to invalidate
//
//
int32_t fGMTFormatHmsMinLen[kNumGMTFormatMinLengths];
NumberFormat **fNumberFormatters;
NSOverride *fOverrideList;
UBool fHaveDefaultCentury;
};
@ -1151,8 +1152,8 @@ SimpleDateFormat::format(const Formattable& obj,
}
inline UnicodeString&
SimpleDateFormat::format(const Formattable& obj,
UnicodeString& appendTo,
SimpleDateFormat::format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const
{
@ -1164,7 +1165,7 @@ SimpleDateFormat::format(const Formattable& obj,
inline UnicodeString&
SimpleDateFormat::format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const
{
// Don't use Format:: - use immediate base class only,
@ -1184,7 +1185,7 @@ SimpleDateFormat::format(UDate date,
inline UnicodeString&
SimpleDateFormat::format(UDate date,
UnicodeString& appendTo,
FieldPositionIterator& posIter,
FieldPositionIterator* posIter,
UErrorCode& status) const {
// Don't use Format:: - use immediate base class only,
// in case immediate base modifies behavior later.

View file

@ -1,9 +1,9 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2009, International Business Machines Corporation and
* others. All Rights Reserved.
* COPYRIGHT:
* Copyright (c) 1997-2010, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
@ -20,7 +20,7 @@
#include "cstring.h"
#include "caltest.h" // for fieldName
#include <stdio.h> // for sprintf
"ti
#ifdef U_WINDOWS
#include "windttst.h"
#endif
@ -189,7 +189,7 @@ void DateFormatTest::TestWallyWedel()
}
// -------------------------------------
/**
* Test operator==
*/
@ -212,7 +212,7 @@ DateFormatTest::TestEquals()
TimeZone* test = TimeZone::createTimeZone("PDT");
delete test;
}
// -------------------------------------
/**
@ -233,7 +233,7 @@ DateFormatTest::TestTwoDigitYearDSTParse(void)
int32_t hour = 2 + (defaultOffset - PSTOffset) / (60*60*1000);
// hour is the expected hour of day, in units of seconds
hour = ((hour < 0) ? hour + 24 : hour) * 60*60;
UnicodeString str;
if(U_FAILURE(status)) {
@ -259,9 +259,9 @@ DateFormatTest::TestTwoDigitYearDSTParse(void)
delete PST;
delete defaultTZ;
}
// -------------------------------------
UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
UnicodeString&
@ -282,7 +282,7 @@ DateFormatTest::escape(UnicodeString& s)
}
return (s = buf);
}
// -------------------------------------
/**
@ -411,7 +411,7 @@ void DateFormatTest::TestFieldPosition() {
for (i = 0; i < UDAT_FIELD_COUNT; ++i, ++exp) {
FieldPosition pos(i);
buf.remove();
df->format(aug13, buf, pos);
df->format(aug13, buf, pos);
UnicodeString field;
buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), field);
assertEquals((UnicodeString)"field #" + i + " " + DATEFORMAT_FIELD_NAMES[i],
@ -426,7 +426,7 @@ void DateFormatTest::TestFieldPosition() {
FieldPosition fp;
buf.remove();
df->format(aug13, buf, posIter, status);
df->format(aug13, buf, &posIter, status);
while (posIter.next(fp)) {
int32_t i = fp.getField();
UnicodeString field;
@ -434,9 +434,17 @@ void DateFormatTest::TestFieldPosition() {
assertEquals((UnicodeString)"field #" + i + " " + DATEFORMAT_FIELD_NAMES[i],
ctou(EXPECTED[expBase + i]), field);
}
}
}
// test null posIter
buf.remove();
UErrorCode status = U_ZERO_ERROR;
dateFormats[0]->format(aug13, buf, NULL, status);
// if we didn't crash, we succeeded.
for (i=0; i<COUNT; ++i) {
delete dateFormats[i];
}
@ -460,7 +468,7 @@ void DateFormatTest::TestGeneral() {
};
expect(DATA, ARRAY_SIZE(DATA), Locale("en", "", ""));
}
// -------------------------------------
/**
@ -473,7 +481,7 @@ DateFormatTest::TestPartialParse994()
{
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat* f = new SimpleDateFormat(status);
ASSERT_OK(status);
ASSERT_OK(status);
if (U_FAILURE(status)) {
delete f;
return;
@ -487,9 +495,9 @@ DateFormatTest::TestPartialParse994()
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
delete f;
}
// -------------------------------------
void
DateFormatTest::tryPat994(SimpleDateFormat* format, const char* pat, const char* str, UDate expected)
{
@ -524,9 +532,9 @@ DateFormatTest::tryPat994(SimpleDateFormat* format, const char* pat, const char*
// e.printStackTrace();
//}
}
// -------------------------------------
/**
* Verify the behavior of patterns in which digits for different fields run together
* without intervening separators.
@ -539,7 +547,7 @@ DateFormatTest::TestRunTogetherPattern985()
UnicodeString now, then;
//UBool flag;
SimpleDateFormat *formatter = new SimpleDateFormat(format, status);
ASSERT_OK(status);
ASSERT_OK(status);
UDate date1 = Calendar::getNow();
((DateFormat*)formatter)->format(date1, now);
logln(now);
@ -552,9 +560,9 @@ DateFormatTest::TestRunTogetherPattern985()
delete formatter;
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
/**
* Verify the behavior of patterns in which digits for different fields run together
* without intervening separators.
@ -566,7 +574,7 @@ DateFormatTest::TestRunTogetherPattern917()
SimpleDateFormat* fmt;
UnicodeString myDate;
fmt = new SimpleDateFormat((UnicodeString)"yyyy/MM/dd", status);
ASSERT_OK(status);
ASSERT_OK(status);
myDate = "1997/02/03";
testIt917(fmt, myDate, date(97, 2 - 1, 3));
delete fmt;
@ -576,9 +584,9 @@ DateFormatTest::TestRunTogetherPattern917()
delete fmt;
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
void
DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expected)
{
@ -601,9 +609,9 @@ DateFormatTest::testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expec
if (!(formatted == str)) errln((UnicodeString)"FAIL: Expected " + str);
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
/**
* Verify the handling of Czech June and July, which have the unique attribute that
* one is a proper prefix substring of the other.
@ -644,7 +652,7 @@ DateFormatTest::TestCzechMonths459()
//}
delete fmt;
}
// -------------------------------------
/**
@ -662,14 +670,14 @@ DateFormatTest::TestLetterDPattern212()
expLittleD = expBigD; // Expect the same, with default lenient parsing
logln((UnicodeString)"dateString= " + dateString);
SimpleDateFormat *formatter = new SimpleDateFormat(bigD, status);
ASSERT_OK(status);
ASSERT_OK(status);
ParsePosition pos(0);
UDate myDate = formatter->parse(dateString, pos);
logln((UnicodeString)"Using " + bigD + " -> " + myDate);
if (myDate != expBigD) errln((UnicodeString)"FAIL: Expected " + dateToString(expBigD));
delete formatter;
formatter = new SimpleDateFormat(littleD, status);
ASSERT_OK(status);
ASSERT_OK(status);
pos = ParsePosition(0);
myDate = formatter->parse(dateString, pos);
logln((UnicodeString)"Using " + littleD + " -> " + dateToString(myDate));
@ -677,7 +685,7 @@ DateFormatTest::TestLetterDPattern212()
delete formatter;
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
/**
@ -701,9 +709,9 @@ DateFormatTest::TestDayOfYearPattern195()
delete sdf;
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
void
DateFormatTest::tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern, UDate expected)
{
@ -726,7 +734,7 @@ DateFormatTest::tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern,
errln((UnicodeString)"Error: " + (int32_t)status);
//}
}
// -------------------------------------
/**
@ -737,7 +745,7 @@ DateFormatTest::TestQuotePattern161()
{
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat* formatter = new SimpleDateFormat((UnicodeString)"MM/dd/yyyy 'at' hh:mm:ss a zzz", status);
ASSERT_OK(status);
ASSERT_OK(status);
UDate currentTime_1 = date(97, UCAL_AUGUST, 13, 10, 42, 28);
UnicodeString dateString; ((DateFormat*)formatter)->format(currentTime_1, dateString);
UnicodeString exp("08/13/1997 at 10:42:28 AM ");
@ -746,7 +754,7 @@ DateFormatTest::TestQuotePattern161()
delete formatter;
if (U_FAILURE(status)) errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
/**
@ -812,7 +820,7 @@ DateFormatTest::TestBadInput135()
if (U_FAILURE(status))
errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
static const char* const parseFormats[] = {
"MMMM d, yyyy",
"MMMM d yyyy",
@ -824,7 +832,7 @@ static const char* const parseFormats[] = {
"yyyy",
"h:mm a MMMM d, yyyy"
};
static const char* const inputStrings[] = {
"bogus string", 0, 0, 0, 0, 0, 0, 0, 0, 0,
"April 1, 1997", "April 1, 1997", 0, 0, 0, 0, 0, "April 1", 0, 0,
@ -838,7 +846,7 @@ static const char* const inputStrings[] = {
"1", 0, 0, 0, 0, 0, 0, 0, "0001", 0,
"3:00 pm Jan 1, 1997", 0, 0, 0, 0, 0, 0, 0, "0003", "3:00 PM January 1, 1997",
};
// -------------------------------------
/**
@ -921,7 +929,7 @@ DateFormatTest::TestBadInput135a()
if (U_FAILURE(status))
errln((UnicodeString)"FAIL: UErrorCode received during test: " + (int32_t)status);
}
// -------------------------------------
/**
@ -939,9 +947,9 @@ DateFormatTest::TestTwoDigitYear()
parse2DigitYear(fmt, "5/6/17", date(117, UCAL_JUNE, 5));
parse2DigitYear(fmt, "4/6/34", date(34, UCAL_JUNE, 4));
}
// -------------------------------------
void
DateFormatTest::parse2DigitYear(DateFormat& fmt, const char* str, UDate expected)
{
@ -958,7 +966,7 @@ DateFormatTest::parse2DigitYear(DateFormat& fmt, const char* str, UDate expected
errln((UnicodeString)"FAIL: Got exception");
//}
}
// -------------------------------------
/**
@ -992,9 +1000,9 @@ DateFormatTest::TestDateFormatZone061()
//}
delete formatter;
}
// -------------------------------------
/**
* Test the formatting of time zones.
*/
@ -1050,7 +1058,7 @@ DateFormatTest::TestDateFormatZone146()
UnicodeString result;
result = fmt->format(greenwichdate, result);
logln(DATA[i] + result);
if (result != DATA[i+1])
if (result != DATA[i+1])
errln("FAIL: Expected " + DATA[i+1] + ", got " + result);
delete fmt;
}
@ -1064,9 +1072,9 @@ DateFormatTest::TestDateFormatZone146()
}
// -------------------------------------
/**
* Test the formatting of dates in different locales.
*/
@ -1074,16 +1082,16 @@ void
DateFormatTest::TestLocaleDateFormat() // Bug 495
{
UDate testDate = date(97, UCAL_SEPTEMBER, 15);
DateFormat *dfFrench = DateFormat::createDateTimeInstance(DateFormat::FULL,
DateFormat *dfFrench = DateFormat::createDateTimeInstance(DateFormat::FULL,
DateFormat::FULL, Locale::getFrench());
DateFormat *dfUS = DateFormat::createDateTimeInstance(DateFormat::FULL,
DateFormat *dfUS = DateFormat::createDateTimeInstance(DateFormat::FULL,
DateFormat::FULL, Locale::getUS());
UnicodeString expectedFRENCH ( "lundi 15 septembre 1997 00:00:00 heure avanc\\u00E9e du Pacifique", -1, US_INV );
expectedFRENCH = expectedFRENCH.unescape();
//UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 o'clock AM PDT" );
UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 AM Pacific Daylight Time" );
logln((UnicodeString)"Date set to : " + dateToString(testDate));
UnicodeString out;
UnicodeString out;
if (dfUS == NULL || dfFrench == NULL){
dataerrln("Error calling DateFormat::createDateTimeInstance)");
delete dfUS;
@ -1140,7 +1148,7 @@ void DateFormatTest::TestDateFormatCalendar() {
/* Create a calendar */
cal = Calendar::createInstance(Locale::getUS(), ec);
if (cal == NULL || U_FAILURE(ec)) {
errln((UnicodeString)"FAIL: Calendar::createInstance failed with " +
errln((UnicodeString)"FAIL: Calendar::createInstance failed with " +
u_errorName(ec));
goto FAIL;
}
@ -1165,7 +1173,7 @@ void DateFormatTest::TestDateFormatCalendar() {
pos.getIndex());
goto FAIL;
}
/* Check result */
when = cal->getTime(ec);
if (U_FAILURE(ec)) {
@ -1181,7 +1189,7 @@ void DateFormatTest::TestDateFormatCalendar() {
errln("FAIL: Parsed result: " + str + ", exp 4/5/2001 5:45 PM");
}
FAIL:
FAIL:
delete date;
delete time;
delete full;
@ -1235,15 +1243,15 @@ void DateFormatTest::TestExactCountFormat() {
void DateFormatTest::TestWhiteSpaceParsing() {
const char* DATA[] = {
"yyyy MM dd",
// pattern, input, expected parse or null if expect parse failure
// Pattern space run should parse input text space run
"MM d yy", " 04 01 03", "2003 04 01",
NULL, " 04 01 03 ", "2003 04 01",
};
const int32_t DATA_len = sizeof(DATA)/sizeof(DATA[0]);
expectParse(DATA, DATA_len, Locale("en"));
}
@ -1283,7 +1291,7 @@ void DateFormatTest::TestStandAloneMonths()
"yyyy LLL dd H:mm:ss", "fp", "2004 03 10 16:36:31", "2004 Mar 10 16:36:31", "2004 03 10 16:36:31",
"yyyy LLLL dd H:mm:ss", "F", "2004 03 10 16:36:31", "2004 March 10 16:36:31",
"yyyy LLL dd H:mm:ss", "pf", "2004 Mar 10 16:36:31", "2004 03 10 16:36:31", "2004 Mar 10 16:36:31",
"LLLL", "fp", "1970 01 01 0:00:00", "January", "1970 01 01 0:00:00",
"LLLL", "fp", "1970 02 01 0:00:00", "February", "1970 02 01 0:00:00",
"LLLL", "fp", "1970 03 01 0:00:00", "March", "1970 03 01 0:00:00",
@ -1296,7 +1304,7 @@ void DateFormatTest::TestStandAloneMonths()
"LLLL", "fp", "1970 10 01 0:00:00", "October", "1970 10 01 0:00:00",
"LLLL", "fp", "1970 11 01 0:00:00", "November", "1970 11 01 0:00:00",
"LLLL", "fp", "1970 12 01 0:00:00", "December", "1970 12 01 0:00:00",
"LLL", "fp", "1970 01 01 0:00:00", "Jan", "1970 01 01 0:00:00",
"LLL", "fp", "1970 02 01 0:00:00", "Feb", "1970 02 01 0:00:00",
"LLL", "fp", "1970 03 01 0:00:00", "Mar", "1970 03 01 0:00:00",
@ -1310,7 +1318,7 @@ void DateFormatTest::TestStandAloneMonths()
"LLL", "fp", "1970 11 01 0:00:00", "Nov", "1970 11 01 0:00:00",
"LLL", "fp", "1970 12 01 0:00:00", "Dec", "1970 12 01 0:00:00",
};
const char *CS_DATA[] = {
"yyyy MM dd HH:mm:ss",
@ -1321,7 +1329,7 @@ void DateFormatTest::TestStandAloneMonths()
"yyyy MMMM dd H:mm:ss", "F", "2004 04 10 16:36:31", "2004 dubna 10 16:36:31",
"yyyy LLLL dd H:mm:ss", "pf", "2004 duben 10 16:36:31", "2004 04 10 16:36:31", "2004 duben 10 16:36:31",
"yyyy MMMM dd H:mm:ss", "pf", "2004 dubna 10 16:36:31", "2004 04 10 16:36:31", "2004 dubna 10 16:36:31",
"LLLL", "fp", "1970 01 01 0:00:00", "leden", "1970 01 01 0:00:00",
"LLLL", "fp", "1970 02 01 0:00:00", "\\u00FAnor", "1970 02 01 0:00:00",
"LLLL", "fp", "1970 03 01 0:00:00", "b\\u0159ezen", "1970 03 01 0:00:00",
@ -1348,7 +1356,7 @@ void DateFormatTest::TestStandAloneMonths()
"LLL", "fp", "1970 11 01 0:00:00", "11.", "1970 11 01 0:00:00",
"LLL", "fp", "1970 12 01 0:00:00", "12.", "1970 12 01 0:00:00",
};
expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", ""));
expect(CS_DATA, ARRAY_SIZE(CS_DATA), Locale("cs", "", ""));
}
@ -1365,7 +1373,7 @@ void DateFormatTest::TestStandAloneDays()
"cccc", "fp", "1970 01 01 0:00:00", "Thursday", "1970 01 01 0:00:00",
"cccc", "fp", "1970 01 02 0:00:00", "Friday", "1970 01 02 0:00:00",
"cccc", "fp", "1970 01 03 0:00:00", "Saturday", "1970 01 03 0:00:00",
"ccc", "fp", "1970 01 04 0:00:00", "Sun", "1970 01 04 0:00:00",
"ccc", "fp", "1970 01 05 0:00:00", "Mon", "1970 01 05 0:00:00",
"ccc", "fp", "1970 01 06 0:00:00", "Tue", "1970 01 06 0:00:00",
@ -1374,7 +1382,7 @@ void DateFormatTest::TestStandAloneDays()
"ccc", "fp", "1970 01 02 0:00:00", "Fri", "1970 01 02 0:00:00",
"ccc", "fp", "1970 01 03 0:00:00", "Sat", "1970 01 03 0:00:00",
};
const char *CS_DATA[] = {
"yyyy MM dd HH:mm:ss",
@ -1385,7 +1393,7 @@ void DateFormatTest::TestStandAloneDays()
"cccc", "fp", "1970 01 01 0:00:00", "\\u010Dtvrtek", "1970 01 01 0:00:00",
"cccc", "fp", "1970 01 02 0:00:00", "p\\u00E1tek", "1970 01 02 0:00:00",
"cccc", "fp", "1970 01 03 0:00:00", "sobota", "1970 01 03 0:00:00",
"ccc", "fp", "1970 01 04 0:00:00", "ne", "1970 01 04 0:00:00",
"ccc", "fp", "1970 01 05 0:00:00", "po", "1970 01 05 0:00:00",
"ccc", "fp", "1970 01 06 0:00:00", "\\u00FAt", "1970 01 06 0:00:00",
@ -1394,7 +1402,7 @@ void DateFormatTest::TestStandAloneDays()
"ccc", "fp", "1970 01 02 0:00:00", "p\\u00E1", "1970 01 02 0:00:00",
"ccc", "fp", "1970 01 03 0:00:00", "so", "1970 01 03 0:00:00",
};
expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", ""));
expect(CS_DATA, ARRAY_SIZE(CS_DATA), Locale("cs", "", ""));
}
@ -1406,7 +1414,7 @@ void DateFormatTest::TestNarrowNames()
"yyyy MMMMM dd H:mm:ss", "2004 03 10 16:36:31", "2004 M 10 16:36:31",
"yyyy LLLLL dd H:mm:ss", "2004 03 10 16:36:31", "2004 M 10 16:36:31",
"MMMMM", "1970 01 01 0:00:00", "J",
"MMMMM", "1970 02 01 0:00:00", "F",
"MMMMM", "1970 03 01 0:00:00", "M",
@ -1419,7 +1427,7 @@ void DateFormatTest::TestNarrowNames()
"MMMMM", "1970 10 01 0:00:00", "O",
"MMMMM", "1970 11 01 0:00:00", "N",
"MMMMM", "1970 12 01 0:00:00", "D",
"LLLLL", "1970 01 01 0:00:00", "J",
"LLLLL", "1970 02 01 0:00:00", "F",
"LLLLL", "1970 03 01 0:00:00", "M",
@ -1440,7 +1448,7 @@ void DateFormatTest::TestNarrowNames()
"EEEEE", "1970 01 01 0:00:00", "T",
"EEEEE", "1970 01 02 0:00:00", "F",
"EEEEE", "1970 01 03 0:00:00", "S",
"ccccc", "1970 01 04 0:00:00", "S",
"ccccc", "1970 01 05 0:00:00", "M",
"ccccc", "1970 01 06 0:00:00", "T",
@ -1449,13 +1457,13 @@ void DateFormatTest::TestNarrowNames()
"ccccc", "1970 01 02 0:00:00", "F",
"ccccc", "1970 01 03 0:00:00", "S",
};
const char *CS_DATA[] = {
"yyyy MM dd HH:mm:ss",
"yyyy LLLLL dd H:mm:ss", "2004 04 10 16:36:31", "2004 d 10 16:36:31",
"yyyy MMMMM dd H:mm:ss", "2004 04 10 16:36:31", "2004 d 10 16:36:31",
"MMMMM", "1970 01 01 0:00:00", "l",
"MMMMM", "1970 02 01 0:00:00", "\\u00FA",
"MMMMM", "1970 03 01 0:00:00", "b",
@ -1468,7 +1476,7 @@ void DateFormatTest::TestNarrowNames()
"MMMMM", "1970 10 01 0:00:00", "\\u0159",
"MMMMM", "1970 11 01 0:00:00", "l",
"MMMMM", "1970 12 01 0:00:00", "p",
"LLLLL", "1970 01 01 0:00:00", "l",
"LLLLL", "1970 02 01 0:00:00", "\\u00FA",
"LLLLL", "1970 03 01 0:00:00", "b",
@ -1498,7 +1506,7 @@ void DateFormatTest::TestNarrowNames()
"ccccc", "1970 01 02 0:00:00", "P",
"ccccc", "1970 01 03 0:00:00", "S",
};
expectFormat(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", ""));
expectFormat(CS_DATA, ARRAY_SIZE(CS_DATA), Locale("cs", "", ""));
}
@ -1518,7 +1526,7 @@ void DateFormatTest::TestEras()
"MMMM dd yyyy GGG", "fp", "-438 07 17", "July 17 0439 BC", "-438 07 17",
"MMMM dd yyyy GGGG", "fp", "-438 07 17", "July 17 0439 Before Christ", "-438 07 17",
};
expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", ""));
}
@ -1537,7 +1545,7 @@ void DateFormatTest::TestQuarters()
"qqq", "fp", "1970 07 01", "Q3", "1970 07 01",
"qqqq", "fp", "1970 10 01", "4th quarter", "1970 10 01",
};
expect(EN_DATA, ARRAY_SIZE(EN_DATA), Locale("en", "", ""));
}
@ -1606,13 +1614,13 @@ void DateFormatTest::expectParse(const char** data, int32_t data_length,
if (got == exp) {
logln((UnicodeString)"Ok: " + input + " x " +
currentPat + " => " + gotstr);
currentPat + " => " + gotstr);
} else {
errln((UnicodeString)"FAIL: " + input + " x " +
currentPat + " => " + gotstr + ", expected " +
expstr);
}
}
}
}
/**
@ -1820,7 +1828,7 @@ void DateFormatTest::TestGenericTime() {
logln("cross format/parse tests");
UnicodeString basepat("yy/MM/dd H:mm ");
SimpleDateFormat formats[] = {
SimpleDateFormat formats[] = {
SimpleDateFormat(basepat + "vvv", en, status),
SimpleDateFormat(basepat + "vvvv", en, status),
SimpleDateFormat(basepat + "zzz", en, status),
@ -1832,9 +1840,9 @@ void DateFormatTest::TestGenericTime() {
UnicodeString test;
SimpleDateFormat univ("yyyy MM dd HH:mm zzz", en, status);
ASSERT_OK(status);
const UnicodeString times[] = {
"2004 01 02 03:04 PST",
"2004 07 08 09:10 PDT"
const UnicodeString times[] = {
"2004 01 02 03:04 PST",
"2004 07 08 09:10 PDT"
};
int32_t times_length = sizeof(times)/sizeof(times[0]);
for (int i = 0; i < times_length; ++i) {
@ -1848,16 +1856,16 @@ void DateFormatTest::TestGenericTime() {
UDate t = formats[k].parse(test, status);
if (U_SUCCESS(status)) {
if (d != t) {
errln((UnicodeString)"FAIL: format " + k +
" incorrectly parsed output of format " + j +
errln((UnicodeString)"FAIL: format " + k +
" incorrectly parsed output of format " + j +
" (" + test + "), returned " +
dateToString(t) + " instead of " + dateToString(d));
} else {
logln((UnicodeString)"OK: format " + k + " parsed ok");
}
} else if (status == U_PARSE_ERROR) {
errln((UnicodeString)"FAIL: format " + k +
" could not parse output of format " + j +
errln((UnicodeString)"FAIL: format " + k +
" could not parse output of format " + j +
" (" + test + ")");
}
}
@ -1904,7 +1912,7 @@ void DateFormatTest::TestZTimeZoneParsing(void) {
SimpleDateFormat univ("HH:mm Z", en, status);
const TimeZone *t = TimeZone::getGMT();
univ.setTimeZone(*t);
univ.setLenient(false);
ParsePosition pp(0);
ASSERT_OK(status);
@ -1925,9 +1933,9 @@ void DateFormatTest::TestZTimeZoneParsing(void) {
UDate d = univ.parse(tests[i].input, pp);
if(pp.getIndex() != tests[i].input.length()){
errln("setZoneString() did not succeed. Consumed: %i instead of %i",
pp.getIndex(), tests[i].input.length());
pp.getIndex(), tests[i].input.length());
return;
}
}
result.remove();
univ.format(d, result);
if(result != tests[i].expected_result) {
@ -1950,15 +1958,15 @@ void DateFormatTest::TestHost(void)
// Relative Date Tests
void DateFormatTest::TestRelative(int daysdelta,
void DateFormatTest::TestRelative(int daysdelta,
const Locale& loc,
const char *expectChars) {
char banner[25];
sprintf(banner, "%d", daysdelta);
UnicodeString bannerStr(banner, "");
UErrorCode status = U_ZERO_ERROR;
FieldPosition pos(0);
UnicodeString test;
Locale en("en");
@ -1970,31 +1978,31 @@ void DateFormatTest::TestRelative(int daysdelta,
}
DateFormat *full = DateFormat::createDateInstance(DateFormat::kFull , loc);
if (full == NULL) {
errln("DateFormat::createDateInstance(DateFormat::kFull, %s) returned NULL", loc.getName());
return;
}
DateFormat *en_full = DateFormat::createDateInstance(DateFormat::kFull, en);
if (en_full == NULL) {
errln("DateFormat::createDateInstance(DateFormat::kFull, en) returned NULL");
return;
}
DateFormat *en_fulltime = DateFormat::createDateTimeInstance(DateFormat::kFull,DateFormat::kFull,en);
if (en_fulltime == NULL) {
errln("DateFormat::createDateTimeInstance(DateFormat::kFull, DateFormat::kFull, en) returned NULL");
return;
}
UnicodeString result;
UnicodeString normalResult;
UnicodeString expect;
UnicodeString parseResult;
Calendar *c = Calendar::createInstance(status);
// Today = Today
@ -2010,27 +2018,27 @@ void DateFormatTest::TestRelative(int daysdelta,
} else {
full->format(*c, expect, pos); // expected = normal full
}
fullrelative ->format(*c, result, pos);
en_full ->format(*c, normalResult, pos);
if(result != expect) {
errln("FAIL: Relative Format ["+bannerStr+"] of "+normalResult+" failed, expected "+expect+" but got " + result);
} else {
logln("PASS: Relative Format ["+bannerStr+"] of "+normalResult+" got " + result);
}
//verify
UDate d = fullrelative->parse(result, status);
ASSERT_OK(status);
UnicodeString parseFormat; // parse rel->format full
en_full->format(d, parseFormat, status);
UnicodeString origFormat;
en_full->format(*c, origFormat, pos);
if(parseFormat!=origFormat) {
errln("FAIL: Relative Parse ["+bannerStr+"] of "+result+" failed, expected "+parseFormat+" but got "+origFormat);
} else {
@ -2260,7 +2268,7 @@ void DateFormatTest::TestTimeZoneDisplayName()
{ "en", "Asia/Calcutta", "2004-07-15T00:00:00Z", "zzzz", "India Standard Time", "+5:30" },
{ "en", "Asia/Calcutta", "2004-07-15T00:00:00Z", "v", "India Time", "Asia/Calcutta" },
{ "en", "Asia/Calcutta", "2004-07-15T00:00:00Z", "vvvv", "India Standard Time", "Asia/Calcutta" },
// ==========
{ "de", "America/Los_Angeles", "2004-01-15T00:00:00Z", "Z", "-0800", "-8:00" },
@ -2922,7 +2930,7 @@ void DateFormatTest::TestTimeZoneDisplayName()
FieldPosition pos(0);
fmt.format(*cal,result,pos);
if (result != info[4]) {
errln(info[0] + ";" + info[1] + ";" + info[2] + ";" + info[3] + " expected: '" +
errln(info[0] + ";" + info[1] + ";" + info[2] + ";" + info[3] + " expected: '" +
info[4] + "' but got: '" + result + "'");
}
}
@ -3056,7 +3064,7 @@ void DateFormatTest::TestRelativeError(void)
{
UErrorCode status;
Locale en("en");
DateFormat *en_reltime_reldate = DateFormat::createDateTimeInstance(DateFormat::kFullRelative,DateFormat::kFullRelative,en);
if(en_reltime_reldate == NULL) {
logln("PASS: rel date/rel time failed");
@ -3192,7 +3200,7 @@ void DateFormatTest::Test6726(void)
delete fmtl;
delete fmtm;
delete fmts;
return;
}
strf = fmtf->format(dt, strf);
@ -3216,8 +3224,8 @@ void DateFormatTest::Test6726(void)
}
delete fmtf;
delete fmtl;
delete fmtm;
delete fmtl;
delete fmtm;
delete fmts;
return;

View file

@ -5856,15 +5856,20 @@ void NumberFormatTest::TestFieldPositionIterator() {
assertTrue((UnicodeString)"self==", iter1 == iter1);
assertTrue((UnicodeString)"iter1==iter2", iter1 == iter2);
decFmt->format(num, str1, iter1, status);
decFmt->format(num, str1, &iter1, status);
assertTrue((UnicodeString)"iter1 != iter2", iter1 != iter2);
decFmt->format(num, str2, iter2, status);
decFmt->format(num, str2, &iter2, status);
assertTrue((UnicodeString)"iter1 == iter2 (2)", iter1 == iter2);
iter1.next(pos);
assertTrue((UnicodeString)"iter1 != iter2 (2)", iter1 != iter2);
iter2.next(pos);
assertTrue((UnicodeString)"iter1 == iter2 (3)", iter1 == iter2);
// should format ok with no iterator
str2.remove();
decFmt->format(num, str2, NULL, status);
assertEquals("null fpiter", str1, str2);
delete decFmt;
}
@ -5886,7 +5891,7 @@ void NumberFormatTest::TestFormatAttributes() {
FieldPositionIterator posIter;
UnicodeString result;
decFmt->format(val, result, posIter, status);
decFmt->format(val, result, &posIter, status);
expectPositions(posIter, expected, tupleCount, result);
}
{
@ -5919,7 +5924,7 @@ void NumberFormatTest::TestFormatAttributes() {
FieldPositionIterator posIter;
UnicodeString result;
decFmt->format(val, result, posIter, status);
decFmt->format(val, result, &posIter, status);
expectPositions(posIter, expected, tupleCount, result);
}
{