intl/icu/source/i18n/fpositer.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     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 ******************************************************************************
     9 */
    11 #include "unicode/utypes.h"
    13 #if !UCONFIG_NO_FORMATTING
    15 #include "unicode/fpositer.h"
    16 #include "cmemory.h"
    17 #include "uvectr32.h"
    19 U_NAMESPACE_BEGIN
    21 FieldPositionIterator::~FieldPositionIterator() {
    22   delete data;
    23   data = NULL;
    24   pos = -1;
    25 }
    27 FieldPositionIterator::FieldPositionIterator()
    28     : data(NULL), pos(-1) {
    29 }
    31 FieldPositionIterator::FieldPositionIterator(const FieldPositionIterator &rhs)
    32   : UObject(rhs), data(NULL), pos(rhs.pos) {
    34   if (rhs.data) {
    35     UErrorCode status = U_ZERO_ERROR;
    36     data = new UVector32(status);
    37     data->assign(*rhs.data, status);
    38     if (status != U_ZERO_ERROR) {
    39       delete data;
    40       data = NULL;
    41       pos = -1;
    42     }
    43   }
    44 }
    46 UBool FieldPositionIterator::operator==(const FieldPositionIterator &rhs) const {
    47   if (&rhs == this) {
    48     return TRUE;
    49   }
    50   if (pos != rhs.pos) {
    51     return FALSE;
    52   }
    53   if (!data) {
    54     return rhs.data == NULL;
    55   }
    56   return rhs.data ? data->operator==(*rhs.data) : FALSE;
    57 }
    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)) {
    62     if (adopt) {
    63       if ((adopt->size() % 3) != 0) {
    64         status = U_ILLEGAL_ARGUMENT_ERROR;
    65       } else {
    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;
    69             break;
    70           }
    71         }
    72       }
    73     }
    74   }
    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)) {
    79     delete adopt;
    80     return;
    81   }
    83   delete data;
    84   data = adopt;
    85   pos = adopt == NULL ? -1 : 0;
    86 }
    88 UBool FieldPositionIterator::next(FieldPosition& fp) {
    89   if (pos == -1) {
    90     return FALSE;
    91   }
    93   fp.setField(data->elementAti(pos++));
    94   fp.setBeginIndex(data->elementAti(pos++));
    95   fp.setEndIndex(data->elementAti(pos++));
    97   if (pos == data->size()) {
    98     pos = -1;
    99   }
   101   return TRUE;
   102 }
   104 U_NAMESPACE_END
   106 #endif /* #if !UCONFIG_NO_FORMATTING */

mercurial