Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved. |
michael@0 | 3 | ******************************************************************************* |
michael@0 | 4 | * |
michael@0 | 5 | * File PARSEPOS.H |
michael@0 | 6 | * |
michael@0 | 7 | * Modification History: |
michael@0 | 8 | * |
michael@0 | 9 | * Date Name Description |
michael@0 | 10 | * 07/09/97 helena Converted from java. |
michael@0 | 11 | * 07/17/98 stephen Added errorIndex support. |
michael@0 | 12 | * 05/11/99 stephen Cleaned up. |
michael@0 | 13 | ******************************************************************************* |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #ifndef PARSEPOS_H |
michael@0 | 17 | #define PARSEPOS_H |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/utypes.h" |
michael@0 | 20 | #include "unicode/uobject.h" |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | U_NAMESPACE_BEGIN |
michael@0 | 24 | |
michael@0 | 25 | /** |
michael@0 | 26 | * \file |
michael@0 | 27 | * \brief C++ API: Canonical Iterator |
michael@0 | 28 | */ |
michael@0 | 29 | /** |
michael@0 | 30 | * <code>ParsePosition</code> is a simple class used by <code>Format</code> |
michael@0 | 31 | * and its subclasses to keep track of the current position during parsing. |
michael@0 | 32 | * The <code>parseObject</code> method in the various <code>Format</code> |
michael@0 | 33 | * classes requires a <code>ParsePosition</code> object as an argument. |
michael@0 | 34 | * |
michael@0 | 35 | * <p> |
michael@0 | 36 | * By design, as you parse through a string with different formats, |
michael@0 | 37 | * you can use the same <code>ParsePosition</code>, since the index parameter |
michael@0 | 38 | * records the current position. |
michael@0 | 39 | * |
michael@0 | 40 | * The ParsePosition class is not suitable for subclassing. |
michael@0 | 41 | * |
michael@0 | 42 | * @version 1.3 10/30/97 |
michael@0 | 43 | * @author Mark Davis, Helena Shih |
michael@0 | 44 | * @see java.text.Format |
michael@0 | 45 | */ |
michael@0 | 46 | |
michael@0 | 47 | class U_COMMON_API ParsePosition : public UObject { |
michael@0 | 48 | public: |
michael@0 | 49 | /** |
michael@0 | 50 | * Default constructor, the index starts with 0 as default. |
michael@0 | 51 | * @stable ICU 2.0 |
michael@0 | 52 | */ |
michael@0 | 53 | ParsePosition() |
michael@0 | 54 | : UObject(), |
michael@0 | 55 | index(0), |
michael@0 | 56 | errorIndex(-1) |
michael@0 | 57 | {} |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Create a new ParsePosition with the given initial index. |
michael@0 | 61 | * @param newIndex the new text offset. |
michael@0 | 62 | * @stable ICU 2.0 |
michael@0 | 63 | */ |
michael@0 | 64 | ParsePosition(int32_t newIndex) |
michael@0 | 65 | : UObject(), |
michael@0 | 66 | index(newIndex), |
michael@0 | 67 | errorIndex(-1) |
michael@0 | 68 | {} |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Copy constructor |
michael@0 | 72 | * @param copy the object to be copied from. |
michael@0 | 73 | * @stable ICU 2.0 |
michael@0 | 74 | */ |
michael@0 | 75 | ParsePosition(const ParsePosition& copy) |
michael@0 | 76 | : UObject(copy), |
michael@0 | 77 | index(copy.index), |
michael@0 | 78 | errorIndex(copy.errorIndex) |
michael@0 | 79 | {} |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * Destructor |
michael@0 | 83 | * @stable ICU 2.0 |
michael@0 | 84 | */ |
michael@0 | 85 | virtual ~ParsePosition(); |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Assignment operator |
michael@0 | 89 | * @stable ICU 2.0 |
michael@0 | 90 | */ |
michael@0 | 91 | ParsePosition& operator=(const ParsePosition& copy); |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Equality operator. |
michael@0 | 95 | * @return TRUE if the two parse positions are equal, FALSE otherwise. |
michael@0 | 96 | * @stable ICU 2.0 |
michael@0 | 97 | */ |
michael@0 | 98 | UBool operator==(const ParsePosition& that) const; |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Equality operator. |
michael@0 | 102 | * @return TRUE if the two parse positions are not equal, FALSE otherwise. |
michael@0 | 103 | * @stable ICU 2.0 |
michael@0 | 104 | */ |
michael@0 | 105 | UBool operator!=(const ParsePosition& that) const; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Clone this object. |
michael@0 | 109 | * Clones can be used concurrently in multiple threads. |
michael@0 | 110 | * If an error occurs, then NULL is returned. |
michael@0 | 111 | * The caller must delete the clone. |
michael@0 | 112 | * |
michael@0 | 113 | * @return a clone of this object |
michael@0 | 114 | * |
michael@0 | 115 | * @see getDynamicClassID |
michael@0 | 116 | * @stable ICU 2.8 |
michael@0 | 117 | */ |
michael@0 | 118 | ParsePosition *clone() const; |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Retrieve the current parse position. On input to a parse method, this |
michael@0 | 122 | * is the index of the character at which parsing will begin; on output, it |
michael@0 | 123 | * is the index of the character following the last character parsed. |
michael@0 | 124 | * @return the current index. |
michael@0 | 125 | * @stable ICU 2.0 |
michael@0 | 126 | */ |
michael@0 | 127 | int32_t getIndex(void) const; |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Set the current parse position. |
michael@0 | 131 | * @param index the new index. |
michael@0 | 132 | * @stable ICU 2.0 |
michael@0 | 133 | */ |
michael@0 | 134 | void setIndex(int32_t index); |
michael@0 | 135 | |
michael@0 | 136 | /** |
michael@0 | 137 | * Set the index at which a parse error occurred. Formatters |
michael@0 | 138 | * should set this before returning an error code from their |
michael@0 | 139 | * parseObject method. The default value is -1 if this is not |
michael@0 | 140 | * set. |
michael@0 | 141 | * @stable ICU 2.0 |
michael@0 | 142 | */ |
michael@0 | 143 | void setErrorIndex(int32_t ei); |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Retrieve the index at which an error occurred, or -1 if the |
michael@0 | 147 | * error index has not been set. |
michael@0 | 148 | * @stable ICU 2.0 |
michael@0 | 149 | */ |
michael@0 | 150 | int32_t getErrorIndex(void) const; |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 154 | * |
michael@0 | 155 | * @stable ICU 2.2 |
michael@0 | 156 | */ |
michael@0 | 157 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 161 | * |
michael@0 | 162 | * @stable ICU 2.2 |
michael@0 | 163 | */ |
michael@0 | 164 | virtual UClassID getDynamicClassID() const; |
michael@0 | 165 | |
michael@0 | 166 | private: |
michael@0 | 167 | /** |
michael@0 | 168 | * Input: the place you start parsing. |
michael@0 | 169 | * <br>Output: position where the parse stopped. |
michael@0 | 170 | * This is designed to be used serially, |
michael@0 | 171 | * with each call setting index up for the next one. |
michael@0 | 172 | */ |
michael@0 | 173 | int32_t index; |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * The index at which a parse error occurred. |
michael@0 | 177 | */ |
michael@0 | 178 | int32_t errorIndex; |
michael@0 | 179 | |
michael@0 | 180 | }; |
michael@0 | 181 | |
michael@0 | 182 | inline ParsePosition& |
michael@0 | 183 | ParsePosition::operator=(const ParsePosition& copy) |
michael@0 | 184 | { |
michael@0 | 185 | index = copy.index; |
michael@0 | 186 | errorIndex = copy.errorIndex; |
michael@0 | 187 | return *this; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | inline UBool |
michael@0 | 191 | ParsePosition::operator==(const ParsePosition& copy) const |
michael@0 | 192 | { |
michael@0 | 193 | if(index != copy.index || errorIndex != copy.errorIndex) |
michael@0 | 194 | return FALSE; |
michael@0 | 195 | else |
michael@0 | 196 | return TRUE; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | inline UBool |
michael@0 | 200 | ParsePosition::operator!=(const ParsePosition& copy) const |
michael@0 | 201 | { |
michael@0 | 202 | return !operator==(copy); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | inline int32_t |
michael@0 | 206 | ParsePosition::getIndex() const |
michael@0 | 207 | { |
michael@0 | 208 | return index; |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | inline void |
michael@0 | 212 | ParsePosition::setIndex(int32_t offset) |
michael@0 | 213 | { |
michael@0 | 214 | this->index = offset; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | inline int32_t |
michael@0 | 218 | ParsePosition::getErrorIndex() const |
michael@0 | 219 | { |
michael@0 | 220 | return errorIndex; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | inline void |
michael@0 | 224 | ParsePosition::setErrorIndex(int32_t ei) |
michael@0 | 225 | { |
michael@0 | 226 | this->errorIndex = ei; |
michael@0 | 227 | } |
michael@0 | 228 | U_NAMESPACE_END |
michael@0 | 229 | |
michael@0 | 230 | #endif |