@@ -59,58 +59,47 @@ LanguageBreakFactory::~LanguageBreakFactory() {
5959 ******************************************************************
6060 */
6161
62- UnhandledEngine::UnhandledEngine(UErrorCode &/*status*/) {
63- for (int32_t i = 0; i < UPRV_LENGTHOF(fHandled); ++i) {
64- fHandled[i] = 0;
65- }
62+ UnhandledEngine::UnhandledEngine(UErrorCode &status) : fHandled(nullptr) {
63+ (void)status;
6664}
6765
6866UnhandledEngine::~UnhandledEngine() {
69- for (int32_t i = 0; i < UPRV_LENGTHOF(fHandled); ++i) {
70- if (fHandled[i] != 0) {
71- delete fHandled[i];
72- }
73- }
67+ delete fHandled;
68+ fHandled = nullptr;
7469}
7570
7671UBool
77- UnhandledEngine::handles(UChar32 c, int32_t breakType) const {
78- return (breakType >= 0 && breakType < UPRV_LENGTHOF(fHandled)
79- && fHandled[breakType] != 0 && fHandled[breakType]->contains(c));
72+ UnhandledEngine::handles(UChar32 c) const {
73+ return fHandled && fHandled->contains(c);
8074}
8175
8276int32_t
8377UnhandledEngine::findBreaks( UText *text,
8478 int32_t /* startPos */,
8579 int32_t endPos,
86- int32_t breakType,
8780 UVector32 &/*foundBreaks*/ ) const {
88- if (breakType >= 0 && breakType < UPRV_LENGTHOF(fHandled)) {
89- UChar32 c = utext_current32(text);
90- while((int32_t)utext_getNativeIndex(text) < endPos && fHandled[breakType]->contains(c)) {
91- utext_next32(text); // TODO: recast loop to work with post-increment operations.
92- c = utext_current32(text);
93- }
81+ UChar32 c = utext_current32(text);
82+ while((int32_t)utext_getNativeIndex(text) < endPos && fHandled->contains(c)) {
83+ utext_next32(text); // TODO: recast loop to work with post-increment operations.
84+ c = utext_current32(text);
9485 }
9586 return 0;
9687}
9788
9889void
99- UnhandledEngine::handleCharacter(UChar32 c, int32_t breakType) {
100- if (breakType >= 0 && breakType < UPRV_LENGTHOF(fHandled)) {
101- if (fHandled[breakType] == 0) {
102- fHandled[breakType] = new UnicodeSet();
103- if (fHandled[breakType] == 0) {
104- return;
105- }
106- }
107- if (!fHandled[breakType]->contains(c)) {
108- UErrorCode status = U_ZERO_ERROR;
109- // Apply the entire script of the character.
110- int32_t script = u_getIntPropertyValue(c, UCHAR_SCRIPT);
111- fHandled[breakType]->applyIntPropertyValue(UCHAR_SCRIPT, script, status);
90+ UnhandledEngine::handleCharacter(UChar32 c) {
91+ if (fHandled == nullptr) {
92+ fHandled = new UnicodeSet();
93+ if (fHandled == nullptr) {
94+ return;
11295 }
11396 }
97+ if (!fHandled->contains(c)) {
98+ UErrorCode status = U_ZERO_ERROR;
99+ // Apply the entire script of the character.
100+ int32_t script = u_getIntPropertyValue(c, UCHAR_SCRIPT);
101+ fHandled->applyIntPropertyValue(UCHAR_SCRIPT, script, status);
102+ }
114103}
115104
116105/*
@@ -138,7 +127,7 @@ U_NAMESPACE_BEGIN
138127static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
139128
140129const LanguageBreakEngine *
141- ICULanguageBreakFactory::getEngineFor(UChar32 c, int32_t breakType ) {
130+ ICULanguageBreakFactory::getEngineFor(UChar32 c) {
142131 const LanguageBreakEngine *lbe = NULL;
143132 UErrorCode status = U_ZERO_ERROR;
144133
@@ -156,26 +145,26 @@ ICULanguageBreakFactory::getEngineFor(UChar32 c, int32_t breakType) {
156145 int32_t i = fEngines->size();
157146 while (--i >= 0) {
158147 lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i));
159- if (lbe != NULL && lbe->handles(c, breakType )) {
148+ if (lbe != NULL && lbe->handles(c)) {
160149 return lbe;
161150 }
162151 }
163152 }
164153
165154 // We didn't find an engine. Create one.
166- lbe = loadEngineFor(c, breakType );
155+ lbe = loadEngineFor(c);
167156 if (lbe != NULL) {
168157 fEngines->push((void *)lbe, status);
169158 }
170159 return lbe;
171160}
172161
173162const LanguageBreakEngine *
174- ICULanguageBreakFactory::loadEngineFor(UChar32 c, int32_t breakType ) {
163+ ICULanguageBreakFactory::loadEngineFor(UChar32 c) {
175164 UErrorCode status = U_ZERO_ERROR;
176165 UScriptCode code = uscript_getScript(c, &status);
177166 if (U_SUCCESS(status)) {
178- DictionaryMatcher *m = loadDictionaryMatcherFor(code, breakType );
167+ DictionaryMatcher *m = loadDictionaryMatcherFor(code);
179168 if (m != NULL) {
180169 const LanguageBreakEngine *engine = NULL;
181170 switch(code) {
@@ -236,7 +225,7 @@ ICULanguageBreakFactory::loadEngineFor(UChar32 c, int32_t breakType) {
236225}
237226
238227DictionaryMatcher *
239- ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script, int32_t /* brkType */ ) {
228+ ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script) {
240229 UErrorCode status = U_ZERO_ERROR;
241230 // open root from brkitr tree.
242231 UResourceBundle *b = ures_open(U_ICUDATA_BRKITR, "", &status);
0 commit comments