]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/fphdlimp.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2009-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
19 // utility FieldPositionHandler
20 // base class, null implementation
22 FieldPositionHandler::~FieldPositionHandler() {
26 FieldPositionHandler::addAttribute(int32_t, int32_t, int32_t) {
30 FieldPositionHandler::shiftLast(int32_t) {
34 FieldPositionHandler::isRecording(void) const {
39 // utility subclass FieldPositionOnlyHandler
41 FieldPositionOnlyHandler::FieldPositionOnlyHandler(FieldPosition
& _pos
)
45 FieldPositionOnlyHandler::~FieldPositionOnlyHandler() {
49 FieldPositionOnlyHandler::addAttribute(int32_t id
, int32_t start
, int32_t limit
) {
50 if (pos
.getField() == id
) {
51 pos
.setBeginIndex(start
);
52 pos
.setEndIndex(limit
);
57 FieldPositionOnlyHandler::shiftLast(int32_t delta
) {
58 if (delta
!= 0 && pos
.getField() != FieldPosition::DONT_CARE
&& pos
.getBeginIndex() != -1) {
59 pos
.setBeginIndex(delta
+ pos
.getBeginIndex());
60 pos
.setEndIndex(delta
+ pos
.getEndIndex());
65 FieldPositionOnlyHandler::isRecording(void) const {
66 return pos
.getField() != FieldPosition::DONT_CARE
;
70 // utility subclass FieldPositionIteratorHandler
72 FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator
* posIter
,
74 : iter(posIter
), vec(NULL
), status(_status
) {
75 if (iter
&& U_SUCCESS(status
)) {
76 vec
= new UVector32(status
);
80 FieldPositionIteratorHandler::~FieldPositionIteratorHandler() {
81 // setData adopts the vec regardless of status, so it's safe to null it
83 iter
->setData(vec
, status
);
85 // if iter is null, we never allocated vec, so no need to free it
90 FieldPositionIteratorHandler::addAttribute(int32_t id
, int32_t start
, int32_t limit
) {
91 if (iter
&& U_SUCCESS(status
) && start
< limit
) {
92 int32_t size
= vec
->size();
93 vec
->addElement(id
, status
);
94 vec
->addElement(start
, status
);
95 vec
->addElement(limit
, status
);
96 if (!U_SUCCESS(status
)) {
103 FieldPositionIteratorHandler::shiftLast(int32_t delta
) {
104 if (U_SUCCESS(status
) && delta
!= 0) {
105 int32_t i
= vec
->size();
108 vec
->setElementAt(delta
+ vec
->elementAti(i
), i
);
110 vec
->setElementAt(delta
+ vec
->elementAti(i
), i
);
116 FieldPositionIteratorHandler::isRecording(void) const {
117 return U_SUCCESS(status
);
122 #endif /* !UCONFIG_NO_FORMATTING */