@@ -59,7 +59,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
5959{
6060 char  fnbuff[256 ];
6161 char  ext[4 ]={' \0 '  };
62-  CharString actualLocale ;
62+  CharString actual ;
6363 int32_t  size;
6464 const  char16_t * brkfname = nullptr ;
6565 UResourceBundle brkRulesStack;
@@ -94,7 +94,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
9494
9595 //  Use the string if we found it
9696 if  (U_SUCCESS (status) && brkfname) {
97-  actualLocale .append (ures_getLocaleInternal (brkName, &status), -1 , status);
97+  actual .append (ures_getLocaleInternal (brkName, &status), -1 , status);
9898
9999 char16_t * extStart=u_strchr (brkfname, 0x002e );
100100 int  len = 0 ;
@@ -123,10 +123,9 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
123123 if  (U_SUCCESS (status) && result != nullptr ) {
124124 U_LOCALE_BASED (locBased, *(BreakIterator*)result);
125125
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);
130129 }
131130
132131 ures_close (b);
@@ -206,26 +205,32 @@ BreakIterator::getAvailableLocales(int32_t& count)
206205
207206BreakIterator::BreakIterator ()
208207{
209-  *validLocale = *actualLocale = *requestLocale = 0 ;
210208}
211209
212210BreakIterator::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));
216216}
217217
218218BreakIterator &BreakIterator::operator  =(const  BreakIterator &other) {
219219 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));
223225 }
224226 return  *this ;
225227}
226228
227229BreakIterator::~BreakIterator ()
228230{
231+  delete  validLocale;
232+  delete  actualLocale;
233+  delete  requestLocale;
229234}
230235
231236//  ------------------------------------------
@@ -394,7 +399,7 @@ BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& statu
394399 //  revisit this in ICU 3.0 and clean it up/fix it/remove it.
395400 if  (U_SUCCESS (status) && (result != nullptr ) && *actualLoc.getName () != 0 ) {
396401 U_LOCALE_BASED (locBased, *result);
397-  locBased.setLocaleIDs (actualLoc.getName (), actualLoc.getName ());
402+  locBased.setLocaleIDs (actualLoc.getName (), actualLoc.getName (), status );
398403 }
399404 return  result;
400405 }
@@ -488,6 +493,7 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
488493 }
489494
490495 if  (U_FAILURE (status)) {
496+  delete  result;
491497 return  nullptr ;
492498 }
493499
@@ -496,20 +502,25 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
496502
497503Locale
498504BreakIterator::getLocale (ULocDataLocaleType type, UErrorCode& status) const  {
505+  if  (U_FAILURE (status)) {
506+  return  Locale::getRoot ();
507+  }
499508 if  (type == ULOC_REQUESTED_LOCALE) {
500-  return  {requestLocale};
509+  return  requestLocale == nullptr  ?
510+  Locale::getRoot () : Locale (requestLocale->data ());
501511 }
502-  U_LOCALE_BASED (locBased, *this );
503-  return  locBased.getLocale (type, status);
512+  return  LocaleBased::getLocale (validLocale, actualLocale, type, status);
504513}
505514
506515const  char  *
507516BreakIterator::getLocaleID (ULocDataLocaleType type, UErrorCode& status) const  {
517+  if  (U_FAILURE (status)) {
518+  return  nullptr ;
519+  }
508520 if  (type == ULOC_REQUESTED_LOCALE) {
509-  return  requestLocale;
521+  return  requestLocale ==  nullptr  ?  " "  : requestLocale-> data () ;
510522 }
511-  U_LOCALE_BASED (locBased, *this );
512-  return  locBased.getLocaleID (type, status);
523+  return  LocaleBased::getLocaleID (validLocale, actualLocale, type, status);
513524}
514525
515526
@@ -536,8 +547,10 @@ int32_t BreakIterator::getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UE
536547}
537548
538549BreakIterator::BreakIterator  (const  Locale& valid, const  Locale& actual) {
550+  UErrorCode status = U_ZERO_ERROR;
539551 U_LOCALE_BASED (locBased, (*this ));
540-  locBased.setLocaleIDs (valid, actual);
552+  locBased.setLocaleIDs (valid.getName (), actual.getName (), status);
553+  U_ASSERT (U_SUCCESS (status));
541554}
542555
543556U_NAMESPACE_END
0 commit comments