Get the code point at the current iteration position, or U_SENTINEL (-1) if the iteration has reached the end of the input text.
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 U_ASSERT(r==TRUE); ut->chunkOffset = originalOffset; if(!r) { return U_SENTINEL; } } if (U16_IS_TRAIL(trail)) { supplementaryC = U16_GET_SUPPLEMENTARY(c, trail); } return supplementaryC; }
|