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

U_STABLE UChar32 U_EXPORT2 utext_current32 ( UText ut  ) 

Get the code point at the current iteration position, or U_SENTINEL (-1) if the iteration has reached the end of the input text.

ut the text to be accessed.
the Unicode code point at the current iterator position. ICU 3.4

Definition at line 181 of file utext.cpp.

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

    UChar32  c;
    if (ut->chunkOffset==ut->chunkLength) {
        // Current position is just off the end of the chunk.
        if (ut->pFuncs->access(ut, ut->chunkNativeLimit, TRUE) == FALSE) {
            // Off the end of the text.
            return U_SENTINEL;

    c = ut->chunkContents[ut->chunkOffset];
    if (U16_IS_LEAD(c) == FALSE) {
        // Normal, non-supplementary case.
        return c;

    //  Possible supplementary char.
    UChar32   trail = 0;
    UChar32   supplementaryC = c;
    if ((ut->chunkOffset+1) < ut->chunkLength) {
        // The trail surrogate is in the same chunk.
        trail = ut->chunkContents[ut->chunkOffset+1];
    } else {
        //  The trail surrogate is in a different chunk.
        //     Because we must maintain the iteration position, we need to switch forward
        //     into the new chunk, get the trail surrogate, then revert the chunk back to the
        //     original one.
        //     An edge case to be careful of:  the entire text may end with an unpaired
        //        leading surrogate.  The attempt to access the trail will fail, but
        //        the original position before the unpaired lead still needs to be restored.
        int64_t  nativePosition = ut->chunkNativeLimit;
        int32_t  originalOffset = ut->chunkOffset;
        if (ut->pFuncs->access(ut, nativePosition, TRUE)) {
            trail = ut->chunkContents[ut->chunkOffset];
        UBool r = ut->pFuncs->access(ut, nativePosition, FALSE);  // reverse iteration flag loads preceding chunk
        ut->chunkOffset = originalOffset;
        if(!r) {
            return U_SENTINEL;

    if (U16_IS_TRAIL(trail)) {
        supplementaryC = U16_GET_SUPPLEMENTARY(c, trail);
    return supplementaryC;


Generated by  Doxygen 1.6.0   Back to index