+ if (U_FAILURE(status)) { return NULLORDER; }
+ if (dir_ < 0) {
+ // Continue backwards iteration. Test this first.
+ if (otherHalf_ != 0) {
+ uint32_t oh = otherHalf_;
+ otherHalf_ = 0;
+ return oh;
+ }
+ } else if (dir_ == 0) {
+ iter_->resetToOffset(string_.length());
+ dir_ = -1;
+ } else if (dir_ == 1) {
+ // previous() after setOffset()
+ dir_ = -1;
+ } else /* dir_ > 1 */ {
+ // illegal change of direction
+ status = U_INVALID_STATE_ERROR;
+ return NULLORDER;
+ }
+ if (offsets_ == NULL) {
+ offsets_ = new UVector32(status);
+ if (offsets_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULLORDER;
+ }
+ }
+ // If we already have expansion CEs, then we also have offsets.
+ // Otherwise remember the trailing offset in case we need to
+ // write offsets for an artificial expansion.
+ int32_t limitOffset = iter_->getCEsLength() == 0 ? iter_->getOffset() : 0;
+ int64_t ce = iter_->previousCE(*offsets_, status);
+ if (ce == Collation::NO_CE) { return NULLORDER; }
+ // Turn the 64-bit CE into two old-style 32-bit CEs, without quaternary bits.
+ uint32_t p = (uint32_t)(ce >> 32);
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t firstHalf = getFirstHalf(p, lower32);
+ uint32_t secondHalf = getSecondHalf(p, lower32);
+ if (secondHalf != 0) {
+ if (offsets_->isEmpty()) {
+ // When we convert a single 64-bit CE into two 32-bit CEs,
+ // we need to make this artificial expansion behave like a normal expansion.
+ // See CollationIterator::previousCE().
+ offsets_->addElement(iter_->getOffset(), status);
+ offsets_->addElement(limitOffset, status);
+ }
+ otherHalf_ = firstHalf;
+ return secondHalf | 0xc0; // continuation CE
+ }
+ return firstHalf;