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

U_STABLE UChar* U_EXPORT2 u_memchr32 ( const UChar *  s,
UChar32  c,
int32_t  count 
)

Find the first occurrence of a code point in a string. A surrogate code point is found only if its match in the text is not part of a surrogate pair. A NUL character is found at the string terminator.

Parameters:
s The string to search (contains count UChars).
c The code point to find.
count The length of the string.
Returns:
A pointer to the first occurrence of c in s or NULL if c is not in s. ICU 2.0
See also:
u_strchr32

u_memchr

u_strFindFirst

Definition at line 256 of file ustring.c.

References NULL, U16_LEAD, U16_TRAIL, and UCHAR_MAX_VALUE.

                                                     {
    if((uint32_t)c<=U_BMP_MAX) {
        /* find BMP code point */
        return u_memchr(s, (UChar)c, count);
    } else if(count<2) {
        /* too short for a surrogate pair */
        return NULL;
    } else if((uint32_t)c<=UCHAR_MAX_VALUE) {
        /* find supplementary code point as surrogate pair */
        const UChar *limit=s+count-1; /* -1 so that we do not need a separate check for the trail unit */
        UChar lead=U16_LEAD(c), trail=U16_TRAIL(c);

        do {
            if(*s==lead && *(s+1)==trail) {
                return (UChar *)s;
            }
        } while(++s!=limit);
        return NULL;
    } else {
        /* not a Unicode code point, not findable */
        return NULL;
    }
}


Generated by  Doxygen 1.6.0   Back to index