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

U_STABLE UChar32 U_EXPORT2 utext_previous32From ( UText ut,
int64_t  nativeIndex 
)

Set the iteration index, and return the code point preceding the one specified by the initial index. Leave the iteration position at the start of the returned code point.

This function is the most efficient and convenient way to begin a backwards iteration.

Parameters:
ut the text to be accessed.
nativeIndex Iteration index in the native units of the text provider.
Returns:
Code point preceding the one at the initial index, or U_SENTINEL (-1) if it is out of bounds.
ICU 3.4

Definition at line 371 of file utext.cpp.

References UTextFuncs::access, UText::chunkContents, UText::chunkNativeLimit, UText::chunkNativeStart, UText::chunkOffset, FALSE, UTextFuncs::mapNativeIndexToUTF16, UText::nativeIndexingLimit, UText::pFuncs, U16_IS_SURROGATE, and U_SENTINEL.

                                               {
    //
    //  Return the character preceding the specified index.
    //  Leave the iteration position at the start of the character that was returned.
    //
    UChar32     cPrev;    // The character preceding cCurr, which is what we will return.

    // Address the chunk containg the position preceding the incoming index
    // A tricky edge case:
    //   We try to test the requested native index against the chunkNativeStart to determine
    //    whether the character preceding the one at the index is in the current chunk.
    //    BUT, this test can fail with UTF-8 (or any other multibyte encoding), when the
    //    requested index is on something other than the first position of the first char.
    //
    if(index<=ut->chunkNativeStart || index>ut->chunkNativeLimit) {
        // Requested native index is outside of the current chunk.
        if(!ut->pFuncs->access(ut, index, FALSE)) {
            // no chunk available here
            return U_SENTINEL;
        }
    } else if(index - ut->chunkNativeStart <= (int64_t)ut->nativeIndexingLimit) {
        // Direct UTF-16 indexing.
        ut->chunkOffset = (int32_t)(index - ut->chunkNativeStart);
    } else {
        ut->chunkOffset=ut->pFuncs->mapNativeIndexToUTF16(ut, index);
        if (ut->chunkOffset==0 && !ut->pFuncs->access(ut, index, FALSE)) {
            // no chunk available here
            return U_SENTINEL;
        }
    }

    //
    // Simple case with no surrogates.
    //
    ut->chunkOffset--;
    cPrev = ut->chunkContents[ut->chunkOffset];

    if (U16_IS_SURROGATE(cPrev)) {
        // Possible supplementary.  Many edge cases.
        // Let other functions do the heavy lifting.
        utext_setNativeIndex(ut, index);
        cPrev = utext_previous32(ut);
    }
    return cPrev;
}


Generated by  Doxygen 1.6.0   Back to index