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

U_INTERNAL int32_t U_EXPORT2 utext_compareNativeLimit ( UText s1,
int64_t  limit1,
UText s2,
int64_t  limit2 
)

Compare two UTexts (binary order). The comparison begins at each source text's iteration position. The iteration position of each UText will be left following the last character compared. This method differs from utext_compare in that it accepts native limits rather than lengths for each string.

The comparison is done in code point order; unlike u_strCompare, you cannot choose to use code unit order. This is because the characters in a UText are accessed one code point at a time, and may not be from a UTF-16 context.

This functions works with strings of different explicitly specified lengths unlike the ANSI C-like u_strcmp() and u_memcmp() etc. A limit argument of -1 signifies that as much of the string should be used as is necessary to compare with the other string. If both limit arguments are -1, the entire remaining portionss of both strings are used.

Parameters:
s1 First source string.
limit1 Native index of the last character in the first source string to be considered.
s2 Second source string.
limit2 Native index of the last character in the second source string to be considered.
Returns:
<0 or 0 or >0 as usual for string comparisons

For internal use only.

ICU 4.4 technology preview

Definition at line 515 of file utext.cpp.

References U_SENTINEL, UTEXT_GETNATIVEINDEX, and UTEXT_NEXT32.

                                                    {
    UChar32 c1, c2;
    
    if(limit1<0 && limit2<0) {
        /* strcmp style, go until end of string */
        for(;;) {
            c1 = UTEXT_NEXT32(s1);
            c2 = UTEXT_NEXT32(s2);
            if(c1 != c2) {
                return (int32_t)c1-(int32_t)c2;
            } else if(c1 == U_SENTINEL) {
                return 0;
            }
        }
    } else {
        /* memcmp/UnicodeString style, both length-specified */   
        int64_t index1 = (limit1 >= 0 ? UTEXT_GETNATIVEINDEX(s1) : 0);
        int64_t index2 = (limit2 >= 0 ? UTEXT_GETNATIVEINDEX(s2) : 0);
        
        while((limit1 < 0 || index1 < limit1) && (limit2 < 0 || index2 < limit2)) {
            c1 = UTEXT_NEXT32(s1);
            c2 = UTEXT_NEXT32(s2);
            
            if(c1 != c2) {
                return (int32_t)c1-(int32_t)c2;
            } else if(c1 == U_SENTINEL) {
                return 0;
            }
            
            if (limit1 >= 0) {
                index1 = UTEXT_GETNATIVEINDEX(s1);
            }
            if (limit2 >= 0) {
                index2 = UTEXT_GETNATIVEINDEX(s2);
            }
        }
        
        if(limit1 >= 0 && index1 >= limit1) {
            if(index2 >= limit2) {
                return 0;
            } else {
                return -1;
            }
        } else {
            if(index1 >= limit1) {
                return 0;
            } else {
                return 1;
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index