- while(start < limit) {
- // set the iterator limits for the remaining input range
- // this is a moving target because of the replacements in the text object
- iter.start = iter.index = start;
- iter.limit = limit;
-
- // incrementally normalize a small chunk of the input
- buffer = output.getBuffer(-1);
- errorCode = U_ZERO_ERROR;
- length = unorm_next(&iter, buffer, output.getCapacity(),
- fMode, 0,
- TRUE, &neededToNormalize,
- &errorCode);
- output.releaseBuffer(length);
-
- if(errorCode == U_BUFFER_OVERFLOW_ERROR) {
- // use a larger output string buffer and do it again from the start
- iter.index = start;
- buffer = output.getBuffer(length);
- errorCode = U_ZERO_ERROR;
- length = unorm_next(&iter, buffer, output.getCapacity(),
- fMode, 0,
- TRUE, &neededToNormalize,
- &errorCode);
- output.releaseBuffer(length);
- }
-
- if(U_FAILURE(errorCode)) {
- break;
- }
-
- limit = iter.index;
- if(isIncremental && limit == iter.limit) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ UnicodeString segment;
+ UnicodeString normalized;
+ UChar32 c = text.char32At(start);
+ do {
+ int32_t prev = start;
+ // Skip at least one character so we make progress.
+ // c holds the character at start.
+ segment.remove();
+ do {
+ segment.append(c);
+ start += U16_LENGTH(c);
+ } while(start < limit && !fNorm2.hasBoundaryBefore(c = text.char32At(start)));
+ if(start == limit && isIncremental && !fNorm2.hasBoundaryAfter(c)) {