ICU-8638 Merge some changes from r30194 to 4.8.1 so UCNV_NO_CONVERSION passes

X-SVN-Rev: 30381
This commit is contained in:
Michael Ow 2011-07-18 21:04:57 +00:00
parent d1fa046379
commit 43b819cc72
16 changed files with 140 additions and 139 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2008-2009, International Business Machines
* Copyright (C) 2008-2011, International Business Machines
* Corporation, Google and others. All Rights Reserved.
*
*******************************************************************************
@ -26,6 +26,8 @@
#include "unicode/ucnvsel.h"
#if !UCONFIG_NO_CONVERSION
#include <string.h>
#include "unicode/uchar.h"
@ -809,3 +811,5 @@ ucnvsel_selectForUTF8(const UConverterSelector* sel,
}
return selectForMask(sel, mask, status);
}
#endif // !UCONFIG_NO_CONVERSION

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2008-2010, International Business Machines
* Copyright (C) 2008-2011, International Business Machines
* Corporation, Google and others. All Rights Reserved.
*
*******************************************************************************
@ -19,8 +19,11 @@
#ifndef __ICU_UCNV_SEL_H__
#define __ICU_UCNV_SEL_H__
#include "unicode/uset.h"
#include "unicode/utypes.h"
#if !UCONFIG_NO_CONVERSION
#include "unicode/uset.h"
#include "unicode/utf16.h"
#include "unicode/uenum.h"
#include "unicode/ucnv.h"
@ -179,4 +182,6 @@ U_STABLE UEnumeration * U_EXPORT2
ucnvsel_selectForUTF8(const UConverterSelector* sel,
const char *s, int32_t length, UErrorCode *status);
#endif /* !UCONFIG_NO_CONVERSION */
#endif /* __ICU_UCNV_SEL_H__ */

View file

@ -52,7 +52,7 @@
#include "ustrenum.h"
#if !UCONFIG_NO_SERVICE
static U_NAMESPACE_QUALIFIER ICULocaleService* gService = NULL;
static icu::ICULocaleService* gService = NULL;
#endif
// INTERNAL - for cleanup
@ -437,7 +437,7 @@ protected:
} else {
ret->append((UChar)0x40); // '@' is a variant character
ret->append(UNICODE_STRING("calendar=", 9));
ret->append(UnicodeString(gCalTypes[getCalendarTypeForLocale(loc.getName())]));
ret->append(UnicodeString(gCalTypes[getCalendarTypeForLocale(loc.getName())], -1, US_INV));
}
return ret;
}
@ -3079,7 +3079,7 @@ Calendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const
if(U_FAILURE(status)) return 0;
Calendar *cal = clone();
if(!cal) { status = U_MEMORY_ALLOCATION_ERROR; return 0; }
cal->setLenient(TRUE);
cal->setLenient(TRUE);
cal->prepareGetActual(field,FALSE,status);
result = handleGetYearLength(cal->get(UCAL_EXTENDED_YEAR, status));
delete cal;
@ -3201,6 +3201,11 @@ int32_t Calendar::getActualHelper(UCalendarDateFields field, int32_t startValue,
if(U_FAILURE(status)) return startValue;
Calendar *work = clone();
if(!work) { status = U_MEMORY_ALLOCATION_ERROR; return startValue; }
// need to resolve time here, otherwise, fields set for actual limit
// may cause conflict with fields previously set (but not yet resolved).
work->complete(status);
work->setLenient(TRUE);
work->prepareGetActual(field, delta < 0, status);

View file

@ -159,9 +159,9 @@ CurrencyPluralInfo::getCurrencyPluralPattern(const UnicodeString& pluralCount,
(UnicodeString*)fPluralCountToCurrencyUnitPattern->get(pluralCount);
if (currencyPluralPattern == NULL) {
// fall back to "other"
if (pluralCount.compare(gPluralCountOther)) {
if (pluralCount.compare(gPluralCountOther, 5)) {
currencyPluralPattern =
(UnicodeString*)fPluralCountToCurrencyUnitPattern->get(gPluralCountOther);
(UnicodeString*)fPluralCountToCurrencyUnitPattern->get(UnicodeString(TRUE, gPluralCountOther, 5));
}
if (currencyPluralPattern == NULL) {
// no currencyUnitPatterns defined,
@ -291,15 +291,15 @@ CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& st
pattern->extract(0, pattern->length(), result_1, "UTF-8");
std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
#endif
pattern->findAndReplace(gPart0,
pattern->findAndReplace(UnicodeString(TRUE, gPart0, 3),
UnicodeString(numberStylePattern, numberStylePatternLen));
pattern->findAndReplace(gPart1, gTripleCurrencySign);
pattern->findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
if (hasSeparator) {
UnicodeString negPattern(patternChars, ptnLen);
negPattern.findAndReplace(gPart0,
negPattern.findAndReplace(UnicodeString(TRUE, gPart0, 3),
UnicodeString(negNumberStylePattern, negNumberStylePatternLen));
negPattern.findAndReplace(gPart1, gTripleCurrencySign);
negPattern.findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
pattern->append(gNumberPatternSeparator);
pattern->append(negPattern);
}
@ -308,7 +308,7 @@ CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& st
std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
#endif
fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount), pattern, status);
fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount, -1, US_INV), pattern, status);
}
}
}

View file

@ -433,7 +433,7 @@ DecimalFormat::construct(UErrorCode& status,
// For most locale, the patterns are probably the same for all
// plural count. If not, the right pattern need to be re-applied
// during format.
fCurrencyPluralInfo->getCurrencyPluralPattern("other", currencyPluralPatternForOther);
fCurrencyPluralInfo->getCurrencyPluralPattern(UNICODE_STRING("other", 5), currencyPluralPatternForOther);
patternUsed = &currencyPluralPatternForOther;
// TODO: not needed?
setCurrencyForSymbols();
@ -454,7 +454,7 @@ DecimalFormat::construct(UErrorCode& status,
// need it for mix parsing
setupCurrencyAffixPatterns(status);
// expanded affixes for plural names
if (patternUsed->indexOf(fgTripleCurrencySign) != -1) {
if (patternUsed->indexOf(fgTripleCurrencySign, 3, 0) != -1) {
setupCurrencyAffixes(*patternUsed, TRUE, TRUE, status);
}
}
@ -509,7 +509,7 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
*fPosPrefixPattern,
*fPosSuffixPattern,
UCURR_SYMBOL_NAME);
fAffixPatternsForCurrency->put("default", affixPtn, status);
fAffixPatternsForCurrency->put(UNICODE_STRING("default", 7), affixPtn, status);
}
// save the unique currency plural patterns of this locale.
@ -556,14 +556,13 @@ DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
const PluralRules* pluralRules = fCurrencyPluralInfo->getPluralRules();
StringEnumeration* keywords = pluralRules->getKeywords(status);
if (U_SUCCESS(status)) {
const char* pluralCountCh;
while ((pluralCountCh = keywords->next(NULL, status)) != NULL) {
const UnicodeString* pluralCount;
while ((pluralCount = keywords->snext(status)) != NULL) {
if ( U_SUCCESS(status) ) {
UnicodeString pluralCount = UnicodeString(pluralCountCh);
expandAffixAdjustWidth(&pluralCount);
expandAffixAdjustWidth(pluralCount);
AffixesForCurrency* affix = new AffixesForCurrency(
fNegativePrefix, fNegativeSuffix, fPositivePrefix, fPositiveSuffix);
fAffixesForCurrency->put(pluralCount, affix, status);
fAffixesForCurrency->put(*pluralCount, affix, status);
}
}
}
@ -584,16 +583,15 @@ DecimalFormat::setupCurrencyAffixes(const UnicodeString& pattern,
const PluralRules* pluralRules = fCurrencyPluralInfo->getPluralRules();
StringEnumeration* keywords = pluralRules->getKeywords(status);
if (U_SUCCESS(status)) {
const char* pluralCountCh;
while ((pluralCountCh = keywords->next(NULL, status)) != NULL) {
const UnicodeString* pluralCount;
while ((pluralCount = keywords->snext(status)) != NULL) {
if ( U_SUCCESS(status) ) {
UnicodeString pluralCount = UnicodeString(pluralCountCh);
UnicodeString ptn;
fCurrencyPluralInfo->getCurrencyPluralPattern(pluralCount, ptn);
applyPatternInternally(pluralCount, ptn, false, parseErr, status);
fCurrencyPluralInfo->getCurrencyPluralPattern(*pluralCount, ptn);
applyPatternInternally(*pluralCount, ptn, false, parseErr, status);
AffixesForCurrency* affix = new AffixesForCurrency(
fNegativePrefix, fNegativeSuffix, fPositivePrefix, fPositiveSuffix);
fPluralAffixesForCurrency->put(pluralCount, affix, status);
fPluralAffixesForCurrency->put(*pluralCount, affix, status);
}
}
}
@ -2726,7 +2724,7 @@ DecimalFormat::setCurrencyForSymbols() {
uprv_getStaticCurrencyName(intlCurrencySymbol, loc, currencySymbol, ec);
if (U_SUCCESS(ec)
&& getConstSymbol(DecimalFormatSymbols::kCurrencySymbol) == currencySymbol
&& getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == intlCurrencySymbol)
&& getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol) == UnicodeString(intlCurrencySymbol))
{
// Trap an error in mapping locale to currency. If we can't
// map, then don't fail and set the currency to "".
@ -2955,7 +2953,7 @@ void DecimalFormat::setFormatWidth(int32_t width) {
}
UnicodeString DecimalFormat::getPadCharacterString() const {
return fPad;
return UnicodeString(fPad);
}
void DecimalFormat::setPadCharacter(const UnicodeString &padChar) {
@ -3290,21 +3288,17 @@ 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
char pluralCountChar[10];
if (pluralCount->length() >= 10) {
break;
}
pluralCount->extract(0, pluralCount->length(), pluralCountChar);
CharString pluralCountChar;
pluralCountChar.appendInvariantChars(*pluralCount, ec);
UBool isChoiceFormat;
const UChar* s = ucurr_getPluralName(currencyUChars,
fSymbols != NULL ? fSymbols->getLocale().getName() :
Locale::getDefault().getName(), &isChoiceFormat,
pluralCountChar, &len, &ec);
pluralCountChar.data(), &len, &ec);
affix += UnicodeString(s, len);
handler.addAttribute(kCurrencyField, beginIdx, affix.length());
} else if(intl) {
affix += currencyUChars;
affix.append(currencyUChars, -1);
handler.addAttribute(kCurrencyField, beginIdx, affix.length());
} else {
int32_t len;
@ -3325,7 +3319,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
// return.
if (fCurrencyChoice == NULL) {
// TODO Replace double-check with proper thread-safe code
ChoiceFormat* fmt = new ChoiceFormat(s, ec);
ChoiceFormat* fmt = new ChoiceFormat(UnicodeString(s), ec);
if (U_SUCCESS(ec)) {
umtx_lock(NULL);
if (fCurrencyChoice == NULL) {
@ -3355,7 +3349,7 @@ void DecimalFormat::expandAffix(const UnicodeString& pattern,
} else {
// We only arrive here if the currency choice
// format in the locale data is INVALID.
affix += currencyUChars;
affix.append(currencyUChars, -1);
handler.addAttribute(kCurrencyField, beginIdx, affix.length());
}
}
@ -4519,7 +4513,7 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
if (fAffixPatternsForCurrency == NULL) {
setupCurrencyAffixPatterns(status);
}
if (pattern.indexOf(fgTripleCurrencySign) != -1) {
if (pattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
// only setup the affixes of the current pattern.
setupCurrencyAffixes(pattern, TRUE, FALSE, status);
}
@ -4650,7 +4644,7 @@ void DecimalFormat::setCurrencyInternally(const UChar* theCurrency,
void DecimalFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
// set the currency before compute affixes to get the right currency names
NumberFormat::setCurrency(theCurrency, ec);
if (fFormatPattern.indexOf(fgTripleCurrencySign) != -1) {
if (fFormatPattern.indexOf(fgTripleCurrencySign, 3, 0) != -1) {
UnicodeString savedPtn = fFormatPattern;
setupCurrencyAffixes(fFormatPattern, TRUE, TRUE, ec);
UParseError parseErr;

View file

@ -657,7 +657,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
if ( timeSkeleton.length() != 0 ) {
if ( dateSkeleton.length() == 0 ) {
// prefix with yMd
timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort]);
timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
UnicodeString pattern = fDtpng->getBestPattern(timeSkeleton, status);
if ( U_FAILURE(status) ) {
return;
@ -682,7 +682,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
// done
} else if ( dateSkeleton.length() == 0 ) {
// prefix with yMd
timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort]);
timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
UnicodeString pattern = fDtpng->getBestPattern(timeSkeleton, status);
if ( U_FAILURE(status) ) {
return;
@ -1349,7 +1349,8 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton,
DateIntervalInfo::parseSkeleton(inputSkeleton, inputSkeletonFieldWidth);
DateIntervalInfo::parseSkeleton(bestMatchSkeleton, bestMatchSkeletonFieldWidth);
if ( differenceInfo == 2 ) {
adjustedPtn.findAndReplace("v", "z");
adjustedPtn.findAndReplace(UnicodeString((UChar)0x76 /* v */),
UnicodeString((UChar)0x7a /* z */));
}
UBool inQuote = false;

View file

@ -267,43 +267,38 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
int32_t size = ures_getSize(itvDtPtnResource);
int32_t index;
for ( index = 0; index < size; ++index ) {
UResourceBundle* oneRes = ures_getByIndex(itvDtPtnResource, index,
NULL, &status);
LocalUResourceBundlePointer oneRes(ures_getByIndex(itvDtPtnResource, index,
NULL, &status));
if ( U_SUCCESS(status) ) {
const char* skeleton = ures_getKey(oneRes);
if ( skeleton == NULL ||
skeletonSet.geti(UnicodeString(skeleton)) == 1 ) {
ures_close(oneRes);
const char* skeleton = ures_getKey(oneRes.getAlias());
if (skeleton == NULL) {
continue;
}
skeletonSet.puti(UnicodeString(skeleton), 1, status);
UnicodeString skeletonUniStr(skeleton, -1, US_INV);
if ( skeletonSet.geti(skeletonUniStr) == 1 ) {
continue;
}
skeletonSet.puti(skeletonUniStr, 1, status);
if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) {
ures_close(oneRes);
continue; // fallback
}
UResourceBundle* intervalPatterns = ures_getByKey(
itvDtPtnResource, skeleton, NULL, &status);
LocalUResourceBundlePointer intervalPatterns(ures_getByKey(
itvDtPtnResource, skeleton, NULL, &status));
if ( U_FAILURE(status) ) {
ures_close(intervalPatterns);
ures_close(oneRes);
break;
}
if ( intervalPatterns == NULL ) {
ures_close(intervalPatterns);
ures_close(oneRes);
continue;
}
const UChar* pattern;
const char* key;
int32_t ptLength;
int32_t ptnNum = ures_getSize(intervalPatterns);
int32_t ptnNum = ures_getSize(intervalPatterns.getAlias());
int32_t ptnIndex;
for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) {
pattern = ures_getNextString(intervalPatterns, &ptLength, &key,
&status);
UnicodeString pattern =
ures_getNextUnicodeString(intervalPatterns.getAlias(), &key, &status);
if ( U_FAILURE(status) ) {
break;
}
@ -323,12 +318,10 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
calendarField = UCAL_MINUTE;
}
if ( calendarField != UCAL_FIELD_COUNT ) {
setIntervalPatternInternally(skeleton, calendarField, pattern,status);
setIntervalPatternInternally(skeletonUniStr, calendarField, pattern,status);
}
}
ures_close(intervalPatterns);
}
ures_close(oneRes);
}
}
ures_close(itvDtPtnResource);
@ -445,14 +438,8 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton,
const UnicodeString* inputSkeleton = &skeleton;
UnicodeString copySkeleton;
if ( skeleton.indexOf(CHAR_Z) != -1 ) {
UChar zstr[2];
UChar vstr[2];
zstr[0]=CHAR_Z;
vstr[0]=CHAR_V;
zstr[1]=0;
vstr[1]=0;
copySkeleton = skeleton;
copySkeleton.findAndReplace(zstr, vstr);
copySkeleton.findAndReplace(UnicodeString(CHAR_Z), UnicodeString(CHAR_V));
inputSkeleton = &copySkeleton;
replaceZWithV = true;
}

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* Copyright (C) 2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
* Copyright (C) 2010-2011, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -418,7 +418,7 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
appendWithSep(resultRemainder, keyDisplayName(key, temp))
.append("=")
.append((UChar)0x3d /* = */)
.append(keyValueDisplayName(key, value, temp2));
}
delete e;

View file

@ -1100,10 +1100,10 @@ SimpleDateFormat::parseGMT(const UnicodeString &text, ParsePosition &pos) const
void
SimpleDateFormat::formatGMTDefault(NumberFormat *currentNumberFormat,UnicodeString &appendTo, int32_t offset) const {
if (offset < 0) {
appendTo += gGmtMinus;
appendTo.append(gGmtMinus, 4);
offset = -offset; // suppress the '-' sign for text display.
}else{
appendTo += gGmtPlus;
appendTo.append(gGmtPlus, 4);
}
offset /= U_MILLIS_PER_SECOND; // now in seconds
@ -3058,7 +3058,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
// next step. Otherwise, all time zone names starting with GMT/UT/UTC
// (for example, "UTT") will fail.
if (gmtLen > 0 && ((text.length() - start) == gmtLen)) {
TimeZone *tz = TimeZone::createTimeZone(UnicodeString("Etc/GMT"));
TimeZone *tz = TimeZone::createTimeZone(UNICODE_STRING("Etc/GMT", 7));
cal.adoptTimeZone(tz);
return start + gmtLen;
}
@ -3115,7 +3115,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
// Step 5
// If we saw standalone GMT zero pattern, then use GMT.
if (gmtLen > 0) {
TimeZone *tz = TimeZone::createTimeZone(UnicodeString("Etc/GMT"));
TimeZone *tz = TimeZone::createTimeZone(UNICODE_STRING("Etc/GMT", 7));
cal.adoptTimeZone(tz);
return start + gmtLen;
}
@ -3178,7 +3178,7 @@ void SimpleDateFormat::parseInt(const UnicodeString& text,
DecimalFormat* df = NULL;
if (!allowNegative && (df = dynamic_cast<DecimalFormat*>(fmt)) != NULL) {
df->getNegativePrefix(oldPrefix);
df->setNegativePrefix(SUPPRESS_NEGATIVE_PREFIX);
df->setNegativePrefix(UnicodeString(TRUE, SUPPRESS_NEGATIVE_PREFIX, -1));
}
int32_t oldPos = pos.getIndex();
fmt->parse(text, number, pos);
@ -3264,7 +3264,9 @@ UnicodeString&
SimpleDateFormat::toLocalizedPattern(UnicodeString& result,
UErrorCode& status) const
{
translatePattern(fPattern, result, DateFormatSymbols::getPatternUChars(), fSymbols->fLocalPatternChars, status);
translatePattern(fPattern, result,
UnicodeString(DateFormatSymbols::getPatternUChars()),
fSymbols->fLocalPatternChars, status);
return result;
}
@ -3282,7 +3284,9 @@ void
SimpleDateFormat::applyLocalizedPattern(const UnicodeString& pattern,
UErrorCode &status)
{
translatePattern(pattern, fPattern, fSymbols->fLocalPatternChars, DateFormatSymbols::getPatternUChars(), status);
translatePattern(pattern, fPattern,
fSymbols->fLocalPatternChars,
UnicodeString(DateFormatSymbols::getPatternUChars()), status);
}
//----------------------------------------------------------------------

View file

@ -33,27 +33,27 @@ SimpleDateFormatStaticSets::SimpleDateFormatStaticSets(UErrorCode *status)
fTimeIgnorables(NULL),
fOtherIgnorables(NULL)
{
fDateIgnorables = new UnicodeSet("[-,./[:whitespace:]]", *status);
fTimeIgnorables = new UnicodeSet("[-.:[:whitespace:]]", *status);
fOtherIgnorables = new UnicodeSet("[:whitespace:]", *status);
fDateIgnorables = new UnicodeSet(UNICODE_STRING("[-,./[:whitespace:]]", 20), *status);
fTimeIgnorables = new UnicodeSet(UNICODE_STRING("[-.:[:whitespace:]]", 19), *status);
fOtherIgnorables = new UnicodeSet(UNICODE_STRING("[:whitespace:]", 14), *status);
// Check for null pointers
if (fDateIgnorables == NULL || fTimeIgnorables == NULL || fOtherIgnorables == NULL) {
goto ExitConstrDeleteAll;
}
// Freeze all the sets
fDateIgnorables->freeze();
fTimeIgnorables->freeze();
fOtherIgnorables->freeze();
return; // If we reached this point, everything is fine so just exit
ExitConstrDeleteAll: // Remove all sets and return error
delete fDateIgnorables; fDateIgnorables = NULL;
delete fTimeIgnorables; fTimeIgnorables = NULL;
delete fOtherIgnorables; fOtherIgnorables = NULL;
*status = U_MEMORY_ALLOCATION_ERROR;
}

View file

@ -11,6 +11,7 @@
#if !UCONFIG_NO_FORMATTING
#include "charstr.h"
#include "cmemory.h"
#include "cstring.h"
#include "hash.h"
@ -324,11 +325,11 @@ TimeUnitFormat::parseObject(const UnicodeString& source,
*/
if (withNumberFormat == false && longestParseDistance != 0) {
// set the number using plurrual count
if ( *countOfLongestMatch == PLURAL_COUNT_ZERO ) {
if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ZERO, 4)) {
resultNumber = 0;
} else if ( *countOfLongestMatch == PLURAL_COUNT_ONE ) {
} else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ONE, 3)) {
resultNumber = 1;
} else if ( *countOfLongestMatch == PLURAL_COUNT_TWO ) {
} else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_TWO, 3)) {
resultNumber = 2;
} else {
// should not happen.
@ -480,13 +481,11 @@ TimeUnitFormat::readFromCurrentLocale(UTimeUnitFormatStyle style, const char* ke
}
}
int32_t count = ures_getSize(countsToPatternRB);
const UChar* pattern;
const char* pluralCount;
int32_t ptLength;
for ( int32_t pluralIndex = 0; pluralIndex < count; ++pluralIndex) {
// resource of count to pattern
pattern = ures_getNextString(countsToPatternRB, &ptLength,
&pluralCount, &status);
UnicodeString pattern =
ures_getNextUnicodeString(countsToPatternRB, &pluralCount, &status);
if (U_FAILURE(status)) {
continue;
}
@ -495,12 +494,13 @@ TimeUnitFormat::readFromCurrentLocale(UTimeUnitFormatStyle style, const char* ke
if (fNumberFormat != NULL) {
messageFormat->setFormat(0, *fNumberFormat);
}
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(pluralCount);
UnicodeString pluralCountUniStr(pluralCount, -1, US_INV);
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(pluralCountUniStr);
if (formatters == NULL) {
formatters = (MessageFormat**)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*));
formatters[UTMUTFMT_FULL_STYLE] = NULL;
formatters[UTMUTFMT_ABBREVIATED_STYLE] = NULL;
countToPatterns->put(pluralCount, formatters, err);
countToPatterns->put(pluralCountUniStr, formatters, err);
if (U_FAILURE(err)) {
uprv_free(formatters);
}
@ -557,8 +557,8 @@ TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UE
//
StringEnumeration* keywords = fPluralRules->getKeywords(err);
if (U_SUCCESS(err)) {
const char* pluralCount;
while ((pluralCount = keywords->next(NULL, err)) != NULL) {
const UnicodeString* pluralCount;
while ((pluralCount = keywords->snext(err)) != NULL) {
if ( U_SUCCESS(err) ) {
for (int32_t i = 0; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; ++i) {
// for each time unit,
@ -572,13 +572,15 @@ TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UE
}
fTimeUnitToCountToPatterns[i] = countToPatterns;
}
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(pluralCount);
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(*pluralCount);
if( formatters == NULL || formatters[style] == NULL ) {
// look through parents
const char* localeName = fLocale.getName();
CharString pluralCountChars;
pluralCountChars.appendInvariantChars(*pluralCount, err);
searchInLocaleChain(style, key, localeName,
(TimeUnit::UTimeUnitFields)i,
pluralCount, pluralCount,
*pluralCount, pluralCountChars.data(),
countToPatterns, err);
}
}
@ -601,7 +603,7 @@ TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UE
void
TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
TimeUnit::UTimeUnitFields srcTimeUnitField,
const char* srcPluralCount,
const UnicodeString& srcPluralCount,
const char* searchPluralCount,
Hashtable* countToPatterns,
UErrorCode& err) {
@ -625,7 +627,7 @@ TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key,
pattern = ures_getStringByKeyWithFallback(countsToPatternRB, searchPluralCount, &ptLength, &status);
if (U_SUCCESS(status)) {
//found
MessageFormat* messageFormat = new MessageFormat(pattern, fLocale, err);
MessageFormat* messageFormat = new MessageFormat(UnicodeString(TRUE, pattern, ptLength), fLocale, err);
if (U_SUCCESS(err)) {
if (fNumberFormat != NULL) {
messageFormat->setFormat(0, *fNumberFormat);
@ -686,20 +688,24 @@ TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key,
if ( uprv_strcmp(searchPluralCount, gPluralCountOther) == 0 ) {
// set default fall back the same as the resource in root
MessageFormat* messageFormat = NULL;
const UChar *pattern = NULL;
if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_SECOND ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_SECOND, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_SECOND;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MINUTE ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_MINUTE, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_MINUTE;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_HOUR ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_HOUR, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_HOUR;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_WEEK ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_WEEK, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_WEEK;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_DAY ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_DAY, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_DAY;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MONTH ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_MONTH, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_MONTH;
} else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_YEAR ) {
messageFormat = new MessageFormat(DEFAULT_PATTERN_FOR_YEAR, fLocale, err);
pattern = DEFAULT_PATTERN_FOR_YEAR;
}
if (pattern != NULL) {
messageFormat = new MessageFormat(UnicodeString(TRUE, pattern, -1), fLocale, err);
}
if (U_SUCCESS(err)) {
if (fNumberFormat != NULL && messageFormat != NULL) {

View file

@ -77,8 +77,8 @@ static UBool U_CALLCONV timeZoneNames_cleanup(void)
*/
static void U_CALLCONV
deleteTimeZoneNamesCacheEntry(void *obj) {
U_NAMESPACE_QUALIFIER TimeZoneNamesCacheEntry *entry = (U_NAMESPACE_QUALIFIER TimeZoneNamesCacheEntry*)obj;
delete (U_NAMESPACE_QUALIFIER TimeZoneNamesImpl*) entry->names;
icu::TimeZoneNamesCacheEntry *entry = (icu::TimeZoneNamesCacheEntry*)obj;
delete (icu::TimeZoneNamesImpl*) entry->names;
uprv_free(entry);
}
U_CDECL_END
@ -132,7 +132,7 @@ TimeZoneNamesDelegate::TimeZoneNamesDelegate(const Locale& locale, UErrorCode& s
if (!gTimeZoneNamesCacheInitialized) {
gTimeZoneNamesCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
if (U_SUCCESS(status)) {
uhash_setKeyDeleter(gTimeZoneNamesCache, uhash_freeBlock);
uhash_setKeyDeleter(gTimeZoneNamesCache, uprv_free);
uhash_setValueDeleter(gTimeZoneNamesCache, deleteTimeZoneNamesCacheEntry);
gTimeZoneNamesCacheInitialized = TRUE;
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONENAMES, timeZoneNames_cleanup);
@ -277,7 +277,8 @@ TimeZoneNames::getExemplarLocationName(const UnicodeString& tzID, UnicodeString&
int32_t sep = tzID.lastIndexOf((UChar)0x2F /* '/' */);
if (sep > 0 && sep + 1 < tzID.length()) {
name.setTo(tzID, sep + 1);
name.findAndReplace("_", " ");
name.findAndReplace(UnicodeString((UChar)0x5f /* _ */),
UnicodeString((UChar)0x20 /* space */));
} else {
name.setToBogus();
}

View file

@ -707,7 +707,7 @@ MetaZoneIDsEnumeration::MetaZoneIDsEnumeration(UVector *mzIDs)
const UnicodeString*
MetaZoneIDsEnumeration::snext(UErrorCode& status) {
if (U_SUCCESS(status) && fMetaZoneIDs != NULL && fPos < fLen) {
unistr.setTo((const UChar*)fMetaZoneIDs->elementAt(fPos++));
unistr.setTo((const UChar*)fMetaZoneIDs->elementAt(fPos++), -1);
return &unistr;
}
return NULL;
@ -866,7 +866,7 @@ ZNameSearchHandler::handleMatch(int32_t matchLength, const CharacterNode *node,
if ((nameinfo->type & fTypes) != 0) {
// matches a requested type
if (fResults == NULL) {
fResults = new UVector(uhash_freeBlock, NULL, status);
fResults = new UVector(uprv_free, NULL, status);
if (fResults == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
@ -1090,7 +1090,7 @@ TimeZoneNamesImpl::getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeS
UnicodeString&
TimeZoneNamesImpl::getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const {
ZoneMeta::getZoneIdByMetazone(mzID, UnicodeString(region), tzID);
ZoneMeta::getZoneIdByMetazone(mzID, UnicodeString(region, -1, US_INV), tzID);
return tzID;
}

View file

@ -25,12 +25,6 @@
#include "unicode/numfmt.h"
#include "unicode/plurrule.h"
/**
* @internal ICU 4.2
*/
union UHashTok;
/**
* Constants for various styles.
* There are 2 styles: full name and abbreviated name.
@ -243,7 +237,7 @@ private:
// fill in fTimeUnitToCountToPatterns from locale fall-back chain
void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
TimeUnit::UTimeUnitFields field, const char*,
TimeUnit::UTimeUnitFields field, const UnicodeString&,
const char*, Hashtable*, UErrorCode&);
// initialize hash table

View file

@ -233,19 +233,21 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
// Capture Group 8: A syntactically invalid line. Anything that didn't match before.
// Example Line from the confusables.txt source file:
// "1D702 ; 006E 0329 ; SL # MATHEMATICAL ITALIC SMALL ETA ... "
fParseLine = uregex_openC(
UnicodeString pattern(
"(?m)^[ \\t]*([0-9A-Fa-f]+)[ \\t]+;" // Match the source char
"[ \\t]*([0-9A-Fa-f]+" // Match the replacement char(s)
"(?:[ \\t]+[0-9A-Fa-f]+)*)[ \\t]*;" // (continued)
"\\s*(?:(SL)|(SA)|(ML)|(MA))" // Match the table type
"[ \\t]*(?:#.*?)?$" // Match any trailing #comment
"|^([ \\t]*(?:#.*?)?)$" // OR match empty lines or lines with only a #comment
"|^(.*?)$", // OR match any line, which catches illegal lines.
0, NULL, &status);
"|^(.*?)$", -1, US_INV); // OR match any line, which catches illegal lines.
// TODO: Why are we using the regex C API here? C++ would just take UnicodeString...
fParseLine = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
// Regular expression for parsing a hex number out of a space-separated list of them.
// Capture group 1 gets the number, with spaces removed.
fParseHexNum = uregex_openC("\\s*([0-9A-F]+)", 0, NULL, &status);
pattern = UNICODE_STRING_SIMPLE("\\s*([0-9A-F]+)");
fParseHexNum = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
// Zap any Byte Order Mark at the start of input. Changing it to a space is benign
// given the syntax of the input.

View file

@ -52,7 +52,6 @@ U_NAMESPACE_USE
// The expression will match _all_ lines, including erroneous lines.
// The result of the parse is returned via the contents of the (match) groups.
static const char *parseExp =
"(?m)" // Multi-line mode
"^([ \\t]*(?:#.*?)?)$" // A blank or comment line. Matches Group 1.
"|^(?:" // OR
@ -115,7 +114,8 @@ void buildWSConfusableData(SpoofImpl *spImpl, const char * confusablesWS,
anyCaseTrie = utrie2_open(0, 0, &status);
lowerCaseTrie = utrie2_open(0, 0, &status);
UnicodeString pattern(parseExp, -1, US_INV);
// The scriptSets vector provides a mapping from TRIE values to the set of scripts.
//
@ -150,10 +150,8 @@ void buildWSConfusableData(SpoofImpl *spImpl, const char * confusablesWS,
}
u_strFromUTF8(input, inputLen+1, NULL, confusablesWS, confusablesWSLen, &status);
parseRegexp = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
parseRegexp = uregex_openC(parseExp, 0, NULL, &status);
// Zap any Byte Order Mark at the start of input. Changing it to a space is benign
// given the syntax of the input.
if (*input == 0xfeff) {