X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/f3c0d7a59d99c2a94c6b8822291f0e42be3773c9..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/i18n/fphdlimp.cpp diff --git a/icuSources/i18n/fphdlimp.cpp b/icuSources/i18n/fphdlimp.cpp index abcec97e..f51bf4ba 100644 --- a/icuSources/i18n/fphdlimp.cpp +++ b/icuSources/i18n/fphdlimp.cpp @@ -22,17 +22,8 @@ U_NAMESPACE_BEGIN FieldPositionHandler::~FieldPositionHandler() { } -void -FieldPositionHandler::addAttribute(int32_t, int32_t, int32_t) { -} - -void -FieldPositionHandler::shiftLast(int32_t) { -} - -UBool -FieldPositionHandler::isRecording(void) const { - return FALSE; +void FieldPositionHandler::setShift(int32_t delta) { + fShift = delta; } @@ -47,9 +38,10 @@ FieldPositionOnlyHandler::~FieldPositionOnlyHandler() { void FieldPositionOnlyHandler::addAttribute(int32_t id, int32_t start, int32_t limit) { - if (pos.getField() == id) { - pos.setBeginIndex(start); - pos.setEndIndex(limit); + if (pos.getField() == id && (!acceptFirstOnly || !seenFirst)) { + seenFirst = TRUE; + pos.setBeginIndex(start + fShift); + pos.setEndIndex(limit + fShift); } } @@ -66,17 +58,27 @@ FieldPositionOnlyHandler::isRecording(void) const { return pos.getField() != FieldPosition::DONT_CARE; } +void FieldPositionOnlyHandler::setAcceptFirstOnly(UBool acceptFirstOnly) { + this->acceptFirstOnly = acceptFirstOnly; +} + // utility subclass FieldPositionIteratorHandler FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator* posIter, UErrorCode& _status) - : iter(posIter), vec(NULL), status(_status) { + : iter(posIter), vec(NULL), status(_status), fCategory(UFIELD_CATEGORY_UNDEFINED) { if (iter && U_SUCCESS(status)) { vec = new UVector32(status); } } +FieldPositionIteratorHandler::FieldPositionIteratorHandler( + UVector32* vec, + UErrorCode& status) + : iter(nullptr), vec(vec), status(status), fCategory(UFIELD_CATEGORY_UNDEFINED) { +} + FieldPositionIteratorHandler::~FieldPositionIteratorHandler() { // setData adopts the vec regardless of status, so it's safe to null it if (iter) { @@ -88,11 +90,12 @@ FieldPositionIteratorHandler::~FieldPositionIteratorHandler() { void FieldPositionIteratorHandler::addAttribute(int32_t id, int32_t start, int32_t limit) { - if (iter && U_SUCCESS(status) && start < limit) { + if (vec && U_SUCCESS(status) && start < limit) { int32_t size = vec->size(); + vec->addElement(fCategory, status); vec->addElement(id, status); - vec->addElement(start, status); - vec->addElement(limit, status); + vec->addElement(start + fShift, status); + vec->addElement(limit + fShift, status); if (!U_SUCCESS(status)) { vec->setSize(size); }