Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: source/i18n/plurrule.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/i18n/plurfmt.cpp ('k') | source/i18n/quantityformatter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ******************************************************************************* 2 *******************************************************************************
3 * Copyright (C) 2007-2013, International Business Machines Corporation and 3 * Copyright (C) 2007-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 * 6 *
7 * File plurrule.cpp 7 * File plurrule.cpp
8 */ 8 */
9 9
10 #include <math.h> 10 #include <math.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 #include "unicode/utypes.h" 13 #include "unicode/utypes.h"
14 #include "unicode/localpointer.h" 14 #include "unicode/localpointer.h"
15 #include "unicode/plurrule.h" 15 #include "unicode/plurrule.h"
16 #include "unicode/upluralrules.h" 16 #include "unicode/upluralrules.h"
17 #include "unicode/ures.h" 17 #include "unicode/ures.h"
18 #include "charstr.h" 18 #include "charstr.h"
19 #include "cmemory.h" 19 #include "cmemory.h"
20 #include "cstring.h" 20 #include "cstring.h"
21 #include "digitlst.h" 21 #include "digitlst.h"
22 #include "hash.h" 22 #include "hash.h"
23 #include "locutil.h" 23 #include "locutil.h"
24 #include "mutex.h" 24 #include "mutex.h"
25 #include "patternprops.h" 25 #include "patternprops.h"
26 #include "plurrule_impl.h" 26 #include "plurrule_impl.h"
27 #include "putilimp.h" 27 #include "putilimp.h"
28 #include "ucln_in.h" 28 #include "ucln_in.h"
29 #include "ustrfmt.h" 29 #include "ustrfmt.h"
30 #include "uassert.h" 30 #include "uassert.h"
31 #include "uvectr32.h" 31 #include "uvectr32.h"
32 #include "sharedpluralrules.h"
33 #include "unifiedcache.h"
32 34
33 #if !UCONFIG_NO_FORMATTING 35 #if !UCONFIG_NO_FORMATTING
34 36
35 U_NAMESPACE_BEGIN 37 U_NAMESPACE_BEGIN
36 38
37 #define ARRAY_SIZE(array) (int32_t)(sizeof array / sizeof array[0]) 39 #define ARRAY_SIZE(array) (int32_t)(sizeof array / sizeof array[0])
38 40
39 static const UChar PLURAL_KEYWORD_OTHER[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,0}; 41 static const UChar PLURAL_KEYWORD_OTHER[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,0};
40 static const UChar PLURAL_DEFAULT_RULE[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,COLON,SP ACE,LOW_N,0}; 42 static const UChar PLURAL_DEFAULT_RULE[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,COLON,SP ACE,LOW_N,0};
41 static const UChar PK_IN[]={LOW_I,LOW_N,0}; 43 static const UChar PK_IN[]={LOW_I,LOW_N,0};
42 static const UChar PK_NOT[]={LOW_N,LOW_O,LOW_T,0}; 44 static const UChar PK_NOT[]={LOW_N,LOW_O,LOW_T,0};
43 static const UChar PK_IS[]={LOW_I,LOW_S,0}; 45 static const UChar PK_IS[]={LOW_I,LOW_S,0};
44 static const UChar PK_MOD[]={LOW_M,LOW_O,LOW_D,0}; 46 static const UChar PK_MOD[]={LOW_M,LOW_O,LOW_D,0};
45 static const UChar PK_AND[]={LOW_A,LOW_N,LOW_D,0}; 47 static const UChar PK_AND[]={LOW_A,LOW_N,LOW_D,0};
46 static const UChar PK_OR[]={LOW_O,LOW_R,0}; 48 static const UChar PK_OR[]={LOW_O,LOW_R,0};
47 static const UChar PK_VAR_N[]={LOW_N,0}; 49 static const UChar PK_VAR_N[]={LOW_N,0};
48 static const UChar PK_VAR_I[]={LOW_I,0}; 50 static const UChar PK_VAR_I[]={LOW_I,0};
49 static const UChar PK_VAR_F[]={LOW_F,0}; 51 static const UChar PK_VAR_F[]={LOW_F,0};
50 static const UChar PK_VAR_T[]={LOW_T,0}; 52 static const UChar PK_VAR_T[]={LOW_T,0};
51 static const UChar PK_VAR_V[]={LOW_V,0}; 53 static const UChar PK_VAR_V[]={LOW_V,0};
52 static const UChar PK_VAR_J[]={LOW_J,0};
53 static const UChar PK_WITHIN[]={LOW_W,LOW_I,LOW_T,LOW_H,LOW_I,LOW_N,0}; 54 static const UChar PK_WITHIN[]={LOW_W,LOW_I,LOW_T,LOW_H,LOW_I,LOW_N,0};
54 static const UChar PK_DECIMAL[]={LOW_D,LOW_E,LOW_C,LOW_I,LOW_M,LOW_A,LOW_L,0}; 55 static const UChar PK_DECIMAL[]={LOW_D,LOW_E,LOW_C,LOW_I,LOW_M,LOW_A,LOW_L,0};
55 static const UChar PK_INTEGER[]={LOW_I,LOW_N,LOW_T,LOW_E,LOW_G,LOW_E,LOW_R,0}; 56 static const UChar PK_INTEGER[]={LOW_I,LOW_N,LOW_T,LOW_E,LOW_G,LOW_E,LOW_R,0};
56 57
57 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralRules) 58 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralRules)
58 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralKeywordEnumeration) 59 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralKeywordEnumeration)
59 60
60 PluralRules::PluralRules(UErrorCode& /*status*/) 61 PluralRules::PluralRules(UErrorCode& /*status*/)
61 : UObject(), 62 : UObject(),
62 mRules(NULL) 63 mRules(NULL)
63 { 64 {
64 } 65 }
65 66
66 PluralRules::PluralRules(const PluralRules& other) 67 PluralRules::PluralRules(const PluralRules& other)
67 : UObject(other), 68 : UObject(other),
68 mRules(NULL) 69 mRules(NULL)
69 { 70 {
70 *this=other; 71 *this=other;
71 } 72 }
72 73
73 PluralRules::~PluralRules() { 74 PluralRules::~PluralRules() {
74 delete mRules; 75 delete mRules;
75 } 76 }
76 77
78 SharedPluralRules::~SharedPluralRules() {
79 delete ptr;
80 }
81
77 PluralRules* 82 PluralRules*
78 PluralRules::clone() const { 83 PluralRules::clone() const {
79 return new PluralRules(*this); 84 return new PluralRules(*this);
80 } 85 }
81 86
82 PluralRules& 87 PluralRules&
83 PluralRules::operator=(const PluralRules& other) { 88 PluralRules::operator=(const PluralRules& other) {
84 if (this != &other) { 89 if (this != &other) {
85 delete mRules; 90 delete mRules;
86 if (other.mRules==NULL) { 91 if (other.mRules==NULL) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 130 }
126 return newRules; 131 return newRules;
127 } 132 }
128 133
129 134
130 PluralRules* U_EXPORT2 135 PluralRules* U_EXPORT2
131 PluralRules::createDefaultRules(UErrorCode& status) { 136 PluralRules::createDefaultRules(UErrorCode& status) {
132 return createRules(UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1), status); 137 return createRules(UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1), status);
133 } 138 }
134 139
140 /******************************************************************************/
141 /* Create PluralRules cache */
142
143 template<> U_I18N_API
144 const SharedPluralRules *LocaleCacheKey<SharedPluralRules>::createObject(
145 const void * /*unused*/, UErrorCode &status) const {
146 const char *localeId = fLoc.getName();
147 PluralRules *pr = PluralRules::internalForLocale(
148 localeId, UPLURAL_TYPE_CARDINAL, status);
149 if (U_FAILURE(status)) {
150 return NULL;
151 }
152 SharedPluralRules *result = new SharedPluralRules(pr);
153 if (result == NULL) {
154 status = U_MEMORY_ALLOCATION_ERROR;
155 delete pr;
156 return NULL;
157 }
158 result->addRef();
159 return result;
160 }
161
162 /* end plural rules cache */
163 /******************************************************************************/
164
165 const SharedPluralRules* U_EXPORT2
166 PluralRules::createSharedInstance(
167 const Locale& locale, UPluralType type, UErrorCode& status) {
168 if (U_FAILURE(status)) {
169 return NULL;
170 }
171 if (type != UPLURAL_TYPE_CARDINAL) {
172 status = U_UNSUPPORTED_ERROR;
173 return NULL;
174 }
175 const SharedPluralRules *result = NULL;
176 UnifiedCache::getByLocale(locale, result, status);
177 return result;
178 }
179
135 PluralRules* U_EXPORT2 180 PluralRules* U_EXPORT2
136 PluralRules::forLocale(const Locale& locale, UErrorCode& status) { 181 PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
137 return forLocale(locale, UPLURAL_TYPE_CARDINAL, status); 182 return forLocale(locale, UPLURAL_TYPE_CARDINAL, status);
138 } 183 }
139 184
140 PluralRules* U_EXPORT2 185 PluralRules* U_EXPORT2
141 PluralRules::forLocale(const Locale& locale, UPluralType type, UErrorCode& statu s) { 186 PluralRules::forLocale(const Locale& locale, UPluralType type, UErrorCode& statu s) {
187 if (type != UPLURAL_TYPE_CARDINAL) {
188 return internalForLocale(locale, type, status);
189 }
190 const SharedPluralRules *shared = createSharedInstance(
191 locale, type, status);
142 if (U_FAILURE(status)) { 192 if (U_FAILURE(status)) {
143 return NULL; 193 return NULL;
144 } 194 }
195 PluralRules *result = (*shared)->clone();
196 shared->removeRef();
197 if (result == NULL) {
198 status = U_MEMORY_ALLOCATION_ERROR;
199 }
200 return result;
201 }
202
203 PluralRules* U_EXPORT2
204 PluralRules::internalForLocale(const Locale& locale, UPluralType type, UErrorCod e& status) {
205 if (U_FAILURE(status)) {
206 return NULL;
207 }
145 if (type >= UPLURAL_TYPE_COUNT) { 208 if (type >= UPLURAL_TYPE_COUNT) {
146 status = U_ILLEGAL_ARGUMENT_ERROR; 209 status = U_ILLEGAL_ARGUMENT_ERROR;
147 return NULL; 210 return NULL;
148 } 211 }
149 PluralRules *newObj = new PluralRules(status); 212 PluralRules *newObj = new PluralRules(status);
150 if (newObj==NULL || U_FAILURE(status)) { 213 if (newObj==NULL || U_FAILURE(status)) {
151 delete newObj; 214 delete newObj;
152 return NULL; 215 return NULL;
153 } 216 }
154 UnicodeString locRule = newObj->getRuleFromResource(locale, type, status); 217 UnicodeString locRule = newObj->getRuleFromResource(locale, type, status);
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 } 1650 }
1588 return ures_getSize(fLocales); 1651 return ures_getSize(fLocales);
1589 } 1652 }
1590 1653
1591 U_NAMESPACE_END 1654 U_NAMESPACE_END
1592 1655
1593 1656
1594 #endif /* #if !UCONFIG_NO_FORMATTING */ 1657 #endif /* #if !UCONFIG_NO_FORMATTING */
1595 1658
1596 //eof 1659 //eof
OLDNEW
« no previous file with comments | « source/i18n/plurfmt.cpp ('k') | source/i18n/quantityformatter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698