35
35
36
36
#include " unicode/bytestream.h"
37
37
#include " unicode/locid.h"
38
+ #include " unicode/localebuilder.h"
38
39
#include " unicode/strenum.h"
39
40
#include " unicode/stringpiece.h"
40
41
#include " unicode/uloc.h"
@@ -1028,7 +1029,7 @@ class AliasReplacer {
1028
1029
// place the the replaced locale ID in out and return true.
1029
1030
// Otherwise return false for no replacement or error.
1030
1031
bool replace (
1031
- const Locale& locale, CharString& out, UErrorCode status);
1032
+ const Locale& locale, CharString& out, UErrorCode& status);
1032
1033
1033
1034
private:
1034
1035
const char * language;
@@ -1336,10 +1337,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
1336
1337
// Cannot use nullptr for language because that will construct
1337
1338
// the default locale, in that case, use "und" to get the correct
1338
1339
// 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);
1340
1344
l.addLikelySubtags (status);
1341
1345
const char * likelyRegion = l.getCountry ();
1342
- CharString* item = nullptr ;
1346
+ LocalPointer< CharString> item;
1343
1347
if (likelyRegion != nullptr && uprv_strlen (likelyRegion) > 0 ) {
1344
1348
size_t len = uprv_strlen (likelyRegion);
1345
1349
const char * foundInReplacement = uprv_strstr (replacement,
@@ -1351,20 +1355,22 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
1351
1355
*(foundInReplacement-1 ) == ' ' );
1352
1356
U_ASSERT (foundInReplacement[len] == ' ' ||
1353
1357
foundInReplacement[len] == ' \0 ' );
1354
- item = new CharString (foundInReplacement, (int32_t )len, status);
1358
+ item.adoptInsteadAndCheckErrorCode (
1359
+ new CharString (foundInReplacement, (int32_t )len, status), status);
1355
1360
}
1356
1361
}
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);
1360
1366
}
1361
1367
if (U_FAILURE (status)) { return false ; }
1362
- if (item == nullptr ) {
1368
+ if (item. isNull () ) {
1363
1369
status = U_MEMORY_ALLOCATION_ERROR;
1364
1370
return false ;
1365
1371
}
1366
1372
replacedRegion = item->data ();
1367
- toBeFreed.addElement (item, status);
1373
+ toBeFreed.addElement (item. orphan () , status);
1368
1374
}
1369
1375
U_ASSERT (!same (region, replacedRegion));
1370
1376
region = replacedRegion;
@@ -1453,7 +1459,7 @@ AliasReplacer::outputToString(
1453
1459
int32_t variantsStart = out.length ();
1454
1460
for (int32_t i = 0 ; i < variants.size (); i++) {
1455
1461
out.append (SEP_CHAR, status)
1456
- .append ((const char *)((UVector*) variants.elementAt (i)),
1462
+ .append ((const char *)(variants.elementAt (i)),
1457
1463
status);
1458
1464
}
1459
1465
T_CString_toUpperCase (out.data () + variantsStart);
@@ -1470,7 +1476,7 @@ AliasReplacer::outputToString(
1470
1476
}
1471
1477
1472
1478
bool
1473
- AliasReplacer::replace (const Locale& locale, CharString& out, UErrorCode status)
1479
+ AliasReplacer::replace (const Locale& locale, CharString& out, UErrorCode& status)
1474
1480
{
1475
1481
data = AliasData::singleton (status);
1476
1482
if (U_FAILURE (status)) {
@@ -2453,9 +2459,13 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
2453
2459
if (U_FAILURE (status)) {
2454
2460
return ;
2455
2461
}
2462
+ if (status == U_STRING_NOT_TERMINATED_WARNING) {
2463
+ status = U_ZERO_ERROR;
2464
+ }
2456
2465
int32_t bufferLength = uprv_max ((int32_t )(uprv_strlen (fullName) + 1 ), ULOC_FULLNAME_CAPACITY);
2457
2466
int32_t newLength = uloc_setKeywordValue (keywordName, keywordValue, fullName,
2458
2467
bufferLength, &status) + 1 ;
2468
+ U_ASSERT (status != U_STRING_NOT_TERMINATED_WARNING);
2459
2469
/* Handle the case the current buffer is not enough to hold the new id */
2460
2470
if (status == U_BUFFER_OVERFLOW_ERROR) {
2461
2471
U_ASSERT (newLength > bufferLength);
@@ -2472,6 +2482,7 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
2472
2482
fullName = newFullName;
2473
2483
status = U_ZERO_ERROR;
2474
2484
uloc_setKeywordValue (keywordName, keywordValue, fullName, newLength, &status);
2485
+ U_ASSERT (status != U_STRING_NOT_TERMINATED_WARNING);
2475
2486
} else {
2476
2487
U_ASSERT (newLength <= bufferLength);
2477
2488
}
0 commit comments