]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/fpositer.cpp
2 ******************************************************************************
3 * Copyright (C) 2009-2012, 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 FieldPositionIterator::~FieldPositionIterator() {
27 FieldPositionIterator::FieldPositionIterator()
28 : data(NULL
), pos(-1) {
31 FieldPositionIterator::FieldPositionIterator(const FieldPositionIterator
&rhs
)
32 : UObject(rhs
), data(NULL
), pos(rhs
.pos
) {
35 UErrorCode status
= U_ZERO_ERROR
;
36 data
= new UVector32(status
);
37 data
->assign(*rhs
.data
, status
);
38 if (status
!= U_ZERO_ERROR
) {
46 UBool
FieldPositionIterator::operator==(const FieldPositionIterator
&rhs
) const {
54 return rhs
.data
== NULL
;
56 return rhs
.data
? data
->operator==(*rhs
.data
) : FALSE
;
59 void FieldPositionIterator::setData(UVector32
*adopt
, UErrorCode
& status
) {
60 // Verify that adopt has valid data, and update status if it doesn't.
61 if (U_SUCCESS(status
)) {
63 if ((adopt
->size() % 3) != 0) {
64 status
= U_ILLEGAL_ARGUMENT_ERROR
;
66 for (int i
= 1; i
< adopt
->size(); i
+= 3) {
67 if (adopt
->elementAti(i
) >= adopt
->elementAti(i
+1)) {
68 status
= U_ILLEGAL_ARGUMENT_ERROR
;
76 // We own the data, even if status is in error, so we need to delete it now
77 // if we're not keeping track of it.
78 if (!U_SUCCESS(status
)) {
85 pos
= adopt
== NULL
? -1 : 0;
88 UBool
FieldPositionIterator::next(FieldPosition
& fp
) {
93 fp
.setField(data
->elementAti(pos
++));
94 fp
.setBeginIndex(data
->elementAti(pos
++));
95 fp
.setEndIndex(data
->elementAti(pos
++));
97 if (pos
== data
->size()) {
106 #endif /* #if !UCONFIG_NO_FORMATTING */