@@ -59,7 +59,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
59
59
{
60
60
char fnbuff[256 ];
61
61
char ext[4 ]={' \0 ' };
62
- CharString actualLocale ;
62
+ CharString actual ;
63
63
int32_t size;
64
64
const char16_t * brkfname = nullptr ;
65
65
UResourceBundle brkRulesStack;
@@ -94,7 +94,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
94
94
95
95
// Use the string if we found it
96
96
if (U_SUCCESS (status) && brkfname) {
97
- actualLocale .append (ures_getLocaleInternal (brkName, &status), -1 , status);
97
+ actual .append (ures_getLocaleInternal (brkName, &status), -1 , status);
98
98
99
99
char16_t * extStart=u_strchr (brkfname, 0x002e );
100
100
int len = 0 ;
@@ -123,10 +123,9 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
123
123
if (U_SUCCESS (status) && result != nullptr ) {
124
124
U_LOCALE_BASED (locBased, *(BreakIterator*)result);
125
125
126
- locBased.setLocaleIDs (ures_getLocaleByType (b, ULOC_VALID_LOCALE, &status),
127
- actualLocale.data ());
128
- uprv_strncpy (result->requestLocale , loc.getName (), ULOC_FULLNAME_CAPACITY);
129
- result->requestLocale [ULOC_FULLNAME_CAPACITY-1 ] = 0 ; // always terminate
126
+ locBased.setLocaleIDs (ures_getLocaleByType (b, ULOC_VALID_LOCALE, &status),
127
+ actual.data (), status);
128
+ LocaleBased::setLocaleID (loc.getName (), result->requestLocale , status);
130
129
}
131
130
132
131
ures_close (b);
@@ -206,26 +205,32 @@ BreakIterator::getAvailableLocales(int32_t& count)
206
205
207
206
BreakIterator::BreakIterator ()
208
207
{
209
- *validLocale = *actualLocale = *requestLocale = 0 ;
210
208
}
211
209
212
210
BreakIterator::BreakIterator (const BreakIterator &other) : UObject(other) {
213
- uprv_strncpy (actualLocale, other.actualLocale , sizeof (actualLocale));
214
- uprv_strncpy (validLocale, other.validLocale , sizeof (validLocale));
215
- uprv_strncpy (requestLocale, other.requestLocale , sizeof (requestLocale));
211
+ UErrorCode status = U_ZERO_ERROR;
212
+ U_LOCALE_BASED (locBased, *this );
213
+ locBased.setLocaleIDs (other.validLocale , other.actualLocale , status);
214
+ LocaleBased::setLocaleID (other.requestLocale , requestLocale, status);
215
+ U_ASSERT (U_SUCCESS (status));
216
216
}
217
217
218
218
BreakIterator &BreakIterator::operator =(const BreakIterator &other) {
219
219
if (this != &other) {
220
- uprv_strncpy (actualLocale, other.actualLocale , sizeof (actualLocale));
221
- uprv_strncpy (validLocale, other.validLocale , sizeof (validLocale));
222
- uprv_strncpy (requestLocale, other.requestLocale , sizeof (requestLocale));
220
+ UErrorCode status = U_ZERO_ERROR;
221
+ U_LOCALE_BASED (locBased, *this );
222
+ locBased.setLocaleIDs (other.validLocale , other.actualLocale , status);
223
+ LocaleBased::setLocaleID (other.requestLocale , requestLocale, status);
224
+ U_ASSERT (U_SUCCESS (status));
223
225
}
224
226
return *this ;
225
227
}
226
228
227
229
BreakIterator::~BreakIterator ()
228
230
{
231
+ delete validLocale;
232
+ delete actualLocale;
233
+ delete requestLocale;
229
234
}
230
235
231
236
// ------------------------------------------
@@ -394,7 +399,7 @@ BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& statu
394
399
// revisit this in ICU 3.0 and clean it up/fix it/remove it.
395
400
if (U_SUCCESS (status) && (result != nullptr ) && *actualLoc.getName () != 0 ) {
396
401
U_LOCALE_BASED (locBased, *result);
397
- locBased.setLocaleIDs (actualLoc.getName (), actualLoc.getName ());
402
+ locBased.setLocaleIDs (actualLoc.getName (), actualLoc.getName (), status );
398
403
}
399
404
return result;
400
405
}
@@ -488,6 +493,7 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
488
493
}
489
494
490
495
if (U_FAILURE (status)) {
496
+ delete result;
491
497
return nullptr ;
492
498
}
493
499
@@ -496,20 +502,25 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
496
502
497
503
Locale
498
504
BreakIterator::getLocale (ULocDataLocaleType type, UErrorCode& status) const {
505
+ if (U_FAILURE (status)) {
506
+ return Locale::getRoot ();
507
+ }
499
508
if (type == ULOC_REQUESTED_LOCALE) {
500
- return {requestLocale};
509
+ return requestLocale == nullptr ?
510
+ Locale::getRoot () : Locale (requestLocale->data ());
501
511
}
502
- U_LOCALE_BASED (locBased, *this );
503
- return locBased.getLocale (type, status);
512
+ return LocaleBased::getLocale (validLocale, actualLocale, type, status);
504
513
}
505
514
506
515
const char *
507
516
BreakIterator::getLocaleID (ULocDataLocaleType type, UErrorCode& status) const {
517
+ if (U_FAILURE (status)) {
518
+ return nullptr ;
519
+ }
508
520
if (type == ULOC_REQUESTED_LOCALE) {
509
- return requestLocale;
521
+ return requestLocale == nullptr ? " " : requestLocale-> data () ;
510
522
}
511
- U_LOCALE_BASED (locBased, *this );
512
- return locBased.getLocaleID (type, status);
523
+ return LocaleBased::getLocaleID (validLocale, actualLocale, type, status);
513
524
}
514
525
515
526
@@ -536,8 +547,10 @@ int32_t BreakIterator::getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UE
536
547
}
537
548
538
549
BreakIterator::BreakIterator (const Locale& valid, const Locale& actual) {
550
+ UErrorCode status = U_ZERO_ERROR;
539
551
U_LOCALE_BASED (locBased, (*this ));
540
- locBased.setLocaleIDs (valid, actual);
552
+ locBased.setLocaleIDs (valid.getName (), actual.getName (), status);
553
+ U_ASSERT (U_SUCCESS (status));
541
554
}
542
555
543
556
U_NAMESPACE_END
0 commit comments