diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /intl/icu/source/i18n/fpositer.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'intl/icu/source/i18n/fpositer.cpp')
-rw-r--r-- | intl/icu/source/i18n/fpositer.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/intl/icu/source/i18n/fpositer.cpp b/intl/icu/source/i18n/fpositer.cpp new file mode 100644 index 000000000..eb405f9c3 --- /dev/null +++ b/intl/icu/source/i18n/fpositer.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +/* +****************************************************************************** +* Copyright (C) 2009-2012, International Business Machines Corporation and +* others. All Rights Reserved. +****************************************************************************** +* Date Name Description +* 12/14/09 doug Creation. +****************************************************************************** +*/ + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "unicode/fpositer.h" +#include "cmemory.h" +#include "uvectr32.h" + +U_NAMESPACE_BEGIN + +FieldPositionIterator::~FieldPositionIterator() { + delete data; + data = NULL; + pos = -1; +} + +FieldPositionIterator::FieldPositionIterator() + : data(NULL), pos(-1) { +} + +FieldPositionIterator::FieldPositionIterator(const FieldPositionIterator &rhs) + : UObject(rhs), data(NULL), pos(rhs.pos) { + + if (rhs.data) { + UErrorCode status = U_ZERO_ERROR; + data = new UVector32(status); + data->assign(*rhs.data, status); + if (status != U_ZERO_ERROR) { + delete data; + data = NULL; + pos = -1; + } + } +} + +UBool FieldPositionIterator::operator==(const FieldPositionIterator &rhs) const { + if (&rhs == this) { + return TRUE; + } + if (pos != rhs.pos) { + return FALSE; + } + if (!data) { + return rhs.data == NULL; + } + return rhs.data ? data->operator==(*rhs.data) : FALSE; +} + +void FieldPositionIterator::setData(UVector32 *adopt, UErrorCode& status) { + // Verify that adopt has valid data, and update status if it doesn't. + if (U_SUCCESS(status)) { + if (adopt) { + if (adopt->size() == 0) { + delete adopt; + adopt = NULL; + } else if ((adopt->size() % 3) != 0) { + status = U_ILLEGAL_ARGUMENT_ERROR; + } else { + for (int i = 1; i < adopt->size(); i += 3) { + if (adopt->elementAti(i) >= adopt->elementAti(i+1)) { + status = U_ILLEGAL_ARGUMENT_ERROR; + break; + } + } + } + } + } + + // We own the data, even if status is in error, so we need to delete it now + // if we're not keeping track of it. + if (!U_SUCCESS(status)) { + delete adopt; + return; + } + + delete data; + data = adopt; + pos = adopt == NULL ? -1 : 0; +} + +UBool FieldPositionIterator::next(FieldPosition& fp) { + if (pos == -1) { + return FALSE; + } + + fp.setField(data->elementAti(pos++)); + fp.setBeginIndex(data->elementAti(pos++)); + fp.setEndIndex(data->elementAti(pos++)); + + if (pos == data->size()) { + pos = -1; + } + + return TRUE; +} + +U_NAMESPACE_END + +#endif /* #if !UCONFIG_NO_FORMATTING */ + |