OLD | NEW |
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (C) 2008-2012, International Business Machines Corporation and | 2 * Copyright (C) 2008-2015, International Business Machines Corporation and |
3 * others. All Rights Reserved. | 3 * others. All Rights Reserved. |
4 ******************************************************************************* | 4 ******************************************************************************* |
5 * | 5 * |
6 * File DTITVINF.CPP | 6 * File DTITVINF.CPP |
7 * | 7 * |
8 ******************************************************************************* | 8 ******************************************************************************* |
9 */ | 9 */ |
10 | 10 |
11 #include "unicode/dtitvinf.h" | 11 #include "unicode/dtitvinf.h" |
12 | 12 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) | 216 DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) |
217 { | 217 { |
218 fIntervalPatterns = initHash(err); | 218 fIntervalPatterns = initHash(err); |
219 if ( U_FAILURE(err) ) { | 219 if ( U_FAILURE(err) ) { |
220 return; | 220 return; |
221 } | 221 } |
222 const char *locName = locale.getName(); | 222 const char *locName = locale.getName(); |
223 char parentLocale[ULOC_FULLNAME_CAPACITY]; | 223 char parentLocale[ULOC_FULLNAME_CAPACITY]; |
224 uprv_strcpy(parentLocale, locName); | 224 uprv_strcpy(parentLocale, locName); |
225 UErrorCode status = U_ZERO_ERROR; | 225 UErrorCode status = U_ZERO_ERROR; |
226 Hashtable skeletonSet(FALSE, status); | 226 Hashtable skeletonKeyPairs(FALSE, status); |
227 if ( U_FAILURE(status) ) { | 227 if ( U_FAILURE(status) ) { |
228 return; | 228 return; |
229 } | 229 } |
230 | 230 |
231 // determine calendar type | 231 // determine calendar type |
232 const char * calendarTypeToUse = gGregorianTag; // initial default | 232 const char * calendarTypeToUse = gGregorianTag; // initial default |
233 char calendarType[ULOC_KEYWORDS_CAPACITY]; // to be filled in with the
type to use, if all goes well | 233 char calendarType[ULOC_KEYWORDS_CAPACITY]; // to be filled in with the
type to use, if all goes well |
234 char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY]; | 234 char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY]; |
235 // obtain a locale that always has the calendar key value that should be used | 235 // obtain a locale that always has the calendar key value that should be used |
236 (void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFI
ER_CAPACITY, NULL, | 236 (void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFI
ER_CAPACITY, NULL, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 int32_t index; | 270 int32_t index; |
271 for ( index = 0; index < size; ++index ) { | 271 for ( index = 0; index < size; ++index ) { |
272 LocalUResourceBundlePointer oneRes(ures_getByIndex(itvDtPtnResource,
index, | 272 LocalUResourceBundlePointer oneRes(ures_getByIndex(itvDtPtnResource,
index, |
273 NULL, &status)); | 273 NULL, &status)); |
274 if ( U_SUCCESS(status) ) { | 274 if ( U_SUCCESS(status) ) { |
275 const char* skeleton = ures_getKey(oneRes.getAlias()); | 275 const char* skeleton = ures_getKey(oneRes.getAlias()); |
276 if (skeleton == NULL) { | 276 if (skeleton == NULL) { |
277 continue; | 277 continue; |
278 } | 278 } |
279 UnicodeString skeletonUniStr(skeleton, -1, US_INV); | 279 UnicodeString skeletonUniStr(skeleton, -1, US_INV); |
280 if ( skeletonSet.geti(skeletonUniStr) == 1 ) { | |
281 continue; | |
282 } | |
283 skeletonSet.puti(skeletonUniStr, 1, status); | |
284 if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) { | 280 if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) { |
285 continue; // fallback | 281 continue; // fallback |
286 } | 282 } |
287 | 283 |
288 LocalUResourceBundlePointer intervalPatterns(ures_getByKey( | 284 LocalUResourceBundlePointer intervalPatterns(ures_getByKey( |
289 itvDtPtnResource, skeleton, NULL, &status))
; | 285 itvDtPtnResource, skeleton, NULL, &status))
; |
290 | 286 |
291 if ( U_FAILURE(status) ) { | 287 if ( U_FAILURE(status) ) { |
292 break; | 288 break; |
293 } | 289 } |
294 if ( intervalPatterns == NULL ) { | 290 if ( intervalPatterns == NULL ) { |
295 continue; | 291 continue; |
296 } | 292 } |
297 | 293 |
298 const char* key; | 294 const char* key; |
299 int32_t ptnNum = ures_getSize(intervalPatterns.getAlias()); | 295 int32_t ptnNum = ures_getSize(intervalPatterns.getAlias()); |
300 int32_t ptnIndex; | 296 int32_t ptnIndex; |
301 for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) { | 297 for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) { |
302 UnicodeString pattern = | 298 UnicodeString pattern = |
303 ures_getNextUnicodeString(intervalPatterns.getAlias(), &
key, &status); | 299 ures_getNextUnicodeString(intervalPatterns.getAlias(), &
key, &status); |
304 if ( U_FAILURE(status) ) { | 300 if ( U_FAILURE(status) ) { |
305 break; | 301 break; |
306 } | 302 } |
| 303 UnicodeString keyUniStr(key, -1, US_INV); |
| 304 UnicodeString skeletonKeyPair(skeletonUniStr + keyUniStr); |
| 305 if ( skeletonKeyPairs.geti(skeletonKeyPair) == 1 ) { |
| 306 continue; |
| 307 } |
| 308 skeletonKeyPairs.puti(skeletonKeyPair, 1, status); |
307 | 309 |
308 UCalendarDateFields calendarField = UCAL_FIELD_COUNT; | 310 UCalendarDateFields calendarField = UCAL_FIELD_COUNT; |
309 if ( !uprv_strcmp(key, "y") ) { | 311 if ( !uprv_strcmp(key, "y") ) { |
310 calendarField = UCAL_YEAR; | 312 calendarField = UCAL_YEAR; |
311 } else if ( !uprv_strcmp(key, "M") ) { | 313 } else if ( !uprv_strcmp(key, "M") ) { |
312 calendarField = UCAL_MONTH; | 314 calendarField = UCAL_MONTH; |
313 } else if ( !uprv_strcmp(key, "d") ) { | 315 } else if ( !uprv_strcmp(key, "d") ) { |
314 calendarField = UCAL_DATE; | 316 calendarField = UCAL_DATE; |
315 } else if ( !uprv_strcmp(key, "a") ) { | 317 } else if ( !uprv_strcmp(key, "a") ) { |
316 calendarField = UCAL_AM_PM; | 318 calendarField = UCAL_AM_PM; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 int32_t bestDistance = MAX_POSITIVE_INT; | 476 int32_t bestDistance = MAX_POSITIVE_INT; |
475 const UnicodeString* bestSkeleton = NULL; | 477 const UnicodeString* bestSkeleton = NULL; |
476 | 478 |
477 // 0 means exact the same skeletons; | 479 // 0 means exact the same skeletons; |
478 // 1 means having the same field, but with different length, | 480 // 1 means having the same field, but with different length, |
479 // 2 means only z/v differs | 481 // 2 means only z/v differs |
480 // -1 means having different field. | 482 // -1 means having different field. |
481 bestMatchDistanceInfo = 0; | 483 bestMatchDistanceInfo = 0; |
482 int8_t fieldLength = sizeof(skeletonFieldWidth)/sizeof(skeletonFieldWidth[0]
); | 484 int8_t fieldLength = sizeof(skeletonFieldWidth)/sizeof(skeletonFieldWidth[0]
); |
483 | 485 |
484 int32_t pos = -1; | 486 int32_t pos = UHASH_FIRST; |
485 const UHashElement* elem = NULL; | 487 const UHashElement* elem = NULL; |
486 while ( (elem = fIntervalPatterns->nextElement(pos)) != NULL ) { | 488 while ( (elem = fIntervalPatterns->nextElement(pos)) != NULL ) { |
487 const UHashTok keyTok = elem->key; | 489 const UHashTok keyTok = elem->key; |
488 UnicodeString* skeleton = (UnicodeString*)keyTok.pointer; | 490 UnicodeString* skeleton = (UnicodeString*)keyTok.pointer; |
489 #ifdef DTITVINF_DEBUG | 491 #ifdef DTITVINF_DEBUG |
490 skeleton->extract(0, skeleton->length(), result, "UTF-8"); | 492 skeleton->extract(0, skeleton->length(), result, "UTF-8"); |
491 sprintf(mesg, "available skeletons: skeleton: %s; \n", result); | 493 sprintf(mesg, "available skeletons: skeleton: %s; \n", result); |
492 PRINTMESG(mesg) | 494 PRINTMESG(mesg) |
493 #endif | 495 #endif |
494 | 496 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 case UCAL_AM_PM: | 567 case UCAL_AM_PM: |
566 index = kIPI_AM_PM; | 568 index = kIPI_AM_PM; |
567 break; | 569 break; |
568 case UCAL_HOUR: | 570 case UCAL_HOUR: |
569 case UCAL_HOUR_OF_DAY: | 571 case UCAL_HOUR_OF_DAY: |
570 index = kIPI_HOUR; | 572 index = kIPI_HOUR; |
571 break; | 573 break; |
572 case UCAL_MINUTE: | 574 case UCAL_MINUTE: |
573 index = kIPI_MINUTE; | 575 index = kIPI_MINUTE; |
574 break; | 576 break; |
| 577 case UCAL_SECOND: |
| 578 index = kIPI_SECOND; |
| 579 break; |
575 default: | 580 default: |
576 status = U_ILLEGAL_ARGUMENT_ERROR; | 581 status = U_ILLEGAL_ARGUMENT_ERROR; |
577 } | 582 } |
578 return index; | 583 return index; |
579 } | 584 } |
580 | 585 |
581 | 586 |
582 | 587 |
583 void | 588 void |
584 DateIntervalInfo::deleteHash(Hashtable* hTable) | 589 DateIntervalInfo::deleteHash(Hashtable* hTable) |
585 { | 590 { |
586 if ( hTable == NULL ) { | 591 if ( hTable == NULL ) { |
587 return; | 592 return; |
588 } | 593 } |
589 int32_t pos = -1; | 594 int32_t pos = UHASH_FIRST; |
590 const UHashElement* element = NULL; | 595 const UHashElement* element = NULL; |
591 while ( (element = hTable->nextElement(pos)) != NULL ) { | 596 while ( (element = hTable->nextElement(pos)) != NULL ) { |
592 const UHashTok valueTok = element->value; | 597 const UHashTok valueTok = element->value; |
593 const UnicodeString* value = (UnicodeString*)valueTok.pointer; | 598 const UnicodeString* value = (UnicodeString*)valueTok.pointer; |
594 delete[] value; | 599 delete[] value; |
595 } | 600 } |
596 delete fIntervalPatterns; | 601 delete fIntervalPatterns; |
597 } | 602 } |
598 | 603 |
599 | 604 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 } | 647 } |
643 | 648 |
644 | 649 |
645 void | 650 void |
646 DateIntervalInfo::copyHash(const Hashtable* source, | 651 DateIntervalInfo::copyHash(const Hashtable* source, |
647 Hashtable* target, | 652 Hashtable* target, |
648 UErrorCode& status) { | 653 UErrorCode& status) { |
649 if ( U_FAILURE(status) ) { | 654 if ( U_FAILURE(status) ) { |
650 return; | 655 return; |
651 } | 656 } |
652 int32_t pos = -1; | 657 int32_t pos = UHASH_FIRST; |
653 const UHashElement* element = NULL; | 658 const UHashElement* element = NULL; |
654 if ( source ) { | 659 if ( source ) { |
655 while ( (element = source->nextElement(pos)) != NULL ) { | 660 while ( (element = source->nextElement(pos)) != NULL ) { |
656 const UHashTok keyTok = element->key; | 661 const UHashTok keyTok = element->key; |
657 const UnicodeString* key = (UnicodeString*)keyTok.pointer; | 662 const UnicodeString* key = (UnicodeString*)keyTok.pointer; |
658 const UHashTok valueTok = element->value; | 663 const UHashTok valueTok = element->value; |
659 const UnicodeString* value = (UnicodeString*)valueTok.pointer; | 664 const UnicodeString* value = (UnicodeString*)valueTok.pointer; |
660 UnicodeString* copy = new UnicodeString[kIPI_MAX_INDEX]; | 665 UnicodeString* copy = new UnicodeString[kIPI_MAX_INDEX]; |
661 int8_t i; | 666 int8_t i; |
662 for ( i = 0; i < kIPI_MAX_INDEX; ++i ) { | 667 for ( i = 0; i < kIPI_MAX_INDEX; ++i ) { |
663 copy[i] = value[i]; | 668 copy[i] = value[i]; |
664 } | 669 } |
665 target->put(UnicodeString(*key), copy, status); | 670 target->put(UnicodeString(*key), copy, status); |
666 if ( U_FAILURE(status) ) { | 671 if ( U_FAILURE(status) ) { |
667 return; | 672 return; |
668 } | 673 } |
669 } | 674 } |
670 } | 675 } |
671 } | 676 } |
672 | 677 |
673 | 678 |
674 U_NAMESPACE_END | 679 U_NAMESPACE_END |
675 | 680 |
676 #endif | 681 #endif |
OLD | NEW |