]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/fpositer.cpp
2 ******************************************************************************
3 * Copyright (C) 2009-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
6 * Date Name Description
7 * 12/14/09 doug Creation.
8 ******************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
15 #include "unicode/fpositer.h"
21 UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(FieldPositionIterator
)
23 FieldPositionIterator::~FieldPositionIterator() {
29 FieldPositionIterator::FieldPositionIterator()
30 : data(NULL
), pos(-1) {
33 FieldPositionIterator::FieldPositionIterator(const FieldPositionIterator
&rhs
)
34 : UObject(rhs
), data(NULL
), pos(rhs
.pos
) {
37 UErrorCode status
= U_ZERO_ERROR
;
38 data
= new UVector32(status
);
39 data
->assign(*rhs
.data
, status
);
40 if (status
!= U_ZERO_ERROR
) {
48 UBool
FieldPositionIterator::operator==(const FieldPositionIterator
&rhs
) const {
56 return rhs
.data
== NULL
;
58 return rhs
.data
? data
->operator==(*rhs
.data
) : FALSE
;
61 void FieldPositionIterator::setData(UVector32
*adopt
, UErrorCode
& status
) {
62 // Verify that adopt has valid data, and update status if it doesn't.
63 if (U_SUCCESS(status
)) {
65 if ((adopt
->size() % 3) != 0) {
66 status
= U_ILLEGAL_ARGUMENT_ERROR
;
68 for (int i
= 1; i
< adopt
->size(); i
+= 3) {
69 if (adopt
->elementAti(i
) >= adopt
->elementAti(i
+1)) {
70 status
= U_ILLEGAL_ARGUMENT_ERROR
;
78 // We own the data, even if status is in error, so we need to delete it now
79 // if we're not keeping track of it.
80 if (!U_SUCCESS(status
)) {
87 pos
= adopt
== NULL
? -1 : 0;
90 UBool
FieldPositionIterator::next(FieldPosition
& fp
) {
95 fp
.setField(data
->elementAti(pos
++));
96 fp
.setBeginIndex(data
->elementAti(pos
++));
97 fp
.setEndIndex(data
->elementAti(pos
++));
99 if (pos
== data
->size()) {
108 #endif /* #if !UCONFIG_NO_FORMATTING */