~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/common/normlzr.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2005-05-21 22:44:31 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: package-import@ubuntu.com-20050521224431-r7rktfhnu1n4tf1g
Tags: 2.1-2.1
Rename icu-doc to icu21-doc. icu-doc is built by the icu28 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
                      UErrorCode &status) {
166
166
    if(source.isBogus() || U_FAILURE(status)) {
167
167
        result.setToBogus();
 
168
        if(U_SUCCESS(status)) {
 
169
            status=U_ILLEGAL_ARGUMENT_ERROR;
 
170
        }
168
171
    } else {
169
172
        UChar *buffer=result.getBuffer(source.length());
170
173
        int32_t length=unorm_internalNormalize(buffer, result.getCapacity(),
207
210
                    UErrorCode &status) {
208
211
    if(source.isBogus() || U_FAILURE(status)) {
209
212
        result.setToBogus();
 
213
        if(U_SUCCESS(status)) {
 
214
            status=U_ILLEGAL_ARGUMENT_ERROR;
 
215
        }
210
216
    } else {
211
217
        UChar *buffer=result.getBuffer(source.length());
212
218
        int32_t length=unorm_compose(buffer, result.getCapacity(),
237
243
                      UErrorCode &status) {
238
244
    if(source.isBogus() || U_FAILURE(status)) {
239
245
        result.setToBogus();
 
246
        if(U_SUCCESS(status)) {
 
247
            status=U_ILLEGAL_ARGUMENT_ERROR;
 
248
        }
240
249
    } else {
241
250
        UChar *buffer=result.getBuffer(source.length());
242
251
        int32_t length=unorm_decompose(buffer, result.getCapacity(),
260
269
    }
261
270
}
262
271
 
 
272
UnicodeString &
 
273
Normalizer::concatenate(UnicodeString &left, UnicodeString &right,
 
274
                        UnicodeString &result,
 
275
                        UNormalizationMode mode, int32_t options,
 
276
                        UErrorCode &errorCode) {
 
277
    if(left.isBogus() || right.isBogus() || U_FAILURE(errorCode)) {
 
278
        result.setToBogus();
 
279
        if(U_SUCCESS(errorCode)) {
 
280
            errorCode=U_ILLEGAL_ARGUMENT_ERROR;
 
281
        }
 
282
    } else {
 
283
        UChar *buffer=result.getBuffer(left.length()+right.length());
 
284
        int32_t length=unorm_concatenate(left.getBuffer(), left.length(),
 
285
                                         right.getBuffer(), right.length(),
 
286
                                         buffer, result.getCapacity(),
 
287
                                         mode, options,
 
288
                                         &errorCode);
 
289
        result.releaseBuffer(length);
 
290
        if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
 
291
            errorCode=U_ZERO_ERROR;
 
292
            buffer=result.getBuffer(length);
 
293
            int32_t length=unorm_concatenate(left.getBuffer(), left.length(),
 
294
                                             right.getBuffer(), right.length(),
 
295
                                             buffer, result.getCapacity(),
 
296
                                             mode, options,
 
297
                                             &errorCode);
 
298
            result.releaseBuffer(length);
 
299
        }
 
300
 
 
301
        if(U_FAILURE(errorCode)) {
 
302
            result.setToBogus();
 
303
        }
 
304
    }
 
305
    return result;
 
306
}
 
307
 
263
308
//-------------------------------------------------------------------------
264
309
// Iteration API
265
310
//-------------------------------------------------------------------------
311
356
}
312
357
 
313
358
void
314
 
Normalizer::setIndexOnly(UTextOffset index) {
315
 
    currentIndex=nextIndex=text->move(text, index, UITER_START); // validates index
 
359
Normalizer::setIndexOnly(int32_t index) {
 
360
    currentIndex=nextIndex=text->move(text, index, UITER_ZERO); // validates index
316
361
    clearBuffer();
317
362
}
318
363
 
335
380
 * @throws IllegalArgumentException if the given index is less than
336
381
 *          {@link #getBeginIndex} or greater than {@link #getEndIndex}.
337
382
 */
338
 
UChar32 Normalizer::setIndex(UTextOffset index) {
 
383
UChar32 Normalizer::setIndex(int32_t index) {
339
384
    setIndexOnly(index);
340
385
    return current();
341
386
}
374
419
 * <tt>setIndex</tt> and {@link #getIndex}.
375
420
 *
376
421
 */
377
 
UTextOffset Normalizer::getIndex() const {
 
422
int32_t Normalizer::getIndex() const {
378
423
    if(bufferPos<buffer.length()) {
379
424
        return currentIndex;
380
425
    } else {
387
432
 * of the <tt>CharacterIterator</tt> or the start (i.e. 0) of the <tt>String</tt>
388
433
 * over which this <tt>Normalizer</tt> is iterating
389
434
 */
390
 
UTextOffset Normalizer::startIndex() const {
391
 
    return text->move(text, 0, UITER_START);
 
435
int32_t Normalizer::startIndex() const {
 
436
    return text->getIndex(text, UITER_START);
392
437
}
393
438
 
394
439
/**
396
441
 * of the <tt>CharacterIterator</tt> or the length of the <tt>String</tt>
397
442
 * over which this <tt>Normalizer</tt> is iterating
398
443
 */
399
 
UTextOffset Normalizer::endIndex() const {
400
 
    return text->move(text, 0, UITER_LIMIT);
 
444
int32_t Normalizer::endIndex() const {
 
445
    return text->getIndex(text, UITER_LIMIT);
401
446
}
402
447
 
403
448
//-------------------------------------------------------------------------
520
565
 
521
566
    clearBuffer();
522
567
    currentIndex=nextIndex;
523
 
    text->move(text, nextIndex, UITER_START);
 
568
    text->move(text, nextIndex, UITER_ZERO);
524
569
    if(!text->hasNext(text)) {
525
570
        return FALSE;
526
571
    }
534
579
    buffer.releaseBuffer(length);
535
580
    if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
536
581
        errorCode=U_ZERO_ERROR;
537
 
        text->move(text, nextIndex, UITER_START);
 
582
        text->move(text, nextIndex, UITER_ZERO);
538
583
        p=buffer.getBuffer(length);
539
584
        length=unorm_next(text, p, buffer.getCapacity(),
540
585
                          fUMode, fOptions!=0,
543
588
        buffer.releaseBuffer(length);
544
589
    }
545
590
 
546
 
    nextIndex=text->move(text, 0, UITER_CURRENT);
 
591
    nextIndex=text->getIndex(text, UITER_CURRENT);
547
592
    return U_SUCCESS(errorCode) && !buffer.isEmpty();
548
593
}
549
594
 
555
600
 
556
601
    clearBuffer();
557
602
    nextIndex=currentIndex;
558
 
    text->move(text, currentIndex, UITER_START);
 
603
    text->move(text, currentIndex, UITER_ZERO);
559
604
    if(!text->hasPrevious(text)) {
560
605
        return FALSE;
561
606
    }
569
614
    buffer.releaseBuffer(length);
570
615
    if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
571
616
        errorCode=U_ZERO_ERROR;
572
 
        text->move(text, currentIndex, UITER_START);
 
617
        text->move(text, currentIndex, UITER_ZERO);
573
618
        p=buffer.getBuffer(length);
574
619
        length=unorm_previous(text, p, buffer.getCapacity(),
575
620
                              fUMode, fOptions,
579
624
    }
580
625
 
581
626
    bufferPos=buffer.length();
582
 
    currentIndex=text->move(text, 0, UITER_CURRENT);
 
627
    currentIndex=text->getIndex(text, UITER_CURRENT);
583
628
    return U_SUCCESS(errorCode) && !buffer.isEmpty();
584
629
}
585
630