[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

utf8strrchr()

Search backwards for a UTF-8 character in a string

Synopsis:

#include <utf8.h>

char *utf8strrchr( char const *string_base, 
                   char const *start_char, 
                   char const *mbchar,
                   int *count );

Arguments:

string_base
A pointer to the beginning of the string to search.
start_char
A pointer to the character in the string from which to search.
mbchar
The character to look for.
count
A pointer to the location where utf8strrchr() stores the number of UTF-8 characters the matching character is from the start of the search.

Library:

ph

Description:

This function searches backwards from start_char to string_base (inclusive) for a UTF-8 character that matches mbchar. If such a match is found, count (if provided) is set to the number of UTF-8 characters the matching character is from the start of the search. For example, if mbchar matches the start_char character in string, count is set to 0. If mbchar matches the previous character in string, count is set to 1.

A pointer to the beginning of the matching character within string_base is returned. If no match is found, the function returns NULL and doesn't change count.

Note that start_char doesn't need to be on a character boundary.

Returns:

A pointer to the matched character, or NULL if none was found.

Examples:

Search from the end of a string for a match to the provided UTF-8 character:

#include <Pt.h>

int main()
    {
    char string[] = "Hello there: äîòéü found"; 
    char mbchar[] = "é";
    int count;
    char *p;

    if( (p = utf8strrchr( string, string + strlen( string ) - 1, 
                       mbchar, &count ) ) )
    {
        printf( 
            "Character found: \n%d characters from the end.\n",
            count );
        printf( "Byte offset %d.\n", p - string );
    }
    else
        printf( "Not found.\n" );
    }

Classification:

Photon

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

utf8strchr(), utf8strichr(), utf8strnchr(), utf8strnichr(), utf8strirchr()

Unicode Multilingual Support in the Photon Programmer's Guide


[Previous] [Contents] [Index] [Next]