| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************* | 2 ******************************************************************************* |
| 3 * Copyright (C) 2008-2014, Google, International Business Machines Corporation | 3 * Copyright (C) 2008-2014, 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 "unicode/tmutfmt.h" | 8 #include "unicode/tmutfmt.h" |
| 9 | 9 |
| 10 #if !UCONFIG_NO_FORMATTING | 10 #if !UCONFIG_NO_FORMATTING |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 char res[1000]; | 182 char res[1000]; |
| 183 source.extract(0, source.length(), res, "UTF-8"); | 183 source.extract(0, source.length(), res, "UTF-8"); |
| 184 std::cout << "parse source: " << res << "\n"; | 184 std::cout << "parse source: " << res << "\n"; |
| 185 #endif | 185 #endif |
| 186 // parse by iterating through all available patterns | 186 // parse by iterating through all available patterns |
| 187 // and looking for the longest match. | 187 // and looking for the longest match. |
| 188 for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; | 188 for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; |
| 189 i < TimeUnit::UTIMEUNIT_FIELD_COUNT; | 189 i < TimeUnit::UTIMEUNIT_FIELD_COUNT; |
| 190 i = (TimeUnit::UTimeUnitFields)(i+1)) { | 190 i = (TimeUnit::UTimeUnitFields)(i+1)) { |
| 191 Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i]; | 191 Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i]; |
| 192 int32_t elemPos = -1; | 192 int32_t elemPos = UHASH_FIRST; |
| 193 const UHashElement* elem = NULL; | 193 const UHashElement* elem = NULL; |
| 194 while ((elem = countToPatterns->nextElement(elemPos)) != NULL){ | 194 while ((elem = countToPatterns->nextElement(elemPos)) != NULL){ |
| 195 const UHashTok keyTok = elem->key; | 195 const UHashTok keyTok = elem->key; |
| 196 UnicodeString* count = (UnicodeString*)keyTok.pointer; | 196 UnicodeString* count = (UnicodeString*)keyTok.pointer; |
| 197 #ifdef TMUTFMT_DEBUG | 197 #ifdef TMUTFMT_DEBUG |
| 198 count->extract(0, count->length(), res, "UTF-8"); | 198 count->extract(0, count->length(), res, "UTF-8"); |
| 199 std::cout << "parse plural count: " << res << "\n"; | 199 std::cout << "parse plural count: " << res << "\n"; |
| 200 #endif | 200 #endif |
| 201 const UHashTok valueTok = elem->value; | 201 const UHashTok valueTok = elem->value; |
| 202 // the value is a pair of MessageFormat* | 202 // the value is a pair of MessageFormat* |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 TimeUnitFormat::setNumberFormat(const NumberFormat& format, UErrorCode& status){ | 679 TimeUnitFormat::setNumberFormat(const NumberFormat& format, UErrorCode& status){ |
| 680 if (U_FAILURE(status)) { | 680 if (U_FAILURE(status)) { |
| 681 return; | 681 return; |
| 682 } | 682 } |
| 683 adoptNumberFormat((NumberFormat *)format.clone(), status); | 683 adoptNumberFormat((NumberFormat *)format.clone(), status); |
| 684 } | 684 } |
| 685 | 685 |
| 686 | 686 |
| 687 void | 687 void |
| 688 TimeUnitFormat::deleteHash(Hashtable* htable) { | 688 TimeUnitFormat::deleteHash(Hashtable* htable) { |
| 689 int32_t pos = -1; | 689 int32_t pos = UHASH_FIRST; |
| 690 const UHashElement* element = NULL; | 690 const UHashElement* element = NULL; |
| 691 if ( htable ) { | 691 if ( htable ) { |
| 692 while ( (element = htable->nextElement(pos)) != NULL ) { | 692 while ( (element = htable->nextElement(pos)) != NULL ) { |
| 693 const UHashTok valueTok = element->value; | 693 const UHashTok valueTok = element->value; |
| 694 const MessageFormat** value = (const MessageFormat**)valueTok.pointe
r; | 694 const MessageFormat** value = (const MessageFormat**)valueTok.pointe
r; |
| 695 delete value[UTMUTFMT_FULL_STYLE]; | 695 delete value[UTMUTFMT_FULL_STYLE]; |
| 696 delete value[UTMUTFMT_ABBREVIATED_STYLE]; | 696 delete value[UTMUTFMT_ABBREVIATED_STYLE]; |
| 697 //delete[] value; | 697 //delete[] value; |
| 698 uprv_free(value); | 698 uprv_free(value); |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 delete htable; | 701 delete htable; |
| 702 } | 702 } |
| 703 | 703 |
| 704 | 704 |
| 705 void | 705 void |
| 706 TimeUnitFormat::copyHash(const Hashtable* source, Hashtable* target, UErrorCode&
status) { | 706 TimeUnitFormat::copyHash(const Hashtable* source, Hashtable* target, UErrorCode&
status) { |
| 707 if ( U_FAILURE(status) ) { | 707 if ( U_FAILURE(status) ) { |
| 708 return; | 708 return; |
| 709 } | 709 } |
| 710 int32_t pos = -1; | 710 int32_t pos = UHASH_FIRST; |
| 711 const UHashElement* element = NULL; | 711 const UHashElement* element = NULL; |
| 712 if ( source ) { | 712 if ( source ) { |
| 713 while ( (element = source->nextElement(pos)) != NULL ) { | 713 while ( (element = source->nextElement(pos)) != NULL ) { |
| 714 const UHashTok keyTok = element->key; | 714 const UHashTok keyTok = element->key; |
| 715 const UnicodeString* key = (UnicodeString*)keyTok.pointer; | 715 const UnicodeString* key = (UnicodeString*)keyTok.pointer; |
| 716 const UHashTok valueTok = element->value; | 716 const UHashTok valueTok = element->value; |
| 717 const MessageFormat** value = (const MessageFormat**)valueTok.pointe
r; | 717 const MessageFormat** value = (const MessageFormat**)valueTok.pointe
r; |
| 718 MessageFormat** newVal = (MessageFormat**)uprv_malloc(UTMUTFMT_FORMA
T_STYLE_COUNT*sizeof(MessageFormat*)); | 718 MessageFormat** newVal = (MessageFormat**)uprv_malloc(UTMUTFMT_FORMA
T_STYLE_COUNT*sizeof(MessageFormat*)); |
| 719 newVal[0] = (MessageFormat*)value[0]->clone(); | 719 newVal[0] = (MessageFormat*)value[0]->clone(); |
| 720 newVal[1] = (MessageFormat*)value[1]->clone(); | 720 newVal[1] = (MessageFormat*)value[1]->clone(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 return gTimeUnitSecond; | 792 return gTimeUnitSecond; |
| 793 default: | 793 default: |
| 794 status = U_ILLEGAL_ARGUMENT_ERROR; | 794 status = U_ILLEGAL_ARGUMENT_ERROR; |
| 795 return NULL; | 795 return NULL; |
| 796 } | 796 } |
| 797 } | 797 } |
| 798 | 798 |
| 799 U_NAMESPACE_END | 799 U_NAMESPACE_END |
| 800 | 800 |
| 801 #endif | 801 #endif |
| OLD | NEW |