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

U_STABLE UChar32 U_EXPORT2 utext_previous32 ( UText ut  ) 

Move the iterator position to the character (code point) whose index precedes the current position, and return that character. This is a pre-decrement operation.

If the initial position is at the start of the text (index of 0) return U_SENTINEL (-1), and leave the position unchanged.

An inline macro version of this function, UTEXT_PREVIOUS32(), is available for performance critical use.

ut the text to be accessed.
the previous UChar32 code point, or U_SENTINEL (-1) if the iteration has reached the start of the text.
See also:

Definition at line 302 of file utext.cpp.

References UTextFuncs::access, UText::chunkContents, UText::chunkNativeStart, UText::chunkOffset, FALSE, UText::pFuncs, U16_GET_SUPPLEMENTARY, U16_IS_LEAD, U16_IS_TRAIL, and U_SENTINEL.

    UChar32       c;

    if (ut->chunkOffset <= 0) {
        if (ut->pFuncs->access(ut, ut->chunkNativeStart, FALSE) == FALSE) {
            return U_SENTINEL;
    c = ut->chunkContents[ut->chunkOffset];
    if (U16_IS_TRAIL(c) == FALSE) {
        // Normal case, not supplementary.
        //   (A lead surrogate seen here is just returned as is, as a surrogate value.
        //    It cannot be part of a pair.)
        return c;

    if (ut->chunkOffset <= 0) {
        if (ut->pFuncs->access(ut, ut->chunkNativeStart, FALSE) == FALSE) {
            // c is an unpaired trail surrogate at the start of the text.
            // return it as it is.
            return c;

    UChar32 lead = ut->chunkContents[ut->chunkOffset-1];
    if (U16_IS_LEAD(lead) == FALSE) {
        // c was an unpaired trail surrogate, not at the end of the text.
        // return it as it is (unpaired).  Iteration position is at c
        return c;

    UChar32 supplementary = U16_GET_SUPPLEMENTARY(lead, c);
    ut->chunkOffset--;   // move iteration position over the lead surrogate.
    return supplementary;

Generated by  Doxygen 1.6.0   Back to index