From 3727ad903b4e111061ed0b5277ab937ae57f7a29 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Sat, 4 Aug 2007 14:19:29 +0000 Subject: [PATCH] ICU-5787 Minor code cleanup. X-SVN-Rev: 22282 --- icu4c/source/i18n/dtptngen.cpp | 58 +++++++++------------------- icu4c/source/i18n/unicode/dtptngen.h | 7 ---- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp index 7435c83c772..12df3395b3f 100644 --- a/icu4c/source/i18n/dtptngen.cpp +++ b/icu4c/source/i18n/dtptngen.cpp @@ -208,12 +208,7 @@ DateTimePatternGenerator::operator==(const DateTimePatternGenerator& other) cons if (this == &other) { return TRUE; } - if ((pLocale==other.pLocale) && (patternMap->equals(*other.patternMap))) { - return TRUE; - } - else { - return FALSE; - } + return (UBool)((pLocale==other.pLocale) && (patternMap->equals(*other.patternMap))); } DateTimePatternGenerator::~DateTimePatternGenerator() { @@ -277,15 +272,13 @@ DateTimePatternGenerator::addICUPatterns(const Locale& locale) { UErrorCode status = U_ZERO_ERROR; // Load with ICU patterns - for (DateFormat::EStyle i=DateFormat::kFull; i<=DateFormat::kShort; i=(DateFormat::EStyle)(i+1)) { - dfPattern.remove(); - if ((df = (SimpleDateFormat*)DateFormat::createDateInstance(i, locale))!= NULL) { + for (int32_t i=DateFormat::kFull; i<=DateFormat::kShort; i++) { + if ((df = (SimpleDateFormat*)DateFormat::createDateInstance((DateFormat::EStyle)i, locale))!= NULL) { conflictingStatus = addPattern(df->toPattern(dfPattern), FALSE, conflictingString, status); delete df; } - dfPattern.remove(); - if ((df = (SimpleDateFormat*)DateFormat::createTimeInstance(i, locale)) != NULL) { + if ((df = (SimpleDateFormat*)DateFormat::createTimeInstance((DateFormat::EStyle)i, locale)) != NULL) { conflictingStatus = addPattern(df->toPattern(dfPattern), FALSE, conflictingString, status); if (U_FAILURE(status)) { delete df; @@ -298,7 +291,6 @@ DateTimePatternGenerator::addICUPatterns(const Locale& locale) { delete df; } } - } void @@ -500,7 +492,8 @@ DateTimePatternGenerator::initHashtable(UErrorCode& err) { if (fAvailableFormatKeyHash!=NULL) { return; } - if ((fAvailableFormatKeyHash = new Hashtable(FALSE, err))!=NULL) { + if ((fAvailableFormatKeyHash = new Hashtable(FALSE, err))==NULL) { + err=U_MEMORY_ALLOCATION_ERROR; return; } } @@ -541,7 +534,6 @@ UnicodeString DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UErrorCode& status) { const UnicodeString *bestPattern=NULL; UnicodeString dtFormat; - UErrorCode err = U_ZERO_ERROR; UnicodeString resultPattern; int32_t dateMask=(1<geti(key); - if ( i==1 ) { - return TRUE; - } - else{ - return FALSE; - } + return (UBool)(fAvailableFormatKeyHash->geti(key) == 1); } void @@ -1138,7 +1121,7 @@ PatternMap::getPatternFromBasePattern(UnicodeString& basePattern) { // key to se // the baseChar must be A-Z or a-z if ( (baseChar >= CAP_A) && (baseChar <= CAP_Z) ) { - curElem = boot[26 + (baseChar-CAP_A)]; + curElem = boot[26 + (baseChar-CAP_A)]; } else { if ( (baseChar >=LOW_A) && (baseChar <= LOW_Z) ) { @@ -1149,14 +1132,14 @@ PatternMap::getPatternFromBasePattern(UnicodeString& basePattern) { // key to se } if ( curElem == NULL ) { - return NULL; // no match + return NULL; // no match } do { - if ( basePattern.compare(curElem->basePattern)==0 ) { - return &(curElem->pattern); - } - curElem=curElem->next; + if ( basePattern.compare(curElem->basePattern)==0 ) { + return &(curElem->pattern); + } + curElem=curElem->next; }while (curElem != NULL); return NULL; @@ -1190,7 +1173,7 @@ PatternMap::getPatternFromSkeleton(PtnSkeleton& skeleton) { // key to search for } if ( curElem == NULL ) { - return NULL; // no match + return NULL; // no match } do { @@ -1530,13 +1513,8 @@ FormatParser::getCanonicalIndex(const UnicodeString& s) { UBool FormatParser::isQuoteLiteral(UnicodeString s) { - if ((s.charAt(0)==SINGLE_QUOTE)||(s.charAt(0)==FORWARDSLASH)||(s.charAt(0)==BACKSLASH) || - (s.charAt(0)==SPACE) ||(s.charAt(0)==COMMA) ||(s.charAt(0)==HYPHEN) ||(s.charAt(0)==DOT) ) { - return TRUE; - } - else { - return FALSE; - } + return (UBool)((s.charAt(0)==SINGLE_QUOTE)||(s.charAt(0)==FORWARDSLASH)||(s.charAt(0)==BACKSLASH) || + (s.charAt(0)==SPACE) ||(s.charAt(0)==COMMA) ||(s.charAt(0)==HYPHEN) ||(s.charAt(0)==DOT) ); } // This function aussumes the current itemIndex points to the quote literal. diff --git a/icu4c/source/i18n/unicode/dtptngen.h b/icu4c/source/i18n/unicode/dtptngen.h index 74abc4a5936..bd7d179bcc9 100644 --- a/icu4c/source/i18n/unicode/dtptngen.h +++ b/icu4c/source/i18n/unicode/dtptngen.h @@ -12,20 +12,13 @@ #ifndef __DTPTNGEN_H__ #define __DTPTNGEN_H__ -#include "unicode/utypes.h" -#include "unicode/format.h" #include "unicode/datefmt.h" -#include "unicode/calendar.h" -#include "unicode/ustring.h" #include "unicode/locid.h" #include "unicode/udat.h" #include "unicode/udatpg.h" -#include "unicode/uniset.h" U_NAMESPACE_BEGIN -class DateFormatSymbols; -class DateFormat; class Hashtable; class FormatParser; class DateTimeMatcher;