Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE int32_t U_EXPORT2 u_strCompareIter ( UCharIterator iter1,
UCharIterator iter2,
UBool  codePointOrder 
)

Compare two Unicode strings (binary order) as presented by UCharIterator objects. Works otherwise just like u_strCompare().

Both iterators are reset to their start positions. When the function returns, it is undefined where the iterators have stopped.

Parameters:
iter1 First source string iterator.
iter2 Second source string iterator.
codePointOrder Choose between code unit order (FALSE) and code point order (TRUE).
Returns:
<0 or 0 or >0 as usual for string comparisons
See also:
u_strCompare
ICU 2.6

Definition at line 825 of file ustring.c.

References UCharIterator::current, UCharIterator::move, UCharIterator::next, NULL, UCharIterator::previous, UTF_IS_LEAD, and UTF_IS_TRAIL.

                                                                                   {
    UChar32 c1, c2;

    /* argument checking */
    if(iter1==NULL || iter2==NULL) {
        return 0; /* bad arguments */
    }
    if(iter1==iter2) {
        return 0; /* identical iterators */
    }

    /* reset iterators to start? */
    iter1->move(iter1, 0, UITER_START);
    iter2->move(iter2, 0, UITER_START);

    /* compare identical prefixes - they do not need to be fixed up */
    for(;;) {
        c1=iter1->next(iter1);
        c2=iter2->next(iter2);
        if(c1!=c2) {
            break;
        }
        if(c1==-1) {
            return 0;
        }
    }

    /* if both values are in or above the surrogate range, fix them up */
    if(c1>=0xd800 && c2>=0xd800 && codePointOrder) {
        /* subtract 0x2800 from BMP code points to make them smaller than supplementary ones */
        if(
            (c1<=0xdbff && UTF_IS_TRAIL(iter1->current(iter1))) ||
            (UTF_IS_TRAIL(c1) && (iter1->previous(iter1), UTF_IS_LEAD(iter1->previous(iter1))))
        ) {
            /* part of a surrogate pair, leave >=d800 */
        } else {
            /* BMP code point - may be surrogate code point - make <d800 */
            c1-=0x2800;
        }

        if(
            (c2<=0xdbff && UTF_IS_TRAIL(iter2->current(iter2))) ||
            (UTF_IS_TRAIL(c2) && (iter2->previous(iter2), UTF_IS_LEAD(iter2->previous(iter2))))
        ) {
            /* part of a surrogate pair, leave >=d800 */
        } else {
            /* BMP code point - may be surrogate code point - make <d800 */
            c2-=0x2800;
        }
    }

    /* now c1 and c2 are in the requested (code unit or code point) order */
    return (int32_t)c1-(int32_t)c2;
}


Generated by  Doxygen 1.6.0   Back to index