3535
3636#include " unicode/bytestream.h"
3737#include " unicode/locid.h"
38+ #include " unicode/localebuilder.h"
3839#include " unicode/strenum.h"
3940#include " unicode/stringpiece.h"
4041#include " unicode/uloc.h"
@@ -1028,7 +1029,7 @@ class AliasReplacer {
10281029 // place the the replaced locale ID in out and return true.
10291030 // Otherwise return false for no replacement or error.
10301031 bool replace (
1031- const Locale& locale, CharString& out, UErrorCode status);
1032+ const Locale& locale, CharString& out, UErrorCode& status);
10321033
10331034private:
10341035 const char * language;
@@ -1336,10 +1337,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
13361337 // Cannot use nullptr for language because that will construct
13371338 // the default locale, in that case, use "und" to get the correct
13381339 // locale.
1339- Locale l (language == nullptr ? " und" : language, nullptr , script);
1340+ Locale l = LocaleBuilder ()
1341+ .setLanguage (language == nullptr ? " und" : language)
1342+ .setScript (script)
1343+ .build (status);
13401344 l.addLikelySubtags (status);
13411345 const char * likelyRegion = l.getCountry ();
1342- CharString* item = nullptr ;
1346+ LocalPointer< CharString> item;
13431347 if (likelyRegion != nullptr && uprv_strlen (likelyRegion) > 0 ) {
13441348 size_t len = uprv_strlen (likelyRegion);
13451349 const char * foundInReplacement = uprv_strstr (replacement,
@@ -1351,20 +1355,22 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
13511355 *(foundInReplacement-1 ) == ' ' );
13521356 U_ASSERT (foundInReplacement[len] == ' ' ||
13531357 foundInReplacement[len] == ' \0 ' );
1354- item = new CharString (foundInReplacement, (int32_t )len, status);
1358+ item.adoptInsteadAndCheckErrorCode (
1359+ new CharString (foundInReplacement, (int32_t )len, status), status);
13551360 }
13561361 }
1357- if (item == nullptr ) {
1358- item = new CharString (replacement,
1359- (int32_t )(firstSpace - replacement), status);
1362+ if (item.isNull () && U_SUCCESS (status)) {
1363+ item.adoptInsteadAndCheckErrorCode (
1364+ new CharString (replacement,
1365+ (int32_t )(firstSpace - replacement), status), status);
13601366 }
13611367 if (U_FAILURE (status)) { return false ; }
1362- if (item == nullptr ) {
1368+ if (item. isNull () ) {
13631369 status = U_MEMORY_ALLOCATION_ERROR;
13641370 return false ;
13651371 }
13661372 replacedRegion = item->data ();
1367- toBeFreed.addElement (item, status);
1373+ toBeFreed.addElement (item. orphan () , status);
13681374 }
13691375 U_ASSERT (!same (region, replacedRegion));
13701376 region = replacedRegion;
@@ -1453,7 +1459,7 @@ AliasReplacer::outputToString(
14531459 int32_t variantsStart = out.length ();
14541460 for (int32_t i = 0 ; i < variants.size (); i++) {
14551461 out.append (SEP_CHAR, status)
1456- .append ((const char *)((UVector*) variants.elementAt (i)),
1462+ .append ((const char *)(variants.elementAt (i)),
14571463 status);
14581464 }
14591465 T_CString_toUpperCase (out.data () + variantsStart);
@@ -1470,7 +1476,7 @@ AliasReplacer::outputToString(
14701476}
14711477
14721478bool
1473- AliasReplacer::replace (const Locale& locale, CharString& out, UErrorCode status)
1479+ AliasReplacer::replace (const Locale& locale, CharString& out, UErrorCode& status)
14741480{
14751481 data = AliasData::singleton (status);
14761482 if (U_FAILURE (status)) {
@@ -2453,9 +2459,13 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
24532459 if (U_FAILURE (status)) {
24542460 return ;
24552461 }
2462+ if (status == U_STRING_NOT_TERMINATED_WARNING) {
2463+ status = U_ZERO_ERROR;
2464+ }
24562465 int32_t bufferLength = uprv_max ((int32_t )(uprv_strlen (fullName) + 1 ), ULOC_FULLNAME_CAPACITY);
24572466 int32_t newLength = uloc_setKeywordValue (keywordName, keywordValue, fullName,
24582467 bufferLength, &status) + 1 ;
2468+ U_ASSERT (status != U_STRING_NOT_TERMINATED_WARNING);
24592469 /* Handle the case the current buffer is not enough to hold the new id */
24602470 if (status == U_BUFFER_OVERFLOW_ERROR) {
24612471 U_ASSERT (newLength > bufferLength);
@@ -2472,6 +2482,7 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
24722482 fullName = newFullName;
24732483 status = U_ZERO_ERROR;
24742484 uloc_setKeywordValue (keywordName, keywordValue, fullName, newLength, &status);
2485+ U_ASSERT (status != U_STRING_NOT_TERMINATED_WARNING);
24752486 } else {
24762487 U_ASSERT (newLength <= bufferLength);
24772488 }
0 commit comments