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

U_STABLE int64_t U_EXPORT2 utext_getPreviousNativeIndex ( UText ut  ) 

Get the native index of the character preceeding the current position. If the iteration position is already at the start of the text, zero is returned. The value returned is the same as that obtained from the following sequence, but without the side effect of changing the iteration position.

    UText  *ut = whatever;
      ...
    utext_previous(ut)
    utext_getNativeIndex(ut);

This function is most useful during forwards iteration, where it will get the native index of the character most recently returned from utext_next().

Parameters:
ut the text to be accessed
Returns:
the native index of the character preceeding the current index position, or zero if the current position is at the start of the text. ICU 3.6

Definition at line 138 of file utext.cpp.

References UText::chunkContents, UText::chunkNativeStart, UText::chunkOffset, FALSE, UTextFuncs::mapOffsetToNative, UText::pFuncs, U16_IS_TRAIL, and UTEXT_GETNATIVEINDEX.

                                        {
    //
    //  Fast-path the common case.
    //     Common means current position is not at the beginning of a chunk
    //     and the preceding character is not supplementary.
    //
    int32_t i = ut->chunkOffset - 1;
    int64_t result;
    if (i >= 0) {
        UChar c = ut->chunkContents[i];
        if (U16_IS_TRAIL(c) == FALSE) {
            if (i <= ut->nativeIndexingLimit) {
                result = ut->chunkNativeStart + i;
            } else {
                ut->chunkOffset = i;
                result = ut->pFuncs->mapOffsetToNative(ut);
                ut->chunkOffset++;
            }
            return result;
        }
    }

    // If at the start of text, simply return 0.
    if (ut->chunkOffset==0 && ut->chunkNativeStart==0) {
        return 0;
    }

    // Harder, less common cases.  We are at a chunk boundary, or on a surrogate.
    //    Keep it simple, use other functions to handle the edges.
    //
    utext_previous32(ut);
    result = UTEXT_GETNATIVEINDEX(ut);
    utext_next32(ut);
    return result;
}


Generated by  Doxygen 1.6.0   Back to index