OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2007-2014, International Business Machines Corporation and | 3 * Copyright (C) 2007-2015, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 * | 6 * |
7 * File DTPTNGEN.CPP | 7 * File DTPTNGEN.CPP |
8 * | 8 * |
9 ******************************************************************************* | 9 ******************************************************************************* |
10 */ | 10 */ |
11 | 11 |
12 #include "unicode/utypes.h" | 12 #include "unicode/utypes.h" |
13 #if !UCONFIG_NO_FORMATTING | 13 #if !UCONFIG_NO_FORMATTING |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return ret; | 117 return ret; |
118 #endif | 118 #endif |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 #endif | 122 #endif |
123 | 123 |
124 | 124 |
125 U_NAMESPACE_BEGIN | 125 U_NAMESPACE_BEGIN |
126 | 126 |
127 | |
128 // ***************************************************************************** | 127 // ***************************************************************************** |
129 // class DateTimePatternGenerator | 128 // class DateTimePatternGenerator |
130 // ***************************************************************************** | 129 // ***************************************************************************** |
131 static const UChar Canonical_Items[] = { | 130 static const UChar Canonical_Items[] = { |
132 // GyQMwWEdDFHmsSv | 131 // GyQMwWEdDFHmsSv |
133 CAP_G, LOW_Y, CAP_Q, CAP_M, LOW_W, CAP_W, CAP_E, LOW_D, CAP_D, CAP_F, | 132 CAP_G, LOW_Y, CAP_Q, CAP_M, LOW_W, CAP_W, CAP_E, LOW_D, CAP_D, CAP_F, |
134 CAP_H, LOW_M, LOW_S, CAP_S, LOW_V, 0 | 133 CAP_H, LOW_M, LOW_S, CAP_S, LOW_V, 0 |
135 }; | 134 }; |
136 | 135 |
137 static const dtTypeElem dtTypes[] = { | 136 static const dtTypeElem dtTypes[] = { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTSkeletonEnumeration) | 237 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTSkeletonEnumeration) |
239 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTRedundantEnumeration) | 238 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTRedundantEnumeration) |
240 | 239 |
241 DateTimePatternGenerator* U_EXPORT2 | 240 DateTimePatternGenerator* U_EXPORT2 |
242 DateTimePatternGenerator::createInstance(UErrorCode& status) { | 241 DateTimePatternGenerator::createInstance(UErrorCode& status) { |
243 return createInstance(Locale::getDefault(), status); | 242 return createInstance(Locale::getDefault(), status); |
244 } | 243 } |
245 | 244 |
246 DateTimePatternGenerator* U_EXPORT2 | 245 DateTimePatternGenerator* U_EXPORT2 |
247 DateTimePatternGenerator::createInstance(const Locale& locale, UErrorCode& statu
s) { | 246 DateTimePatternGenerator::createInstance(const Locale& locale, UErrorCode& statu
s) { |
248 DateTimePatternGenerator *result = new DateTimePatternGenerator(locale, stat
us); | 247 if (U_FAILURE(status)) { |
249 if (result == NULL) { | 248 return NULL; |
250 status = U_MEMORY_ALLOCATION_ERROR; | |
251 } | 249 } |
252 if (U_FAILURE(status)) { | 250 LocalPointer<DateTimePatternGenerator> result( |
253 delete result; | 251 new DateTimePatternGenerator(locale, status), status); |
254 result = NULL; | 252 return U_SUCCESS(status) ? result.orphan() : NULL; |
255 } | |
256 return result; | |
257 } | 253 } |
258 | 254 |
259 DateTimePatternGenerator* U_EXPORT2 | 255 DateTimePatternGenerator* U_EXPORT2 |
260 DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) { | 256 DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) { |
261 DateTimePatternGenerator *result = new DateTimePatternGenerator(status); | 257 DateTimePatternGenerator *result = new DateTimePatternGenerator(status); |
262 if (result == NULL) { | 258 if (result == NULL) { |
263 status = U_MEMORY_ALLOCATION_ERROR; | 259 status = U_MEMORY_ALLOCATION_ERROR; |
264 } | 260 } |
265 if (U_FAILURE(status)) { | 261 if (U_FAILURE(status)) { |
266 delete result; | 262 delete result; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 { | 301 { |
306 fp = new FormatParser(); | 302 fp = new FormatParser(); |
307 dtMatcher = new DateTimeMatcher(); | 303 dtMatcher = new DateTimeMatcher(); |
308 distanceInfo = new DistanceInfo(); | 304 distanceInfo = new DistanceInfo(); |
309 patternMap = new PatternMap(); | 305 patternMap = new PatternMap(); |
310 *this=other; | 306 *this=other; |
311 } | 307 } |
312 | 308 |
313 DateTimePatternGenerator& | 309 DateTimePatternGenerator& |
314 DateTimePatternGenerator::operator=(const DateTimePatternGenerator& other) { | 310 DateTimePatternGenerator::operator=(const DateTimePatternGenerator& other) { |
| 311 // reflexive case |
| 312 if (&other == this) { |
| 313 return *this; |
| 314 } |
315 pLocale = other.pLocale; | 315 pLocale = other.pLocale; |
316 fDefaultHourFormatChar = other.fDefaultHourFormatChar; | 316 fDefaultHourFormatChar = other.fDefaultHourFormatChar; |
317 *fp = *(other.fp); | 317 *fp = *(other.fp); |
318 dtMatcher->copyFrom(other.dtMatcher->skeleton); | 318 dtMatcher->copyFrom(other.dtMatcher->skeleton); |
319 *distanceInfo = *(other.distanceInfo); | 319 *distanceInfo = *(other.distanceInfo); |
320 dateTimeFormat = other.dateTimeFormat; | 320 dateTimeFormat = other.dateTimeFormat; |
321 decimal = other.decimal; | 321 decimal = other.decimal; |
322 // NUL-terminate for the C API. | 322 // NUL-terminate for the C API. |
323 dateTimeFormat.getTerminatedBuffer(); | 323 dateTimeFormat.getTerminatedBuffer(); |
324 decimal.getTerminatedBuffer(); | 324 decimal.getTerminatedBuffer(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 addICUPatterns(locale, status); | 390 addICUPatterns(locale, status); |
391 if (U_FAILURE(status)) { | 391 if (U_FAILURE(status)) { |
392 return; | 392 return; |
393 } | 393 } |
394 addCLDRData(locale, status); | 394 addCLDRData(locale, status); |
395 setDateTimeFromCalendar(locale, status); | 395 setDateTimeFromCalendar(locale, status); |
396 setDecimalSymbols(locale, status); | 396 setDecimalSymbols(locale, status); |
397 } // DateTimePatternGenerator::initData | 397 } // DateTimePatternGenerator::initData |
398 | 398 |
399 UnicodeString | 399 UnicodeString |
400 DateTimePatternGenerator::getSkeleton(const UnicodeString& pattern, UErrorCode& | 400 DateTimePatternGenerator::staticGetSkeleton( |
401 /*status*/) { | 401 const UnicodeString& pattern, UErrorCode& /*status*/) { |
402 dtMatcher->set(pattern, fp); | 402 FormatParser fp; |
403 return dtMatcher->getSkeletonPtr()->getSkeleton(); | 403 DateTimeMatcher matcher; |
| 404 PtnSkeleton localSkeleton; |
| 405 matcher.set(pattern, &fp, localSkeleton); |
| 406 return localSkeleton.getSkeleton(); |
404 } | 407 } |
405 | 408 |
406 UnicodeString | 409 UnicodeString |
407 DateTimePatternGenerator::getBaseSkeleton(const UnicodeString& pattern, UErrorCo
de& /*status*/) { | 410 DateTimePatternGenerator::staticGetBaseSkeleton( |
408 dtMatcher->set(pattern, fp); | 411 const UnicodeString& pattern, UErrorCode& /*status*/) { |
409 return dtMatcher->getSkeletonPtr()->getBaseSkeleton(); | 412 FormatParser fp; |
| 413 DateTimeMatcher matcher; |
| 414 PtnSkeleton localSkeleton; |
| 415 matcher.set(pattern, &fp, localSkeleton); |
| 416 return localSkeleton.getBaseSkeleton(); |
410 } | 417 } |
411 | 418 |
412 void | 419 void |
413 DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& statu
s) { | 420 DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& statu
s) { |
414 UnicodeString dfPattern; | 421 UnicodeString dfPattern; |
415 UnicodeString conflictingString; | 422 UnicodeString conflictingString; |
416 DateFormat* df; | 423 DateFormat* df; |
417 | 424 |
418 if (U_FAILURE(status)) { | 425 if (U_FAILURE(status)) { |
419 return; | 426 return; |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 return; | 1217 return; |
1211 } | 1218 } |
1212 if (fAvailableFormatKeyHash != NULL) { | 1219 if (fAvailableFormatKeyHash != NULL) { |
1213 delete fAvailableFormatKeyHash; | 1220 delete fAvailableFormatKeyHash; |
1214 fAvailableFormatKeyHash = NULL; | 1221 fAvailableFormatKeyHash = NULL; |
1215 } | 1222 } |
1216 initHashtable(status); | 1223 initHashtable(status); |
1217 if(U_FAILURE(status)){ | 1224 if(U_FAILURE(status)){ |
1218 return; | 1225 return; |
1219 } | 1226 } |
1220 int32_t pos = -1; | 1227 int32_t pos = UHASH_FIRST; |
1221 const UHashElement* elem = NULL; | 1228 const UHashElement* elem = NULL; |
1222 // walk through the hash table and create a deep clone | 1229 // walk through the hash table and create a deep clone |
1223 while((elem = other->nextElement(pos))!= NULL){ | 1230 while((elem = other->nextElement(pos))!= NULL){ |
1224 const UHashTok otherKeyTok = elem->key; | 1231 const UHashTok otherKeyTok = elem->key; |
1225 UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer; | 1232 UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer; |
1226 fAvailableFormatKeyHash->puti(*otherKey, 1, status); | 1233 fAvailableFormatKeyHash->puti(*otherKey, 1, status); |
1227 if(U_FAILURE(status)){ | 1234 if(U_FAILURE(status)){ |
1228 return; | 1235 return; |
1229 } | 1236 } |
1230 } | 1237 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 return; | 1333 return; |
1327 } | 1334 } |
1328 if ( this->boot[bootIndex]== NULL ) { | 1335 if ( this->boot[bootIndex]== NULL ) { |
1329 this->boot[bootIndex] = curElem; | 1336 this->boot[bootIndex] = curElem; |
1330 } | 1337 } |
1331 if ((curElem->skeleton=new PtnSkeleton(*(otherElem->skeleton))) == N
ULL ) { | 1338 if ((curElem->skeleton=new PtnSkeleton(*(otherElem->skeleton))) == N
ULL ) { |
1332 // out of memory | 1339 // out of memory |
1333 status = U_MEMORY_ALLOCATION_ERROR; | 1340 status = U_MEMORY_ALLOCATION_ERROR; |
1334 return; | 1341 return; |
1335 } | 1342 } |
1336 | 1343 curElem->skeletonWasSpecified = otherElem->skeletonWasSpecified; |
1337 if (prevElem!=NULL) { | 1344 if (prevElem!=NULL) { |
1338 prevElem->next=curElem; | 1345 prevElem->next=curElem; |
1339 } | 1346 } |
1340 curElem->next=NULL; | 1347 curElem->next=NULL; |
1341 prevElem = curElem; | 1348 prevElem = curElem; |
1342 otherElem = otherElem->next; | 1349 otherElem = otherElem->next; |
1343 } | 1350 } |
1344 | 1351 |
1345 } | 1352 } |
1346 } | 1353 } |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 if (dtTypes[i+1].minLen <= len) { | 1840 if (dtTypes[i+1].minLen <= len) { |
1834 ++i; | 1841 ++i; |
1835 continue; | 1842 continue; |
1836 } | 1843 } |
1837 return i; | 1844 return i; |
1838 } | 1845 } |
1839 return strict ? -1 : bestRow; | 1846 return strict ? -1 : bestRow; |
1840 } | 1847 } |
1841 | 1848 |
1842 UBool | 1849 UBool |
1843 FormatParser::isQuoteLiteral(const UnicodeString& s) const { | 1850 FormatParser::isQuoteLiteral(const UnicodeString& s) { |
1844 return (UBool)(s.charAt(0)==SINGLE_QUOTE); | 1851 return (UBool)(s.charAt(0)==SINGLE_QUOTE); |
1845 } | 1852 } |
1846 | 1853 |
1847 // This function aussumes the current itemIndex points to the quote literal. | 1854 // This function aussumes the current itemIndex points to the quote literal. |
1848 // Please call isQuoteLiteral prior to this function. | 1855 // Please call isQuoteLiteral prior to this function. |
1849 void | 1856 void |
1850 FormatParser::getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex) { | 1857 FormatParser::getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex) { |
1851 int32_t i=*itemIndex; | 1858 int32_t i=*itemIndex; |
1852 | 1859 |
1853 quote.remove(); | 1860 quote.remove(); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 } | 2215 } |
2209 delete fPatterns; | 2216 delete fPatterns; |
2210 } | 2217 } |
2211 | 2218 |
2212 U_NAMESPACE_END | 2219 U_NAMESPACE_END |
2213 | 2220 |
2214 | 2221 |
2215 #endif /* #if !UCONFIG_NO_FORMATTING */ | 2222 #endif /* #if !UCONFIG_NO_FORMATTING */ |
2216 | 2223 |
2217 //eof | 2224 //eof |
OLD | NEW |