| Index: source/i18n/plurrule.cpp
|
| diff --git a/source/i18n/plurrule.cpp b/source/i18n/plurrule.cpp
|
| index 05e5efab5be816e4ae4b045da477028fa54ed8ff..ab9fba451406ea1fc59771cdaf64b2c03cee27ab 100644
|
| --- a/source/i18n/plurrule.cpp
|
| +++ b/source/i18n/plurrule.cpp
|
| @@ -1,6 +1,6 @@
|
| /*
|
| *******************************************************************************
|
| -* Copyright (C) 2007-2013, International Business Machines Corporation and
|
| +* Copyright (C) 2007-2014, International Business Machines Corporation and
|
| * others. All Rights Reserved.
|
| *******************************************************************************
|
| *
|
| @@ -29,6 +29,8 @@
|
| #include "ustrfmt.h"
|
| #include "uassert.h"
|
| #include "uvectr32.h"
|
| +#include "sharedpluralrules.h"
|
| +#include "unifiedcache.h"
|
|
|
| #if !UCONFIG_NO_FORMATTING
|
|
|
| @@ -49,7 +51,6 @@ static const UChar PK_VAR_I[]={LOW_I,0};
|
| static const UChar PK_VAR_F[]={LOW_F,0};
|
| static const UChar PK_VAR_T[]={LOW_T,0};
|
| static const UChar PK_VAR_V[]={LOW_V,0};
|
| -static const UChar PK_VAR_J[]={LOW_J,0};
|
| static const UChar PK_WITHIN[]={LOW_W,LOW_I,LOW_T,LOW_H,LOW_I,LOW_N,0};
|
| static const UChar PK_DECIMAL[]={LOW_D,LOW_E,LOW_C,LOW_I,LOW_M,LOW_A,LOW_L,0};
|
| static const UChar PK_INTEGER[]={LOW_I,LOW_N,LOW_T,LOW_E,LOW_G,LOW_E,LOW_R,0};
|
| @@ -74,6 +75,10 @@ PluralRules::~PluralRules() {
|
| delete mRules;
|
| }
|
|
|
| +SharedPluralRules::~SharedPluralRules() {
|
| + delete ptr;
|
| +}
|
| +
|
| PluralRules*
|
| PluralRules::clone() const {
|
| return new PluralRules(*this);
|
| @@ -132,6 +137,46 @@ PluralRules::createDefaultRules(UErrorCode& status) {
|
| return createRules(UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1), status);
|
| }
|
|
|
| +/******************************************************************************/
|
| +/* Create PluralRules cache */
|
| +
|
| +template<> U_I18N_API
|
| +const SharedPluralRules *LocaleCacheKey<SharedPluralRules>::createObject(
|
| + const void * /*unused*/, UErrorCode &status) const {
|
| + const char *localeId = fLoc.getName();
|
| + PluralRules *pr = PluralRules::internalForLocale(
|
| + localeId, UPLURAL_TYPE_CARDINAL, status);
|
| + if (U_FAILURE(status)) {
|
| + return NULL;
|
| + }
|
| + SharedPluralRules *result = new SharedPluralRules(pr);
|
| + if (result == NULL) {
|
| + status = U_MEMORY_ALLOCATION_ERROR;
|
| + delete pr;
|
| + return NULL;
|
| + }
|
| + result->addRef();
|
| + return result;
|
| +}
|
| +
|
| +/* end plural rules cache */
|
| +/******************************************************************************/
|
| +
|
| +const SharedPluralRules* U_EXPORT2
|
| +PluralRules::createSharedInstance(
|
| + const Locale& locale, UPluralType type, UErrorCode& status) {
|
| + if (U_FAILURE(status)) {
|
| + return NULL;
|
| + }
|
| + if (type != UPLURAL_TYPE_CARDINAL) {
|
| + status = U_UNSUPPORTED_ERROR;
|
| + return NULL;
|
| + }
|
| + const SharedPluralRules *result = NULL;
|
| + UnifiedCache::getByLocale(locale, result, status);
|
| + return result;
|
| +}
|
| +
|
| PluralRules* U_EXPORT2
|
| PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
|
| return forLocale(locale, UPLURAL_TYPE_CARDINAL, status);
|
| @@ -139,6 +184,24 @@ PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
|
|
|
| PluralRules* U_EXPORT2
|
| PluralRules::forLocale(const Locale& locale, UPluralType type, UErrorCode& status) {
|
| + if (type != UPLURAL_TYPE_CARDINAL) {
|
| + return internalForLocale(locale, type, status);
|
| + }
|
| + const SharedPluralRules *shared = createSharedInstance(
|
| + locale, type, status);
|
| + if (U_FAILURE(status)) {
|
| + return NULL;
|
| + }
|
| + PluralRules *result = (*shared)->clone();
|
| + shared->removeRef();
|
| + if (result == NULL) {
|
| + status = U_MEMORY_ALLOCATION_ERROR;
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +PluralRules* U_EXPORT2
|
| +PluralRules::internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status) {
|
| if (U_FAILURE(status)) {
|
| return NULL;
|
| }
|
|
|