]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/fphdlimp.cpp
2 *******************************************************************************
3 * Copyright (C) 2009-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
17 // utility FieldPositionHandler
18 // base class, null implementation
20 FieldPositionHandler::~FieldPositionHandler() {
24 FieldPositionHandler::addAttribute(int32_t, int32_t, int32_t) {
28 FieldPositionHandler::shiftLast(int32_t) {
32 FieldPositionHandler::isRecording(void) {
37 // utility subclass FieldPositionOnlyHandler
39 FieldPositionOnlyHandler::FieldPositionOnlyHandler(FieldPosition
& _pos
)
43 FieldPositionOnlyHandler::~FieldPositionOnlyHandler() {
47 FieldPositionOnlyHandler::addAttribute(int32_t id
, int32_t start
, int32_t limit
) {
48 if (pos
.getField() == id
) {
49 pos
.setBeginIndex(start
);
50 pos
.setEndIndex(limit
);
55 FieldPositionOnlyHandler::shiftLast(int32_t delta
) {
56 if (delta
!= 0 && pos
.getField() != FieldPosition::DONT_CARE
&& pos
.getBeginIndex() != -1) {
57 pos
.setBeginIndex(delta
+ pos
.getBeginIndex());
58 pos
.setEndIndex(delta
+ pos
.getEndIndex());
63 FieldPositionOnlyHandler::isRecording(void) {
64 return pos
.getField() != FieldPosition::DONT_CARE
;
68 // utility subclass FieldPositionIteratorHandler
70 FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator
* posIter
,
72 : iter(posIter
), vec(NULL
), status(_status
) {
73 if (iter
&& U_SUCCESS(status
)) {
74 vec
= new UVector32(status
);
78 FieldPositionIteratorHandler::~FieldPositionIteratorHandler() {
79 // setData adopts the vec regardless of status, so it's safe to null it
81 iter
->setData(vec
, status
);
83 // if iter is null, we never allocated vec, so no need to free it
88 FieldPositionIteratorHandler::addAttribute(int32_t id
, int32_t start
, int32_t limit
) {
89 if (iter
&& U_SUCCESS(status
) && start
< limit
) {
90 int32_t size
= vec
->size();
91 vec
->addElement(id
, status
);
92 vec
->addElement(start
, status
);
93 vec
->addElement(limit
, status
);
94 if (!U_SUCCESS(status
)) {
101 FieldPositionIteratorHandler::shiftLast(int32_t delta
) {
102 if (U_SUCCESS(status
) && delta
!= 0) {
103 int32_t i
= vec
->size();
106 vec
->setElementAt(delta
+ vec
->elementAti(i
), i
);
108 vec
->setElementAt(delta
+ vec
->elementAti(i
), i
);
114 FieldPositionIteratorHandler::isRecording(void) {
115 return U_SUCCESS(status
);
120 #endif /* !UCONFIG_NO_FORMATTING */