diff --git a/icu4c/source/i18n/brkiter.cpp b/icu4c/source/i18n/brkiter.cpp index 8fc8086b2e0..d2713ac1e48 100644 --- a/icu4c/source/i18n/brkiter.cpp +++ b/icu4c/source/i18n/brkiter.cpp @@ -22,7 +22,7 @@ #include "unicode/brkiter.h" #include "unicode/udata.h" #include "unicode/resbund.h" - +#include "cstring.h" #include // ***************************************************************************** @@ -48,7 +48,8 @@ BreakIterator::createWordInstance(const Locale& key, UErrorCode& status) UnicodeString temp; if (U_FAILURE(status)) return NULL; - if (key.getLanguage(temp) == UnicodeString("th", (char*)0)) { + if (!uprv_strcmp(key.getLanguage(), "th")) + { filename = "word_th"; } @@ -58,7 +59,7 @@ BreakIterator::createWordInstance(const Locale& key, UErrorCode& status) const void* image = udata_getMemory(file); if (image != NULL) { - if (key.getLanguage(temp) == UnicodeString("th", (char*)0)) { + if(!uprv_strcmp(filename, "word_th")) { const char* dataDir = u_getDataDirectory(); filename = "thaidict.brk"; char* fullPath = new char[strlen(dataDir) + strlen(filename) + 1]; @@ -91,7 +92,8 @@ BreakIterator::createLineInstance(const Locale& key, UErrorCode& status) UnicodeString temp; if (U_FAILURE(status)) return NULL; - if (key.getLanguage(temp) == UnicodeString("th", (char*)0)) { + if (!uprv_strcmp(key.getLanguage(), "th")) + { filename = "line_th"; } @@ -101,7 +103,7 @@ BreakIterator::createLineInstance(const Locale& key, UErrorCode& status) const void* image = udata_getMemory(file); if (image != NULL) { - if (key.getLanguage(temp) == UnicodeString("th", (char*)0)) { + if (!uprv_strcmp(key.getLanguage(), "th")) { const char* dataDir = u_getDataDirectory(); filename = "thaidict.brk"; char* fullPath = new char[strlen(dataDir) + strlen(filename) + 1]; diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index a916630897a..e9f5eb607b6 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -706,7 +706,7 @@ Calendar::setWeekCountData(const Locale& desiredLocale, UErrorCode& status) int32_t count; if (U_FAILURE(status)) return; - ResourceBundle resource(Locale::getDataDirectory(), desiredLocale, status); + ResourceBundle resource(u_getDataDirectory(), desiredLocale, status); // If the resource data doesn't seem to be present at all, then use last-resort // hard-coded data. diff --git a/icu4c/source/i18n/datefmt.cpp b/icu4c/source/i18n/datefmt.cpp index 2fb6443d31a..3ceae9b218a 100644 --- a/icu4c/source/i18n/datefmt.cpp +++ b/icu4c/source/i18n/datefmt.cpp @@ -242,7 +242,7 @@ DateFormat::getAvailableLocales(int32_t& count) for (i=0; idesiredLocale = desiredLocale; - desiredLocale.getName(localeName); + localeName = desiredLocale.getName(); data->realLocaleName = localeName; addToCache(localeName); @@ -849,7 +848,7 @@ RuleBasedCollator::RuleBasedCollator( const Locale& desiredLocale, { case eTryDefaultLocale: status = U_USING_DEFAULT_ERROR; - Locale::getDefault().getName(localeName); + localeName = Locale::getDefault().getName(); next = eTryDefaultCollation; break; @@ -945,7 +944,7 @@ RuleBasedCollator::constructFromFile( const Locale& locale, data = 0; } - char *binaryFilePath = createPathName(UnicodeString(Locale::getDataDirectory(),""), + char *binaryFilePath = createPathName(UnicodeString(u_getDataDirectory(),""), localeFileName, UnicodeString(kFilenameSuffix,"")); if(tryBinaryFile) { @@ -962,10 +961,16 @@ RuleBasedCollator::constructFromFile( const Locale& locale, } // Now try to load it up from a resource bundle text source file - UnicodeString dataDir = UnicodeString(Locale::getDataDirectory(),""); + UnicodeString dataDir = UnicodeString(u_getDataDirectory(),""); - ResourceBundle bundle(dataDir, localeFileName, status); + char *ch; + ch = new char[localeFileName.size() + 1]; + ch[localeFileName.extract(0, 0x7fffffff, ch, "")] = 0; + ResourceBundle bundle(dataDir, ch, status); + + delete [] ch; + // if there is no resource bundle file for the give locale, break out if(U_FAILURE(status)) { diff --git a/icu4c/source/i18n/translit.cpp b/icu4c/source/i18n/translit.cpp index cd52f3ba28a..9cf92c22f65 100644 --- a/icu4c/source/i18n/translit.cpp +++ b/icu4c/source/i18n/translit.cpp @@ -383,7 +383,7 @@ UnicodeString& Transliterator::getDisplayName(const UnicodeString& ID, const Locale& inLocale, UnicodeString& result) { UErrorCode status = U_ZERO_ERROR; - ResourceBundle bundle(Locale::getDataDirectory(), inLocale, status); + ResourceBundle bundle(u_getDataDirectory(), inLocale, status); // Suspend checking status until later... // build the char* key @@ -572,7 +572,7 @@ const char* Transliterator::RESOURCE_SUB_DIR = "translit"; /** * Returns the directory in which the transliterator resource bundle * files are located. This is a subdirectory, named RESOURCE_SUB_DIR, - * under Locale::getDataDirectory(). It ends in a path separator. + * under u_getDataDirectory(). It ends in a path separator. */ const char* Transliterator::getDataDirectory(void) { if (DATA_DIR == 0) { @@ -581,7 +581,7 @@ const char* Transliterator::getDataDirectory(void) { /* Construct the transliterator data directory path. This * is a subdirectory of the locale data directory. */ - const char* data = Locale::getDataDirectory(); + const char* data = u_getDataDirectory(); int32_t len = uprv_strlen(data); DATA_DIR = (char*) uprv_malloc( len + uprv_strlen(RESOURCE_SUB_DIR) + 2); @@ -642,7 +642,11 @@ Transliterator* Transliterator::_createInstance(const UnicodeString& ID, // 2-d array at static init time, as a locale language. We're // just using the locale mechanism to map through to a file // name; this in no way represents an actual locale. - Locale fakeLocale(entry->rbFile); + char *ch; + ch = new char[entry->rbFile.size() + 1]; + ch[entry->rbFile.extract(0, 0x7fffffff, ch, "")] = 0; + Locale fakeLocale(ch); + delete [] ch; ResourceBundle bundle(Transliterator::getDataDirectory(), fakeLocale, status); @@ -864,7 +868,7 @@ void Transliterator::initializeCache(void) { * } */ - Locale indexLoc(UNICODE_STRING("index", 5)); + Locale indexLoc("index"); ResourceBundle bundle(Transliterator::getDataDirectory(), indexLoc, status); diff --git a/icu4c/source/i18n/ubrk.cpp b/icu4c/source/i18n/ubrk.cpp index 88df6ce9080..078bf90efbe 100644 --- a/icu4c/source/i18n/ubrk.cpp +++ b/icu4c/source/i18n/ubrk.cpp @@ -26,19 +26,19 @@ ubrk_open(UBreakIteratorType type, switch(type) { case UBRK_CHARACTER: - result = BreakIterator::createCharacterInstance(Locale().init(locale), *status); + result = BreakIterator::createCharacterInstance(Locale(locale), *status); break; case UBRK_WORD: - result = BreakIterator::createWordInstance(Locale().init(locale), *status); + result = BreakIterator::createWordInstance(Locale(locale), *status); break; case UBRK_LINE: - result = BreakIterator::createLineInstance(Locale().init(locale), *status); + result = BreakIterator::createLineInstance(Locale(locale), *status); break; case UBRK_SENTENCE: - result = BreakIterator::createSentenceInstance(Locale().init(locale), *status); + result = BreakIterator::createSentenceInstance(Locale(locale), *status); break; } diff --git a/icu4c/source/i18n/ucal.cpp b/icu4c/source/i18n/ucal.cpp index cc799eeb9b8..e100d2c30c9 100644 --- a/icu4c/source/i18n/ucal.cpp +++ b/icu4c/source/i18n/ucal.cpp @@ -87,7 +87,7 @@ ucal_open( const UChar* zoneID, return 0; } - return (UCalendar*)Calendar::createInstance(zone, Locale().init(locale), *status); + return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status); } U_CAPI void @@ -138,19 +138,19 @@ ucal_getTimeZoneDisplayName( const UCalendar* cal, switch(type) { case UCAL_STANDARD: - tz.getDisplayName(FALSE, TimeZone::LONG, Locale().init(locale), id); + tz.getDisplayName(FALSE, TimeZone::LONG, Locale(locale), id); break; case UCAL_SHORT_STANDARD: - tz.getDisplayName(FALSE, TimeZone::SHORT, Locale().init(locale), id); + tz.getDisplayName(FALSE, TimeZone::SHORT, Locale(locale), id); break; case UCAL_DST: - tz.getDisplayName(TRUE, TimeZone::LONG, Locale().init(locale), id); + tz.getDisplayName(TRUE, TimeZone::LONG, Locale(locale), id); break; case UCAL_SHORT_DST: - tz.getDisplayName(TRUE, TimeZone::SHORT, Locale().init(locale), id); + tz.getDisplayName(TRUE, TimeZone::SHORT, Locale(locale), id); break; } diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index c321fe393c3..674757b3ff1 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -70,7 +70,7 @@ ucol_open( const char *loc, if(loc == 0) col = Collator::createInstance(*status); else - col = Collator::createInstance(Locale().init(loc), *status); + col = Collator::createInstance(Locale(loc), *status); if(col == 0) { *status = U_MEMORY_ALLOCATION_ERROR; @@ -248,7 +248,7 @@ ucol_getDisplayName( const char *objLoc, if(U_FAILURE(*status)) return -1; UnicodeString dst(result, resultLength, resultLength); - Collator::getDisplayName(Locale().init(objLoc), Locale().init(dispLoc), dst); + Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst); int32_t actLen; T_fillOutputParams(&dst, result, resultLength, &actLen, status); return actLen; diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp index 1eb90d631c8..cbd5062c065 100644 --- a/icu4c/source/i18n/udat.cpp +++ b/icu4c/source/i18n/udat.cpp @@ -36,7 +36,7 @@ udat_open( UDateFormatStyle timeStyle, else fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle, (DateFormat::EStyle)timeStyle, - Locale().init(locale)); + Locale(locale)); if(fmt == 0) { *status = U_MEMORY_ALLOCATION_ERROR; @@ -77,7 +77,7 @@ udat_openPattern( const UChar *pattern, else retVal = (UDateFormat*)new SimpleDateFormat(UnicodeString((UChar*)pattern, len, len), - Locale().init(locale), + Locale(locale), *status); if(retVal == 0) { diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index bf38d5f0d11..dba2a994f79 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -411,7 +411,7 @@ u_vformatMessage( const char *locale, // just call through to the C++ implementation UnicodeString patString((UChar*)pattern, patLen, patLen); - MessageFormat fmt(patString, Locale().init(locale), *status); + MessageFormat fmt(patString, Locale(locale), *status); UnicodeString res(result, 0, resultLength); FieldPosition fp; fmt.format(args, count, res, fp, *status); @@ -462,7 +462,7 @@ u_vparseMessage( const char *locale, int32_t srcLen = (sourceLength == -1 ? u_strlen(source) : sourceLength); UnicodeString patString((UChar*)pattern, patLen, patLen); - MessageFormat fmt(patString, Locale().init(locale), *status); + MessageFormat fmt(patString, Locale(locale), *status); UnicodeString srcString((UChar*)source, srcLen, srcLen); int32_t count = 0; Formattable *args = fmt.parse(srcString, count, *status); diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 1111252acee..1b9c4897ce7 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -34,7 +34,7 @@ unum_open( UNumberFormatStyle style, if(locale == 0) retVal = (UNumberFormat*)NumberFormat::createInstance(*status); else - retVal = (UNumberFormat*)NumberFormat::createInstance(Locale().init(locale), + retVal = (UNumberFormat*)NumberFormat::createInstance(Locale(locale), *status); break; @@ -42,7 +42,7 @@ unum_open( UNumberFormatStyle style, if(locale == 0) retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(*status); else - retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(Locale().init(locale), + retVal = (UNumberFormat*)NumberFormat::createCurrencyInstance(Locale(locale), *status); break; @@ -50,7 +50,7 @@ unum_open( UNumberFormatStyle style, if(locale == 0) retVal = (UNumberFormat*)NumberFormat::createPercentInstance(*status); else - retVal = (UNumberFormat*)NumberFormat::createPercentInstance(Locale().init(locale), + retVal = (UNumberFormat*)NumberFormat::createPercentInstance(Locale(locale), *status); break; @@ -85,7 +85,7 @@ unum_openPattern( const UChar* pattern, if(locale == 0) syms = new DecimalFormatSymbols(*status); else - syms = new DecimalFormatSymbols(Locale().init(locale), + syms = new DecimalFormatSymbols(Locale(locale), *status); if(syms == 0) {