ICU-7457 replace MessageFormat with SimpleFormatter where easy; remove obsolete ChoiceFormat handling of currency names; move LocaleDisplayNames & ucurr from i18n to common

X-SVN-Rev: 38200
This commit is contained in:
Markus Scherer 2016-01-26 22:56:59 +00:00
parent dcb76aab72
commit bb5f37a069
25 changed files with 247 additions and 409 deletions

View file

@ -85,7 +85,8 @@ ucnv.o ucnv_bld.o ucnv_cnv.o ucnv_io.o ucnv_cb.o ucnv_err.o ucnvlat1.o \
ucnv_u7.o ucnv_u8.o ucnv_u16.o ucnv_u32.o ucnvscsu.o ucnvbocu.o \
ucnv_ext.o ucnvmbcs.o ucnv2022.o ucnvhz.o ucnv_lmb.o ucnvisci.o ucnvdisp.o ucnv_set.o ucnv_ct.o \
resource.o uresbund.o ures_cnv.o uresdata.o resbund.o resbund_cnv.o \
messagepattern.o ucat.o locmap.o uloc.o locid.o locutil.o locavailable.o locdispnames.o loclikely.o locresdata.o \
ucurr.o \
messagepattern.o ucat.o locmap.o uloc.o locid.o locutil.o locavailable.o locdispnames.o locdspnm.o loclikely.o locresdata.o \
bytestream.o stringpiece.o \
stringtriebuilder.o bytestriebuilder.o \
bytestrie.o bytestrieiterator.o \

View file

@ -365,6 +365,7 @@
</ClCompile>
<ClCompile Include="locbased.cpp" />
<ClCompile Include="locdispnames.cpp" />
<ClCompile Include="locdspnm.cpp" />
<ClCompile Include="locid.cpp">
</ClCompile>
<ClCompile Include="loclikely.cpp" />
@ -381,6 +382,7 @@
<ClCompile Include="uresbund.cpp" />
<ClCompile Include="uresdata.cpp" />
<ClCompile Include="resource.cpp" />
<ClCompile Include="ucurr.cpp" />
<ClCompile Include="caniter.cpp">
</ClCompile>
<ClCompile Include="filterednormalizer2.cpp" />
@ -1089,6 +1091,20 @@
</CustomBuild>
<ClInclude Include="sharedobject.h" />
<ClCompile Include="sharedobject.cpp" />
<CustomBuild Include="unicode\locdspnm.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\simpleformatter.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
@ -1114,6 +1130,34 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\udisplaycontext.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\uldnames.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
@ -1151,6 +1195,21 @@
<ClInclude Include="uresimp.h" />
<ClInclude Include="ureslocs.h" />
<ClInclude Include="resource.h" />
<CustomBuild Include="unicode\ucurr.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<ClInclude Include="ucurrimp.h" />
<CustomBuild Include="unicode\caniter.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>

View file

@ -277,12 +277,18 @@
<ClCompile Include="dtintrv.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="locdspnm.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="parsepos.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="simpleformatter.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="ucurr.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="ustrfmt.c">
<Filter>formatting</Filter>
</ClCompile>
@ -751,6 +757,9 @@
<ClInclude Include="umapfile.h">
<Filter>data &amp; memory</Filter>
</ClInclude>
<CustomBuild Include="unicode\locdspnm.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\simpleformatter.h">
<Filter>formatting</Filter>
</CustomBuild>
@ -760,6 +769,18 @@
<ClInclude Include="util.h">
<Filter>formatting</Filter>
</ClInclude>
<CustomBuild Include="unicode\ucurr.h">
<Filter>formatting</Filter>
</CustomBuild>
<ClInclude Include="ucurrimp.h">
<Filter>formatting</Filter>
</ClInclude>
<CustomBuild Include="unicode\udisplaycontext.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\uldnames.h">
<Filter>formatting</Filter>
</CustomBuild>
<ClInclude Include="punycode.h">
<Filter>idna</Filter>
</ClInclude>

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2010-2014, International Business Machines Corporation and
* Copyright (C) 2010-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -10,11 +10,11 @@
#if !UCONFIG_NO_FORMATTING
#include "unicode/locdspnm.h"
#include "unicode/msgfmt.h"
#include "unicode/simpleformatter.h"
#include "unicode/ures.h"
#include "unicode/udisplaycontext.h"
#include "unicode/brkiter.h"
#include "unicode/ucurr.h"
#include "cmemory.h"
#include "cstring.h"
#include "mutex.h"
@ -274,9 +274,9 @@ class LocaleDisplayNamesImpl : public LocaleDisplayNames {
UDialectHandling dialectHandling;
ICUDataTable langData;
ICUDataTable regionData;
MessageFormat *separatorFormat;
MessageFormat *format;
MessageFormat *keyTypeFormat;
SimpleFormatter separatorFormat;
SimpleFormatter format;
SimpleFormatter keyTypeFormat;
UDisplayContext capitalizationContext;
BreakIterator* capitalizationBrkIter;
static UMutex capitalizationBrkIterLock;
@ -344,9 +344,6 @@ LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
: dialectHandling(dialectHandling)
, langData(U_ICUDATA_LANG, locale)
, regionData(U_ICUDATA_REGION, locale)
, separatorFormat(NULL)
, format(NULL)
, keyTypeFormat(NULL)
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
, capitalizationBrkIter(NULL)
, nameLength(UDISPCTX_LENGTH_FULL)
@ -359,9 +356,6 @@ LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
: dialectHandling(ULDN_STANDARD_NAMES)
, langData(U_ICUDATA_LANG, locale)
, regionData(U_ICUDATA_REGION, locale)
, separatorFormat(NULL)
, format(NULL)
, keyTypeFormat(NULL)
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
, capitalizationBrkIter(NULL)
, nameLength(UDISPCTX_LENGTH_FULL)
@ -399,14 +393,14 @@ LocaleDisplayNamesImpl::initialize(void) {
sep = UnicodeString("{0}, {1}", -1, US_INV);
}
UErrorCode status = U_ZERO_ERROR;
separatorFormat = new MessageFormat(sep, status);
separatorFormat.applyPatternMinMaxArguments(sep, 2, 2, status);
UnicodeString pattern;
langData.getNoFallback("localeDisplayPattern", "pattern", pattern);
if (pattern.isBogus()) {
pattern = UnicodeString("{0} ({1})", -1, US_INV);
}
format = new MessageFormat(pattern, status);
format.applyPatternMinMaxArguments(pattern, 2, 2, status);
if (pattern.indexOf((UChar)0xFF08) >= 0) {
formatOpenParen.setTo((UChar)0xFF08); // fullwidth (
formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [
@ -424,7 +418,7 @@ LocaleDisplayNamesImpl::initialize(void) {
if (ktPattern.isBogus()) {
ktPattern = UnicodeString("{0}={1}", -1, US_INV);
}
keyTypeFormat = new MessageFormat(ktPattern, status);
keyTypeFormat.applyPatternMinMaxArguments(ktPattern, 2, 2, status);
uprv_memset(fCapitalization, 0, sizeof(fCapitalization));
#if !UCONFIG_NO_BREAK_ITERATION
@ -494,9 +488,6 @@ LocaleDisplayNamesImpl::initialize(void) {
}
LocaleDisplayNamesImpl::~LocaleDisplayNamesImpl() {
delete separatorFormat;
delete format;
delete keyTypeFormat;
delete capitalizationBrkIter;
}
@ -593,7 +584,6 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString resultRemainder;
UnicodeString temp;
StringEnumeration *e = NULL;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
@ -608,13 +598,16 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen);
resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen);
e = locale.createKeywords(status);
if (e && U_SUCCESS(status)) {
LocalPointer<StringEnumeration> e(locale.createKeywords(status));
if (e.isValid() && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
if (U_FAILURE(status)) {
return result;
}
keyDisplayName(key, temp);
temp.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp.findAndReplace(formatCloseParen, formatReplaceCloseParen);
@ -625,13 +618,7 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
Formattable data[] = {
temp,
temp2
};
FieldPosition fpos;
status = U_ZERO_ERROR;
keyTypeFormat->format(data, 2, temp3, fpos, status);
keyTypeFormat.format(temp, temp2, temp3, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
@ -639,17 +626,10 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
.append(temp2);
}
}
delete e;
}
if (!resultRemainder.isEmpty()) {
Formattable data[] = {
resultName,
resultRemainder
};
FieldPosition fpos;
status = U_ZERO_ERROR;
format->format(data, 2, result, fpos, status);
format.format(resultName, resultRemainder, result.remove(), status);
return adjustForUsageAndContext(kCapContextUsageLanguage, result);
}
@ -662,17 +642,9 @@ LocaleDisplayNamesImpl::appendWithSep(UnicodeString& buffer, const UnicodeString
if (buffer.isEmpty()) {
buffer.setTo(src);
} else {
UnicodeString combined;
Formattable data[] = {
buffer,
src
};
FieldPosition fpos;
const UnicodeString *values[2] = { &buffer, &src };
UErrorCode status = U_ZERO_ERROR;
separatorFormat->format(data, 2, combined, fpos, status);
if (U_SUCCESS(status)) {
buffer.setTo(combined);
}
separatorFormat.formatAndReplace(values, 2, buffer, NULL, 0, status);
}
return buffer;
}

View file

@ -1,9 +1,7 @@
/*
******************************************************************************
* *
* Copyright (C) 2001-2014, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
* Copyright (C) 2001-2016, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: ucln_cmn.h
* encoding: US-ASCII
@ -41,6 +39,7 @@ typedef enum ECleanupCommonType {
UCLN_COMMON_LOCALE,
UCLN_COMMON_LOCALE_AVAILABLE,
UCLN_COMMON_ULOC,
UCLN_COMMON_CURRENCY,
UCLN_COMMON_LOADED_NORMALIZER2,
UCLN_COMMON_NORMALIZER2,
UCLN_COMMON_USET,

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2014, International Business Machines
* Copyright (c) 2002-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -13,14 +13,13 @@
#include "unicode/locid.h"
#include "unicode/ures.h"
#include "unicode/ustring.h"
#include "unicode/choicfmt.h"
#include "unicode/parsepos.h"
#include "ustr_imp.h"
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
#include "umutex.h"
#include "ucln_in.h"
#include "ucln_cmn.h"
#include "uenumimp.h"
#include "uhash.h"
#include "hash.h"
@ -103,12 +102,6 @@ static const char VAR_DELIM_STR[] = "_";
static const char CURRENCIES[] = "Currencies";
static const char CURRENCYPLURALS[] = "CurrencyPlurals";
// Marker character indicating that a display name is a ChoiceFormat
// pattern. Strings that start with one mark are ChoiceFormat
// patterns. Strings that start with 2 marks are static strings, and
// the first mark is deleted.
static const UChar CHOICE_FORMAT_MARK = 0x003D; // Equals sign
static const UChar EUR_STR[] = {0x0045,0x0055,0x0052,0};
// ISO codes mapping table
@ -432,7 +425,7 @@ struct CReg : public icu::UMemory {
umtx_lock(&gCRegLock);
if (!gCRegHead) {
/* register for the first time */
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
}
n->next = gCRegHead;
gCRegHead = n;
@ -469,7 +462,7 @@ struct CReg : public icu::UMemory {
CReg* p = gCRegHead;
/* register cleanup of the mutex */
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
while (p) {
if (uprv_strcmp(id, p->id) == 0) {
result = p->iso;
@ -740,20 +733,11 @@ ucurr_getName(const UChar* currency,
}
}
// Determine if this is a ChoiceFormat pattern. One leading mark
// indicates a ChoiceFormat. Two indicates a static string that
// starts with a mark. In either case, the first mark is ignored,
// if present. Marks in the rest of the string have no special
// meaning.
// We no longer support choice format data in names. Data should not contain
// choice patterns.
*isChoiceFormat = FALSE;
if (U_SUCCESS(ec2)) {
U_ASSERT(s != NULL);
int32_t i=0;
while (i < *len && s[i] == CHOICE_FORMAT_MARK && i < 2) {
++i;
}
*isChoiceFormat = (i == 1);
if (i != 0) ++s; // Skip over first mark
return s;
}
@ -915,26 +899,10 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_
UResourceBundle* names = ures_getByIndex(curr, i, NULL, &ec2);
int32_t len;
s = ures_getStringByIndex(names, UCURR_SYMBOL_NAME, &len, &ec2);
UBool isChoice = FALSE;
if (len > 0 && s[0] == CHOICE_FORMAT_MARK) {
++s;
--len;
if (len > 0 && s[0] != CHOICE_FORMAT_MARK) {
isChoice = TRUE;
}
++(*total_currency_symbol_count); // currency symbol
if (currencySymbolsEquiv != NULL) {
*total_currency_symbol_count += countEquivalent(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
}
if (isChoice) {
ChoiceFormat fmt(UnicodeString(TRUE, s, len), ec2);
int32_t fmt_count;
fmt.getFormats(fmt_count);
*total_currency_symbol_count += fmt_count;
} else {
++(*total_currency_symbol_count); // currency symbol
if (currencySymbolsEquiv != NULL) {
*total_currency_symbol_count += countEquivalent(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
}
}
++(*total_currency_symbol_count); // iso code
++(*total_currency_name_count); // long name
ures_close(names);
@ -1047,44 +1015,20 @@ collectCurrencyNames(const char* locale,
uhash_put(currencyIsoCodes, iso, iso, &ec3);
}
}
UBool isChoice = FALSE;
if (len > 0 && s[0] == CHOICE_FORMAT_MARK) {
++s;
--len;
if (len > 0 && s[0] != CHOICE_FORMAT_MARK) {
isChoice = TRUE;
}
}
if (isChoice) {
ChoiceFormat fmt(UnicodeString(TRUE, s, len), ec2);
int32_t fmt_count;
const UnicodeString* formats = fmt.getFormats(fmt_count);
for (int i = 0; i < fmt_count; ++i) {
// put iso, formats[i]; into array
int32_t length = formats[i].length();
UChar* name = (UChar*)uprv_malloc(sizeof(UChar)*length);
formats[i].extract(0, length, name);
// Add currency symbol.
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = (UChar*)s;
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = len;
// Add equivalent symbols
if (currencySymbolsEquiv != NULL) {
icu::EquivIterator iter(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
const UnicodeString *symbol;
while ((symbol = iter.next()) != NULL) {
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = name;
(*currencySymbols)[*total_currency_symbol_count].flag = NEED_TO_BE_DELETED;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = length;
}
} else {
// Add currency symbol.
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = (UChar*)s;
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = len;
// Add equivalent symbols
if (currencySymbolsEquiv != NULL) {
icu::EquivIterator iter(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
const UnicodeString *symbol;
while ((symbol = iter.next()) != NULL) {
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = (UChar*) symbol->getBuffer();
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = symbol->length();
}
(*currencySymbols)[*total_currency_symbol_count].currencyName = (UChar*) symbol->getBuffer();
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = symbol->length();
}
}
@ -1528,8 +1472,7 @@ uprv_parseCurrency(const char* locale,
cacheEntry->totalCurrencySymbolCount = total_currency_symbol_count;
cacheEntry->refCount = 2; // one for cache, one for reference
currentCacheEntryIndex = (currentCacheEntryIndex + 1) % CURRENCY_NAME_CACHE_NUM;
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cache_cleanup);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cache_cleanup);
} else {
deleteCurrencyNames(currencyNames, total_currency_name_count);
deleteCurrencyNames(currencySymbols, total_currency_symbol_count);
@ -1617,19 +1560,7 @@ uprv_getStaticCurrencyName(const UChar* iso, const char* loc,
const UChar* currname = ucurr_getName(iso, loc, UCURR_SYMBOL_NAME,
&isChoiceFormat, &len, &ec);
if (U_SUCCESS(ec)) {
// If this is a ChoiceFormat currency, then format an
// arbitrary value; pick something != 1; more common.
result.truncate(0);
if (isChoiceFormat) {
ChoiceFormat f(UnicodeString(TRUE, currname, len), ec);
if (U_SUCCESS(ec)) {
f.format(2.0, result);
} else {
result.setTo(iso, -1);
}
} else {
result.setTo(currname, -1);
}
result.setTo(currname, len);
}
}
@ -2167,7 +2098,7 @@ U_CDECL_END
static void U_CALLCONV initIsoCodes(UErrorCode &status) {
U_ASSERT(gIsoCodes == NULL);
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
UHashtable *isoCodes = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
if (U_FAILURE(status)) {
@ -2202,7 +2133,7 @@ static void populateCurrSymbolsEquiv(icu::Hashtable *hash, UErrorCode &status) {
static void U_CALLCONV initCurrSymbolsEquiv() {
U_ASSERT(gCurrSymbolsEquiv == NULL);
UErrorCode status = U_ZERO_ERROR;
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
icu::Hashtable *temp = new icu::Hashtable(status);
if (temp == NULL) {
return;

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2011, International Business Machines
* Copyright (c) 2002-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 2010-2014, International Business Machines Corporation and
* Copyright (C) 2010-2016, International Business Machines Corporation and
* others. All Rights Reserved.
******************************************************************************
*/
@ -30,7 +30,7 @@ U_NAMESPACE_BEGIN
* values, see Locale.
* @stable ICU 4.4
*/
class U_I18N_API LocaleDisplayNames : public UObject {
class U_COMMON_API LocaleDisplayNames : public UObject {
public:
/**
* Destructor.

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2015, International Business Machines
* Copyright (c) 2002-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -13,6 +13,21 @@
/**
* \file
* \brief C API: Encapsulates information about a currency.
*
* The ucurr API encapsulates information about a currency, as defined by
* ISO 4217. A currency is represented by a 3-character string
* containing its ISO 4217 code. This API can return various data
* necessary the proper display of a currency:
*
* <ul><li>A display symbol, for a specific locale
* <li>The number of fraction digits to display
* <li>A rounding increment
* </ul>
*
* The <tt>DecimalFormat</tt> class uses these data to display
* currencies.
* @author Alan Liu
* @since ICU 2.2
*/
#if !UCONFIG_NO_FORMATTING
@ -43,23 +58,6 @@ enum UCurrencyUsage {
};
typedef enum UCurrencyUsage UCurrencyUsage;
/**
* The ucurr API encapsulates information about a currency, as defined by
* ISO 4217. A currency is represented by a 3-character string
* containing its ISO 4217 code. This API can return various data
* necessary the proper display of a currency:
*
* <ul><li>A display symbol, for a specific locale
* <li>The number of fraction digits to display
* <li>A rounding increment
* </ul>
*
* The <tt>DecimalFormat</tt> class uses these data to display
* currencies.
* @author Alan Liu
* @since ICU 2.2
*/
/**
* Finds a currency code for the given locale.
* @param locale the locale for which to retrieve a currency code.

View file

@ -1,6 +1,6 @@
/*
*****************************************************************************************
* Copyright (C) 2014-2015, International Business Machines
* Copyright (C) 2014-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*****************************************************************************************
*/

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* Copyright (C) 2010-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
* Copyright (C) 2010-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/

View file

@ -1,6 +1,6 @@
#******************************************************************************
#
# Copyright (C) 1998-2015, International Business Machines
# Copyright (C) 1998-2016, International Business Machines
# Corporation and others. All Rights Reserved.
#
#******************************************************************************
@ -64,7 +64,7 @@ LIBS = $(LIBICUUC) $(DEFAULT_LIBS)
OBJECTS = ucln_in.o \
fmtable.o format.o msgfmt.o umsg.o numfmt.o unum.o decimfmt.o decimalformatpattern.o dcfmtsym.o \
ucurr.o digitlst.o fmtable_cnv.o \
digitlst.o fmtable_cnv.o \
choicfmt.o datefmt.o smpdtfmt.o reldtfmt.o dtfmtsym.o udat.o dtptngen.o udatpg.o \
nfrs.o nfrule.o nfsubs.o rbnf.o numsys.o unumsys.o ucsdet.o \
ucal.o calendar.o gregocal.o timezone.o simpletz.o olsontz.o \
@ -91,7 +91,7 @@ wintzimpl.o windtfmt.o winnmfmt.o basictz.o dtrule.o rbtz.o tzrule.o tztrans.o v
standardplural.o upluralrules.o plurrule.o plurfmt.o selfmt.o dtitvfmt.o dtitvinf.o udateintervalformat.o \
tmunit.o tmutamt.o tmutfmt.o currpinf.o \
uspoof.o uspoof_impl.o uspoof_build.o uspoof_conf.o uspoof_wsconf.o decfmtst.o smpdtfst.o \
ztrans.o zrule.o vzone.o fphdlimp.o fpositer.o ufieldpositer.o locdspnm.o \
ztrans.o zrule.o vzone.o fphdlimp.o fpositer.o ufieldpositer.o \
decNumber.o decContext.o alphaindex.o tznames.o tznames_impl.o tzgnames.o \
tzfmt.o compactdecimalformat.o gender.o region.o scriptset.o identifier_info.o \
uregion.o reldatefmt.o quantityformatter.o measunit.o \

View file

@ -17,11 +17,10 @@
//TODO: put in compilation
//#define DTITVFMT_DEBUG 1
#include "unicode/msgfmt.h"
#include "unicode/calendar.h"
#include "unicode/dtptngen.h"
#include "unicode/dtitvinf.h"
#include "unicode/calendar.h"
#include "unicode/simpleformatter.h"
#include "cstring.h"
#include "dtitv_impl.h"
#include "gregoimp.h"
@ -1353,38 +1352,36 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar,
UnicodeString fullPattern; // for saving the pattern in fDateFormat
UBool formatDatePlusTimeRange = (fromToOnSameDay && fDatePattern && fTimePattern);
// the fall back
// no need delete earlierDate and laterDate since they are adopted
if (formatDatePlusTimeRange) {
fDateFormat->toPattern(fullPattern); // save current pattern, restore later
fDateFormat->applyPattern(*fTimePattern);
}
FieldPosition otherPos;
otherPos.setField(pos.getField());
UnicodeString* earlierDate = new UnicodeString();
fDateFormat->format(fromCalendar, *earlierDate, pos);
UnicodeString* laterDate = new UnicodeString();
fDateFormat->format(toCalendar, *laterDate, otherPos);
UnicodeString earlierDate;
fDateFormat->format(fromCalendar, earlierDate, pos);
UnicodeString laterDate;
fDateFormat->format(toCalendar, laterDate, otherPos);
UnicodeString fallbackPattern;
fInfo->getFallbackIntervalPattern(fallbackPattern);
adjustPosition(fallbackPattern, *earlierDate, pos, *laterDate, otherPos, pos);
Formattable fmtArray[2];
fmtArray[0].adoptString(earlierDate);
fmtArray[1].adoptString(laterDate);
adjustPosition(fallbackPattern, earlierDate, pos, laterDate, otherPos, pos);
UnicodeString fallbackRange;
MessageFormat::format(fallbackPattern, fmtArray, 2, fallbackRange, status);
SimpleFormatter(fallbackPattern, 2, 2, status).
format(earlierDate, laterDate, fallbackRange, status);
if ( U_SUCCESS(status) && formatDatePlusTimeRange ) {
// fallbackRange has just the time range, need to format the date part and combine that
fDateFormat->applyPattern(*fDatePattern);
UnicodeString* datePortion = new UnicodeString();
UnicodeString datePortion;
otherPos.setBeginIndex(0);
otherPos.setEndIndex(0);
fDateFormat->format(fromCalendar, *datePortion, otherPos);
adjustPosition(*fDateTimeFormat, fallbackRange, pos, *datePortion, otherPos, pos);
fmtArray[0].setString(fallbackRange); // {0} is time range
fmtArray[1].adoptString(datePortion); // {1} is single date portion
fallbackRange.remove();
MessageFormat::format(*fDateTimeFormat, fmtArray, 2, fallbackRange, status);
fDateFormat->format(fromCalendar, datePortion, otherPos);
adjustPosition(*fDateTimeFormat, fallbackRange, pos, datePortion, otherPos, pos);
const UnicodeString *values[2] = {
&fallbackRange, // {0} is time range
&datePortion, // {1} is single date portion
};
SimpleFormatter(*fDateTimeFormat, 2, 2, status).
formatAndReplace(values, 2, fallbackRange, NULL, 0, status);
}
if ( U_SUCCESS(status) ) {
appendTo.append(fallbackRange);
@ -1533,15 +1530,11 @@ DateIntervalFormat::concatSingleDate2TimeInterval(UnicodeString& format,
}
PatternInfo& timeItvPtnInfo = fIntervalPatterns[itvPtnIndex];
if ( !timeItvPtnInfo.firstPart.isEmpty() ) {
// UnicodeString allocated here is adopted, so no need to delete
UnicodeString* timeIntervalPattern = new UnicodeString(timeItvPtnInfo.firstPart);
timeIntervalPattern->append(timeItvPtnInfo.secondPart);
UnicodeString* dateStr = new UnicodeString(datePattern);
Formattable fmtArray[2];
fmtArray[0].adoptString(timeIntervalPattern);
fmtArray[1].adoptString(dateStr);
UnicodeString timeIntervalPattern(timeItvPtnInfo.firstPart);
timeIntervalPattern.append(timeItvPtnInfo.secondPart);
UnicodeString combinedPattern;
MessageFormat::format(format, fmtArray, 2, combinedPattern, status);
SimpleFormatter(format, 2, 2, status).
format(timeIntervalPattern, datePattern, combinedPattern, status);
if ( U_FAILURE(status) ) {
return;
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2007-2015, International Business Machines Corporation and
* Copyright (C) 2007-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
@ -16,7 +16,7 @@
#include "unicode/decimfmt.h"
#include "unicode/dtfmtsym.h"
#include "unicode/dtptngen.h"
#include "unicode/msgfmt.h"
#include "unicode/simpleformatter.h"
#include "unicode/smpdtfmt.h"
#include "unicode/udat.h"
#include "unicode/udatpg.h"
@ -830,8 +830,7 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
resultPattern.remove();
status = U_ZERO_ERROR;
dtFormat=getDateTimeFormat();
Formattable dateTimeObject[] = { timePattern, datePattern };
resultPattern = MessageFormat::format(dtFormat, dateTimeObject, 2, resultPattern, status );
SimpleFormatter(dtFormat, 2, 2, status).format(timePattern, datePattern, resultPattern, status);
return resultPattern;
}
@ -1171,13 +1170,13 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
int32_t topField=getTopBitNumber(foundMask);
UnicodeString appendName;
getAppendName((UDateTimePatternField)topField, appendName);
const Formattable formatPattern[] = {
resultPattern,
tempPattern,
appendName
const UnicodeString *values[3] = {
&resultPattern,
&tempPattern,
&appendName
};
UnicodeString emptyStr;
resultPattern = MessageFormat::format(appendItemFormats[topField], formatPattern, 3, emptyStr, err);
SimpleFormatter(appendItemFormats[topField], 2, 3, err).
formatAndReplace(values, 3, resultPattern, NULL, 0, err);
lastMissingFieldMask = distanceInfo->missingFieldMask;
}
}

View file

@ -336,7 +336,6 @@
<ClCompile Include="indiancal.cpp" />
<ClCompile Include="islamcal.cpp" />
<ClCompile Include="japancal.cpp" />
<ClCompile Include="locdspnm.cpp" />
<ClCompile Include="measfmt.cpp" />
<ClCompile Include="measunit.cpp" />
<ClCompile Include="measure.cpp" />
@ -373,7 +372,6 @@
<ClCompile Include="tzrule.cpp" />
<ClCompile Include="tztrans.cpp" />
<ClCompile Include="ucal.cpp" />
<ClCompile Include="ucurr.cpp" />
<ClCompile Include="udat.cpp" />
<ClCompile Include="udateintervalformat.cpp" />
<ClCompile Include="udatpg.cpp" />
@ -1039,20 +1037,6 @@
<ClInclude Include="indiancal.h" />
<ClInclude Include="islamcal.h" />
<ClInclude Include="japancal.h" />
<CustomBuild Include="unicode\locdspnm.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\measfmt.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
@ -1379,21 +1363,6 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\ucurr.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<ClInclude Include="ucurrimp.h" />
<CustomBuild Include="unicode\udat.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
@ -1433,20 +1402,6 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\udisplaycontext.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
@ -1461,20 +1416,6 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="unicode\uldnames.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>

View file

@ -207,9 +207,6 @@
<ClCompile Include="japancal.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="locdspnm.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="measfmt.cpp">
<Filter>formatting</Filter>
</ClCompile>
@ -309,9 +306,6 @@
<ClCompile Include="ucal.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="ucurr.cpp">
<Filter>formatting</Filter>
</ClCompile>
<ClCompile Include="udat.cpp">
<Filter>formatting</Filter>
</ClCompile>
@ -796,9 +790,6 @@
<ClInclude Include="taiwncal.h">
<Filter>formatting</Filter>
</ClInclude>
<ClInclude Include="ucurrimp.h">
<Filter>formatting</Filter>
</ClInclude>
<ClInclude Include="umsg_imp.h">
<Filter>formatting</Filter>
</ClInclude>
@ -1133,9 +1124,6 @@
<CustomBuild Include="unicode\gregocal.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\locdspnm.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\measfmt.h">
<Filter>formatting</Filter>
</CustomBuild>
@ -1199,9 +1187,6 @@
<CustomBuild Include="unicode\ucal.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\ucurr.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\udat.h">
<Filter>formatting</Filter>
</CustomBuild>
@ -1211,18 +1196,12 @@
<CustomBuild Include="unicode\udatpg.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\udisplaycontext.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\ugender.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\ufieldpositer.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\uldnames.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\ulocdata.h">
<Filter>formatting</Filter>
</CustomBuild>

View file

@ -18,7 +18,7 @@
#include "unicode/localpointer.h"
#include "quantityformatter.h"
#include "unicode/plurrule.h"
#include "unicode/msgfmt.h"
#include "unicode/simpleformatter.h"
#include "unicode/decimfmt.h"
#include "unicode/numfmt.h"
#include "unicode/brkiter.h"
@ -54,15 +54,15 @@ public:
// means past e.g 5 days ago; 1 means future e.g in 5 days.
QuantityFormatter relativeUnits[UDAT_STYLE_COUNT][UDAT_RELATIVE_UNIT_COUNT][2];
void adoptCombinedDateAndTime(MessageFormat *mfToAdopt) {
void adoptCombinedDateAndTime(SimpleFormatter *fmtToAdopt) {
delete combinedDateAndTime;
combinedDateAndTime = mfToAdopt;
combinedDateAndTime = fmtToAdopt;
}
const MessageFormat *getCombinedDateAndTime() const {
const SimpleFormatter *getCombinedDateAndTime() const {
return combinedDateAndTime;
}
private:
MessageFormat *combinedDateAndTime;
SimpleFormatter *combinedDateAndTime;
RelativeDateTimeCacheData(const RelativeDateTimeCacheData &other);
RelativeDateTimeCacheData& operator=(
const RelativeDateTimeCacheData &other);
@ -643,7 +643,7 @@ const RelativeDateTimeCacheData *LocaleCacheKey<RelativeDateTimeCacheData>::crea
return NULL;
}
result->adoptCombinedDateAndTime(
new MessageFormat(dateTimePattern, localeId, status));
new SimpleFormatter(dateTimePattern, 2, 2, status));
if (U_FAILURE(status)) {
return NULL;
}
@ -913,12 +913,10 @@ UnicodeString& RelativeDateTimeFormatter::format(
}
UnicodeString& RelativeDateTimeFormatter::combineDateAndTime(
const UnicodeString& relativeDateString, const UnicodeString& timeString,
UnicodeString& appendTo, UErrorCode& status) const {
Formattable args[2] = {timeString, relativeDateString};
FieldPosition fpos(0);
const UnicodeString& relativeDateString, const UnicodeString& timeString,
UnicodeString& appendTo, UErrorCode& status) const {
return fCache->getCombinedDateAndTime()->format(
args, 2, appendTo, fpos, status);
timeString, relativeDateString, appendTo, status);
}
void RelativeDateTimeFormatter::adjustForContext(UnicodeString &str) const {

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2007-2014, International Business Machines Corporation and
* Copyright (C) 2007-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -13,8 +13,8 @@
#include "reldtfmt.h"
#include "unicode/datefmt.h"
#include "unicode/simpleformatter.h"
#include "unicode/smpdtfmt.h"
#include "unicode/msgfmt.h"
#include "unicode/udisplaycontext.h"
#include "unicode/uchar.h"
#include "unicode/brkiter.h"
@ -56,7 +56,7 @@ RelativeDateFormat::RelativeDateFormat(const RelativeDateFormat& other) :
fDateTimeFormatter = (SimpleDateFormat*)other.fDateTimeFormatter->clone();
}
if(other.fCombinedFormat != NULL) {
fCombinedFormat = (MessageFormat*)other.fCombinedFormat->clone();
fCombinedFormat = new SimpleFormatter(*other.fCombinedFormat);
}
if (fDatesLen > 0) {
fDates = (URelativeString*) uprv_malloc(sizeof(fDates[0])*fDatesLen);
@ -211,12 +211,11 @@ UnicodeString& RelativeDateFormat::format( Calendar& cal,
datePattern.setTo(fDatePattern);
}
UnicodeString combinedPattern;
Formattable timeDatePatterns[] = { fTimePattern, datePattern };
fCombinedFormat->format(timeDatePatterns, 2, combinedPattern, pos, status); // pos is ignored by this
fCombinedFormat->format(fTimePattern, datePattern, combinedPattern, status);
fDateTimeFormatter->applyPattern(combinedPattern);
fDateTimeFormatter->format(cal,appendTo,pos);
}
return appendTo;
}
@ -308,8 +307,7 @@ void RelativeDateFormat::parse( const UnicodeString& text,
}
}
UnicodeString combinedPattern;
Formattable timeDatePatterns[] = { fTimePattern, fDatePattern };
fCombinedFormat->format(timeDatePatterns, 2, combinedPattern, fPos, status); // pos is ignored by this
fCombinedFormat->format(fTimePattern, fDatePattern, combinedPattern, status);
fDateTimeFormatter->applyPattern(combinedPattern);
fDateTimeFormatter->parse(modifiedText,cal,pos);
@ -381,9 +379,7 @@ RelativeDateFormat::toPattern(UnicodeString& result, UErrorCode& status) const
} else if (fTimePattern.isEmpty() || fCombinedFormat == NULL) {
result.setTo(fDatePattern);
} else {
Formattable timeDatePatterns[] = { fTimePattern, fDatePattern };
FieldPosition pos;
fCombinedFormat->format(timeDatePatterns, 2, result, pos, status);
fCombinedFormat->format(fTimePattern, fDatePattern, result, status);
}
}
return result;
@ -514,7 +510,7 @@ void RelativeDateFormat::loadDates(UErrorCode &status) {
if (U_SUCCESS(tempStatus) && resStrLen >= patItem1Len && u_strncmp(resStr,patItem1,patItem1Len)==0) {
fCombinedHasDateAtStart = TRUE;
}
fCombinedFormat = new MessageFormat(UnicodeString(TRUE, resStr, resStrLen), fLocale, tempStatus);
fCombinedFormat = new SimpleFormatter(UnicodeString(TRUE, resStr, resStrLen), 2, 2, tempStatus);
}
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2007-2014, International Business Machines Corporation and *
* Copyright (C) 2007-2016, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -25,7 +25,7 @@ U_NAMESPACE_BEGIN
// forward declarations
class DateFormatSymbols;
class MessageFormat;
class SimpleFormatter;
// internal structure used for caching strings
struct URelativeString;
@ -250,7 +250,7 @@ private:
SimpleDateFormat *fDateTimeFormatter;
UnicodeString fDatePattern;
UnicodeString fTimePattern;
MessageFormat *fCombinedFormat; // the {0} {1} format.
SimpleFormatter *fCombinedFormat; // the {0} {1} format.
UDateFormatStyle fDateStyle;
Locale fLocale;

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* Copyright (C) 1997-2015, International Business Machines Corporation and *
* others. All Rights Reserved. *
* Copyright (C) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File SMPDTFMT.CPP
@ -42,6 +42,7 @@
#include "unicode/uniset.h"
#include "unicode/ustring.h"
#include "unicode/basictz.h"
#include "unicode/simpleformatter.h"
#include "unicode/simpletz.h"
#include "unicode/rbtz.h"
#include "unicode/tzfmt.h"
@ -726,16 +727,9 @@ void SimpleDateFormat::construct(EStyle timeStyle,
// if the pattern should include both date and time information, use the date/time
// pattern string as a guide to tell use how to glue together the appropriate date
// and time pattern strings. The actual gluing-together is handled by a convenience
// method on MessageFormat.
// and time pattern strings.
if ((timeStyle != kNone) && (dateStyle != kNone))
{
Formattable timeDateArray[2];
// 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;
@ -760,13 +754,7 @@ void SimpleDateFormat::construct(EStyle timeStyle,
}
ures_close(currentBundle);
UnicodeString *tempus1 = new UnicodeString(TRUE, resStr, resStrLen);
// NULL pointer check
if (tempus1 == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
timeDateArray[0].adoptString(tempus1);
UnicodeString tempus1(TRUE, resStr, resStrLen);
currentBundle = ures_getByIndex(dateTimePatterns, (int32_t)dateStyle, NULL, &status);
if (U_FAILURE(status)) {
@ -792,13 +780,7 @@ void SimpleDateFormat::construct(EStyle timeStyle,
}
ures_close(currentBundle);
UnicodeString *tempus2 = new UnicodeString(TRUE, resStr, resStrLen);
// Null pointer check
if (tempus2 == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
timeDateArray[1].adoptString(tempus2);
UnicodeString tempus2(TRUE, resStr, resStrLen);
int32_t glueIndex = kDateTime;
int32_t patternsSize = ures_getSize(dateTimePatterns);
@ -808,7 +790,8 @@ void SimpleDateFormat::construct(EStyle timeStyle,
}
resStr = ures_getStringByIndex(dateTimePatterns, glueIndex, &resStrLen, &status);
MessageFormat::format(UnicodeString(TRUE, resStr, resStrLen), timeDateArray, 2, fPattern, status);
SimpleFormatter(UnicodeString(TRUE, resStr, resStrLen), 2, 2, status).
format(tempus1, tempus2, fPattern, status);
}
// if the pattern includes just time data or just date date, load the appropriate
// pattern string from the resources
@ -1238,8 +1221,7 @@ _appendSymbolWithMonthPattern(UnicodeString& dst, int32_t value, const UnicodeSt
if (monthPattern == NULL) {
dst += symbols[value];
} else {
Formattable monthName((const UnicodeString&)(symbols[value]));
MessageFormat::format(*monthPattern, &monthName, 1, dst, status);
SimpleFormatter(*monthPattern, 1, 1, status).format(symbols[value], dst, status);
}
}
}
@ -2542,8 +2524,7 @@ int32_t SimpleDateFormat::matchString(const UnicodeString& text,
if (monthPattern != NULL) {
UErrorCode status = U_ZERO_ERROR;
UnicodeString leapMonthName;
Formattable monthName((const UnicodeString&)(data[i]));
MessageFormat::format(*monthPattern, &monthName, 1, leapMonthName, status);
SimpleFormatter(*monthPattern, 1, 1, status).format(data[i], leapMonthName, status);
if (U_SUCCESS(status)) {
if ((matchLen = matchStringWithOptionalDot(text, start, leapMonthName)) > bestMatchLength) {
bestMatch = i;

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2011-2015, International Business Machines Corporation and
* Copyright (C) 2011-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -13,8 +13,8 @@
#include "unicode/basictz.h"
#include "unicode/locdspnm.h"
#include "unicode/msgfmt.h"
#include "unicode/rbtz.h"
#include "unicode/simpleformatter.h"
#include "unicode/simpletz.h"
#include "unicode/vtzone.h"
@ -287,8 +287,8 @@ private:
UHashtable* fLocationNamesMap;
UHashtable* fPartialLocationNamesMap;
MessageFormat* fRegionFormat;
MessageFormat* fFallbackFormat;
SimpleFormatter fRegionFormat;
SimpleFormatter fFallbackFormat;
LocaleDisplayNames* fLocaleDisplayNames;
ZNStringPool fStringPool;
@ -333,8 +333,6 @@ TZGNCore::TZGNCore(const Locale& locale, UErrorCode& status)
fTimeZoneNames(NULL),
fLocationNamesMap(NULL),
fPartialLocationNamesMap(NULL),
fRegionFormat(NULL),
fFallbackFormat(NULL),
fLocaleDisplayNames(NULL),
fStringPool(status),
fGNamesTrie(TRUE, deleteGNameInfo),
@ -379,14 +377,8 @@ TZGNCore::initialize(const Locale& locale, UErrorCode& status) {
}
ures_close(zoneStrings);
fRegionFormat = new MessageFormat(rpat, status);
if (fRegionFormat == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
fFallbackFormat = new MessageFormat(fpat, status);
if (fFallbackFormat == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
fRegionFormat.applyPatternMinMaxArguments(rpat, 1, 1, status);
fFallbackFormat.applyPatternMinMaxArguments(fpat, 2, 2, status);
if (U_FAILURE(status)) {
cleanup();
return;
@ -441,12 +433,6 @@ TZGNCore::initialize(const Locale& locale, UErrorCode& status) {
void
TZGNCore::cleanup() {
if (fRegionFormat != NULL) {
delete fRegionFormat;
}
if (fFallbackFormat != NULL) {
delete fFallbackFormat;
}
if (fLocaleDisplayNames != NULL) {
delete fLocaleDisplayNames;
}
@ -545,8 +531,6 @@ TZGNCore::getGenericLocationName(const UnicodeString& tzCanonicalID) {
ZoneMeta::getCanonicalCountry(tzCanonicalID, usCountryCode, &isPrimary);
if (!usCountryCode.isEmpty()) {
FieldPosition fpos;
if (isPrimary) {
// If this is the primary zone in the country, use the country name.
char countryCode[ULOC_COUNTRY_CAPACITY];
@ -556,12 +540,7 @@ TZGNCore::getGenericLocationName(const UnicodeString& tzCanonicalID) {
UnicodeString country;
fLocaleDisplayNames->regionDisplayName(countryCode, country);
Formattable param[] = {
Formattable(country)
};
fRegionFormat->format(param, 1, name, fpos, status);
fRegionFormat.format(country, name, status);
} else {
// If this is not the primary zone in the country,
// use the exemplar city name.
@ -571,12 +550,7 @@ TZGNCore::getGenericLocationName(const UnicodeString& tzCanonicalID) {
UnicodeString city;
fTimeZoneNames->getExemplarLocationName(tzCanonicalID, city);
Formattable param[] = {
Formattable(city),
};
fRegionFormat->format(param, 1, name, fpos, status);
fRegionFormat.format(city, name, status);
}
if (U_FAILURE(status)) {
return NULL;
@ -828,13 +802,7 @@ TZGNCore::getPartialLocationName(const UnicodeString& tzCanonicalID,
UErrorCode status = U_ZERO_ERROR;
UnicodeString name;
FieldPosition fpos;
Formattable param[] = {
Formattable(location),
Formattable(mzDisplayName)
};
fFallbackFormat->format(param, 2, name, fpos, status);
fFallbackFormat.format(location, mzDisplayName, name, status);
if (U_FAILURE(status)) {
return NULL;
}

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 2001-2014, International Business Machines
* Copyright (C) 2001-2016, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: ucln_cmn.h
@ -40,7 +40,6 @@ typedef enum ECleanupI18NType {
UCLN_I18N_TIMEZONENAMES,
UCLN_I18N_ZONEMETA,
UCLN_I18N_TIMEZONE,
UCLN_I18N_CURRENCY,
UCLN_I18N_DECFMT,
UCLN_I18N_NUMFMT,
UCLN_I18N_SMPDTFMT,

View file

@ -1,6 +1,6 @@
/*
********************************************************************************
* Copyright (C) 1997-2015, International Business Machines
* Copyright (C) 1997-2016, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
@ -54,7 +54,6 @@
U_NAMESPACE_BEGIN
class DigitList;
class ChoiceFormat;
class CurrencyPluralInfo;
class Hashtable;
class UnicodeSet;

View file

@ -1,6 +1,6 @@
/*
********************************************************************************
* Copyright (C) 2005-2014, International Business Machines
* Copyright (C) 2005-2016, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
@ -19,7 +19,7 @@
#include "unicode/format.h"
#include "unicode/fmtable.h"
#include "unicode/datefmt.h"
#include "unicode/msgfmt.h"
#include "unicode/simpleformatter.h"
#include "unicode/calendar.h"
#include "unicode/gregocal.h"
#include "unicode/locid.h"
@ -167,22 +167,18 @@ UnicodeString &Win32DateFormat::format(Calendar &cal, UnicodeString &appendTo, F
if (fDateStyle != DateFormat::kNone && fTimeStyle != DateFormat::kNone) {
UnicodeString *date = new UnicodeString();
UnicodeString *time = new UnicodeString();
UnicodeString date;
UnicodeString time;
UnicodeString *pattern = fDateTimeMsg;
Formattable timeDateArray[2];
formatDate(&st_local, *date);
formatTime(&st_local, *time);
timeDateArray[0].adoptString(time);
timeDateArray[1].adoptString(date);
formatDate(&st_local, date);
formatTime(&st_local, time);
if (strcmp(fCalendar->getType(), cal.getType()) != 0) {
pattern = getTimeDateFormat(&cal, &fLocale, status);
}
MessageFormat::format(*pattern, timeDateArray, 2, appendTo, status);
SimpleFormatter(*pattern, 2, 2, status).format(time, date, appendTo, status);
} else if (fDateStyle != DateFormat::kNone) {
formatDate(&st_local, appendTo);
} else if (fTimeStyle != DateFormat::kNone) {

View file

@ -149,6 +149,8 @@ library: common
listformatter
resourcebundle service_registration resbund_cnv ures_cnv icudataver ucat
loclikely
currency
locale_display_names2
conversion converter_selector ucnv_set ucnvdisp
messagepattern simpleformatter
icu_utility icu_utility_with_props
@ -533,10 +535,21 @@ group: ucat # message-catalog-like API
resourcebundle
group: locale_display_names
locdispnames.o
locdispnames.o # Locale.getDisplayName()
deps
locresdata
group: locale_display_names2
locdspnm.o # class LocaleDisplayNames
deps
resourcebundle currency simpleformatter unistr_titlecase_brkiter uchar
group: currency
ucurr.o
deps
loclikely resourcebundle ulist ustring_case_locale
stdlib_qsort # for ucurr.o (which does not use ICU's uarrsort.o)
group: icudataver # u_getDataVersion()
icudataver.o
deps
@ -828,10 +841,6 @@ group: string_search
group: formatting
# TODO: Try to subdivide this ball of wax.
# locale_display_names2
locdspnm.o
# currency
ucurr.o
# currencyformat
curramt.o currfmt.o currpinf.o currunit.o
# decimalformat
@ -868,7 +877,6 @@ group: formatting
common
floating_point # sqrt() for astro.o
trigonometry # for astro.o
stdlib_qsort # for ucurr.o (which does not use ICU's uarrsort.o)
sharedbreakiterator # for reldatefmt.o
uclean_i18n