OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2008-2010, Google, International Business Machines Corporation | 3 * Copyright (C) 2008-2010, Google, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 | 7 |
8 #include <typeinfo> // for 'typeid' to work | |
9 | 8 |
10 #include "unicode/tmutfmt.h" | 9 #include "unicode/tmutfmt.h" |
11 | 10 |
12 #if !UCONFIG_NO_FORMATTING | 11 #if !UCONFIG_NO_FORMATTING |
13 | 12 |
14 #include "cmemory.h" | 13 #include "cmemory.h" |
15 #include "cstring.h" | 14 #include "cstring.h" |
16 #include "hash.h" | 15 #include "hash.h" |
17 #include "uresimp.h" | 16 #include "uresimp.h" |
18 #include "unicode/msgfmt.h" | 17 #include "unicode/msgfmt.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } else { | 165 } else { |
167 fPluralRules = NULL; | 166 fPluralRules = NULL; |
168 } | 167 } |
169 fStyle = other.fStyle; | 168 fStyle = other.fStyle; |
170 return *this; | 169 return *this; |
171 } | 170 } |
172 | 171 |
173 | 172 |
174 UBool | 173 UBool |
175 TimeUnitFormat::operator==(const Format& other) const { | 174 TimeUnitFormat::operator==(const Format& other) const { |
176 if (typeid(*this) == typeid(other)) { | 175 if (CR_TYPEID(*this) == CR_TYPEID(other)) { |
177 TimeUnitFormat* fmt = (TimeUnitFormat*)&other; | 176 TimeUnitFormat* fmt = (TimeUnitFormat*)&other; |
178 UBool ret = ( ((fNumberFormat && fmt->fNumberFormat && *fNumberFormat =
= *fmt->fNumberFormat) | 177 UBool ret = ( ((fNumberFormat && fmt->fNumberFormat && *fNumberFormat =
= *fmt->fNumberFormat) |
179 || fNumberFormat == fmt->fNumberFormat ) | 178 || fNumberFormat == fmt->fNumberFormat ) |
180 && fLocale == fmt->fLocale | 179 && fLocale == fmt->fLocale |
181 && ((fPluralRules && fmt->fPluralRules && *fPluralRules
== *fmt->fPluralRules) | 180 && ((fPluralRules && fmt->fPluralRules && *fPluralRules
== *fmt->fPluralRules) |
182 || fPluralRules == fmt->fPluralRules) | 181 || fPluralRules == fmt->fPluralRules) |
183 && fStyle == fmt->fStyle); | 182 && fStyle == fmt->fStyle); |
184 if (ret) { | 183 if (ret) { |
185 for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; | 184 for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; |
186 i < TimeUnit::UTIMEUNIT_FIELD_COUNT && ret; | 185 i < TimeUnit::UTIMEUNIT_FIELD_COUNT && ret; |
187 i = (TimeUnit::UTimeUnitFields)(i+1)) { | 186 i = (TimeUnit::UTimeUnitFields)(i+1)) { |
188 ret = fTimeUnitToCountToPatterns[i]->equals(*(fmt->fTimeUnitToCo
untToPatterns[i])); | 187 ret = fTimeUnitToCountToPatterns[i]->equals(*(fmt->fTimeUnitToCo
untToPatterns[i])); |
189 } | 188 } |
190 } | 189 } |
191 return ret; | 190 return ret; |
192 } | 191 } |
193 return false; | 192 return false; |
194 } | 193 } |
195 | 194 |
196 | 195 |
197 UnicodeString& | 196 UnicodeString& |
198 TimeUnitFormat::format(const Formattable& obj, UnicodeString& toAppendTo, | 197 TimeUnitFormat::format(const Formattable& obj, UnicodeString& toAppendTo, |
199 FieldPosition& pos, UErrorCode& status) const { | 198 FieldPosition& pos, UErrorCode& status) const { |
200 if (U_FAILURE(status)) { | 199 if (U_FAILURE(status)) { |
201 return toAppendTo; | 200 return toAppendTo; |
202 } | 201 } |
203 if (obj.getType() == Formattable::kObject) { | 202 if (obj.getType() == Formattable::kObject) { |
204 const UObject* formatObj = obj.getObject(); | 203 const UObject* formatObj = obj.getObject(); |
205 const TimeUnitAmount* amount = dynamic_cast<const TimeUnitAmount*>(forma
tObj); | 204 const TimeUnitAmount* amount = CR_DYNAMIC_CAST<const TimeUnitAmount*>(fo
rmatObj); |
206 if (amount != NULL){ | 205 if (amount != NULL){ |
207 Hashtable* countToPattern = fTimeUnitToCountToPatterns[amount->getTi
meUnitField()]; | 206 Hashtable* countToPattern = fTimeUnitToCountToPatterns[amount->getTi
meUnitField()]; |
208 double number; | 207 double number; |
209 const Formattable& amtNumber = amount->getNumber(); | 208 const Formattable& amtNumber = amount->getNumber(); |
210 if (amtNumber.getType() == Formattable::kDouble) { | 209 if (amtNumber.getType() == Formattable::kDouble) { |
211 number = amtNumber.getDouble(); | 210 number = amtNumber.getDouble(); |
212 } else if (amtNumber.getType() == Formattable::kLong) { | 211 } else if (amtNumber.getType() == Formattable::kLong) { |
213 number = amtNumber.getLong(); | 212 number = amtNumber.getLong(); |
214 } else { | 213 } else { |
215 status = U_ILLEGAL_ARGUMENT_ERROR; | 214 status = U_ILLEGAL_ARGUMENT_ERROR; |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 return gTimeUnitSecond; | 864 return gTimeUnitSecond; |
866 default: | 865 default: |
867 status = U_ILLEGAL_ARGUMENT_ERROR; | 866 status = U_ILLEGAL_ARGUMENT_ERROR; |
868 return NULL; | 867 return NULL; |
869 } | 868 } |
870 } | 869 } |
871 | 870 |
872 U_NAMESPACE_END | 871 U_NAMESPACE_END |
873 | 872 |
874 #endif | 873 #endif |
OLD | NEW |