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

U_INTERNAL int32_t U_EXPORT2 utext_compare ( UText s1,
int32_t  length1,
UText s2,
int32_t  length2 
)

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.

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 length argument of -1 signifies that as much of the string should be used as is necessary to compare with the other string. If both length arguments are -1, the entire remaining portionss of both strings are used.

Parameters:
s1 First source string.
length1 Length of first source string in UTF-32 code points.
s2 Second source string.
length2 Length of second source string in UTF-32 code points.
Returns:
<0 or 0 or >0 as usual for string comparisons

For internal use only.

ICU 4.4 technology preview

Definition at line 455 of file utext.cpp.

References INT32_MIN, U_SENTINEL, and UTEXT_NEXT32.

                                          {
    UChar32 c1 = 0, c2 = 0;
    
    if(length1<0 && length2<0) {
        /* strcmp style, go until end of string */
        for(;;) {
            c1 = UTEXT_NEXT32(s1);
            c2 = UTEXT_NEXT32(s2);
            if(c1 != c2) {
                break;
            } else if(c1 == U_SENTINEL) {
                return 0;
            }
        }
    } else {
        if(length1 < 0) {
            length1 = INT32_MIN;
        } else if (length2 < 0) {
            length2 = INT32_MIN;
        }
        
        /* memcmp/UnicodeString style, both length-specified */        
        while((length1 > 0 || length1 == INT32_MIN) && (length2 > 0 || length2 == INT32_MIN)) {
            c1 = UTEXT_NEXT32(s1);
            c2 = UTEXT_NEXT32(s2);
                       
            if(c1 != c2) {
                break;
            } else if(c1 == U_SENTINEL) {
                return 0;
            }
            
            if (length1 != INT32_MIN) {
                length1 -= 1;
            }
            if (length2 != INT32_MIN) {
                length2 -= 1;
            }
        }
        
        if(length1 <= 0 && length1 != INT32_MIN) {
            if(length2 <= 0) {
                return 0;
            } else {
                return -1;
            }
        } else if(length2 <= 0 && length2 != INT32_MIN) {
            if (length1 <= 0) {
                return 0;
            } else {
                return 1;
            }
        }
    }
    
    return (int32_t)c1-(int32_t)c2;
}


Generated by  Doxygen 1.6.0   Back to index