Skip to content

Commit

Permalink
ICU-21653 utext_current32 should handle access callback that changes …
Browse files Browse the repository at this point in the history
…chunk size
  • Loading branch information
pedberg-icu committed Mar 17, 2023
1 parent 34eaffc commit dd1d4de
Show file tree
Hide file tree
Showing 3 changed files with 399 additions and 2 deletions.
7 changes: 5 additions & 2 deletions icu4c/source/common/utext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ utext_current32(UText *ut) {
// 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);
ut->chunkOffset = originalOffset;
// Here we need to restore chunkOffset since the access functions were called with
// chunkNativeLimit but that is not where we were (we were 1 code unit before the
// limit). Restoring was originally added in ICU-4669 but did not support access
// functions that changed the chunk size, the following does.
ut->chunkOffset = ut->chunkLength - 1;
if(!r) {
return U_SENTINEL;
}
Expand Down
Loading

0 comments on commit dd1d4de

Please sign in to comment.