2009-12-17 22:15:20 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2009-2015, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
2009-12-17 22:15:20 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2010-01-26 00:55:35 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2009-12-17 22:15:20 +00:00
|
|
|
|
|
|
|
#include "fphdlimp.h"
|
2010-01-21 23:54:42 +00:00
|
|
|
#include "uvectr32.h"
|
2009-12-17 22:15:20 +00:00
|
|
|
|
2010-01-21 23:25:54 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2009-12-17 22:15:20 +00:00
|
|
|
// utility FieldPositionHandler
|
|
|
|
// base class, null implementation
|
|
|
|
|
|
|
|
FieldPositionHandler::~FieldPositionHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionHandler::addAttribute(int32_t, int32_t, int32_t) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionHandler::shiftLast(int32_t) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool
|
2015-08-25 23:31:01 +00:00
|
|
|
FieldPositionHandler::isRecording(void) const {
|
2009-12-17 22:15:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// utility subclass FieldPositionOnlyHandler
|
|
|
|
|
|
|
|
FieldPositionOnlyHandler::FieldPositionOnlyHandler(FieldPosition& _pos)
|
|
|
|
: pos(_pos) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldPositionOnlyHandler::~FieldPositionOnlyHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionOnlyHandler::addAttribute(int32_t id, int32_t start, int32_t limit) {
|
|
|
|
if (pos.getField() == id) {
|
|
|
|
pos.setBeginIndex(start);
|
|
|
|
pos.setEndIndex(limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionOnlyHandler::shiftLast(int32_t delta) {
|
|
|
|
if (delta != 0 && pos.getField() != FieldPosition::DONT_CARE && pos.getBeginIndex() != -1) {
|
|
|
|
pos.setBeginIndex(delta + pos.getBeginIndex());
|
|
|
|
pos.setEndIndex(delta + pos.getEndIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool
|
2015-08-25 23:31:01 +00:00
|
|
|
FieldPositionOnlyHandler::isRecording(void) const {
|
2009-12-17 22:15:20 +00:00
|
|
|
return pos.getField() != FieldPosition::DONT_CARE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// utility subclass FieldPositionIteratorHandler
|
|
|
|
|
2010-01-28 19:39:24 +00:00
|
|
|
FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator* posIter,
|
2009-12-17 22:15:20 +00:00
|
|
|
UErrorCode& _status)
|
|
|
|
: iter(posIter), vec(NULL), status(_status) {
|
2010-01-28 19:39:24 +00:00
|
|
|
if (iter && U_SUCCESS(status)) {
|
2009-12-17 22:15:20 +00:00
|
|
|
vec = new UVector32(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldPositionIteratorHandler::~FieldPositionIteratorHandler() {
|
|
|
|
// setData adopts the vec regardless of status, so it's safe to null it
|
2010-01-28 19:39:24 +00:00
|
|
|
if (iter) {
|
|
|
|
iter->setData(vec, status);
|
|
|
|
}
|
|
|
|
// if iter is null, we never allocated vec, so no need to free it
|
2009-12-17 22:15:20 +00:00
|
|
|
vec = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionIteratorHandler::addAttribute(int32_t id, int32_t start, int32_t limit) {
|
2010-01-28 19:39:24 +00:00
|
|
|
if (iter && U_SUCCESS(status) && start < limit) {
|
2009-12-17 22:15:20 +00:00
|
|
|
int32_t size = vec->size();
|
|
|
|
vec->addElement(id, status);
|
|
|
|
vec->addElement(start, status);
|
|
|
|
vec->addElement(limit, status);
|
|
|
|
if (!U_SUCCESS(status)) {
|
|
|
|
vec->setSize(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FieldPositionIteratorHandler::shiftLast(int32_t delta) {
|
|
|
|
if (U_SUCCESS(status) && delta != 0) {
|
|
|
|
int32_t i = vec->size();
|
|
|
|
if (i > 0) {
|
|
|
|
--i;
|
|
|
|
vec->setElementAt(delta + vec->elementAti(i), i);
|
|
|
|
--i;
|
|
|
|
vec->setElementAt(delta + vec->elementAti(i), i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool
|
2015-08-25 23:31:01 +00:00
|
|
|
FieldPositionIteratorHandler::isRecording(void) const {
|
2009-12-17 22:15:20 +00:00
|
|
|
return U_SUCCESS(status);
|
|
|
|
}
|
|
|
|
|
2010-01-21 23:25:54 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2010-01-26 00:55:35 +00:00
|
|
|
#endif /* !UCONFIG_NO_FORMATTING */
|