intl/icu/source/common/unicode/uchriter.h

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.

michael@0 1 /*
michael@0 2 **********************************************************************
michael@0 3 * Copyright (C) 1998-2005, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 **********************************************************************
michael@0 6 */
michael@0 7
michael@0 8 #ifndef UCHRITER_H
michael@0 9 #define UCHRITER_H
michael@0 10
michael@0 11 #include "unicode/utypes.h"
michael@0 12 #include "unicode/chariter.h"
michael@0 13
michael@0 14 /**
michael@0 15 * \file
michael@0 16 * \brief C++ API: UChar Character Iterator
michael@0 17 */
michael@0 18
michael@0 19 U_NAMESPACE_BEGIN
michael@0 20
michael@0 21 /**
michael@0 22 * A concrete subclass of CharacterIterator that iterates over the
michael@0 23 * characters (code units or code points) in a UChar array.
michael@0 24 * It's possible not only to create an
michael@0 25 * iterator that iterates over an entire UChar array, but also to
michael@0 26 * create one that iterates over only a subrange of a UChar array
michael@0 27 * (iterators over different subranges of the same UChar array don't
michael@0 28 * compare equal).
michael@0 29 * @see CharacterIterator
michael@0 30 * @see ForwardCharacterIterator
michael@0 31 * @stable ICU 2.0
michael@0 32 */
michael@0 33 class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
michael@0 34 public:
michael@0 35 /**
michael@0 36 * Create an iterator over the UChar array referred to by "textPtr".
michael@0 37 * The iteration range is 0 to <code>length-1</code>.
michael@0 38 * text is only aliased, not adopted (the
michael@0 39 * destructor will not delete it).
michael@0 40 * @param textPtr The UChar array to be iterated over
michael@0 41 * @param length The length of the UChar array
michael@0 42 * @stable ICU 2.0
michael@0 43 */
michael@0 44 UCharCharacterIterator(const UChar* textPtr, int32_t length);
michael@0 45
michael@0 46 /**
michael@0 47 * Create an iterator over the UChar array referred to by "textPtr".
michael@0 48 * The iteration range is 0 to <code>length-1</code>.
michael@0 49 * text is only aliased, not adopted (the
michael@0 50 * destructor will not delete it).
michael@0 51 * The starting
michael@0 52 * position is specified by "position". If "position" is outside the valid
michael@0 53 * iteration range, the behavior of this object is undefined.
michael@0 54 * @param textPtr The UChar array to be iteratd over
michael@0 55 * @param length The length of the UChar array
michael@0 56 * @param position The starting position of the iteration
michael@0 57 * @stable ICU 2.0
michael@0 58 */
michael@0 59 UCharCharacterIterator(const UChar* textPtr, int32_t length,
michael@0 60 int32_t position);
michael@0 61
michael@0 62 /**
michael@0 63 * Create an iterator over the UChar array referred to by "textPtr".
michael@0 64 * The iteration range is 0 to <code>end-1</code>.
michael@0 65 * text is only aliased, not adopted (the
michael@0 66 * destructor will not delete it).
michael@0 67 * The starting
michael@0 68 * position is specified by "position". If begin and end do not
michael@0 69 * form a valid iteration range or "position" is outside the valid
michael@0 70 * iteration range, the behavior of this object is undefined.
michael@0 71 * @param textPtr The UChar array to be iterated over
michael@0 72 * @param length The length of the UChar array
michael@0 73 * @param textBegin The begin position of the iteration range
michael@0 74 * @param textEnd The end position of the iteration range
michael@0 75 * @param position The starting position of the iteration
michael@0 76 * @stable ICU 2.0
michael@0 77 */
michael@0 78 UCharCharacterIterator(const UChar* textPtr, int32_t length,
michael@0 79 int32_t textBegin,
michael@0 80 int32_t textEnd,
michael@0 81 int32_t position);
michael@0 82
michael@0 83 /**
michael@0 84 * Copy constructor. The new iterator iterates over the same range
michael@0 85 * of the same string as "that", and its initial position is the
michael@0 86 * same as "that"'s current position.
michael@0 87 * @param that The UCharCharacterIterator to be copied
michael@0 88 * @stable ICU 2.0
michael@0 89 */
michael@0 90 UCharCharacterIterator(const UCharCharacterIterator& that);
michael@0 91
michael@0 92 /**
michael@0 93 * Destructor.
michael@0 94 * @stable ICU 2.0
michael@0 95 */
michael@0 96 virtual ~UCharCharacterIterator();
michael@0 97
michael@0 98 /**
michael@0 99 * Assignment operator. *this is altered to iterate over the sane
michael@0 100 * range of the same string as "that", and refers to the same
michael@0 101 * character within that string as "that" does.
michael@0 102 * @param that The object to be copied
michael@0 103 * @return the newly created object
michael@0 104 * @stable ICU 2.0
michael@0 105 */
michael@0 106 UCharCharacterIterator&
michael@0 107 operator=(const UCharCharacterIterator& that);
michael@0 108
michael@0 109 /**
michael@0 110 * Returns true if the iterators iterate over the same range of the
michael@0 111 * same string and are pointing at the same character.
michael@0 112 * @param that The ForwardCharacterIterator used to be compared for equality
michael@0 113 * @return true if the iterators iterate over the same range of the
michael@0 114 * same string and are pointing at the same character.
michael@0 115 * @stable ICU 2.0
michael@0 116 */
michael@0 117 virtual UBool operator==(const ForwardCharacterIterator& that) const;
michael@0 118
michael@0 119 /**
michael@0 120 * Generates a hash code for this iterator.
michael@0 121 * @return the hash code.
michael@0 122 * @stable ICU 2.0
michael@0 123 */
michael@0 124 virtual int32_t hashCode(void) const;
michael@0 125
michael@0 126 /**
michael@0 127 * Returns a new UCharCharacterIterator referring to the same
michael@0 128 * character in the same range of the same string as this one. The
michael@0 129 * caller must delete the new iterator.
michael@0 130 * @return the CharacterIterator newly created
michael@0 131 * @stable ICU 2.0
michael@0 132 */
michael@0 133 virtual CharacterIterator* clone(void) const;
michael@0 134
michael@0 135 /**
michael@0 136 * Sets the iterator to refer to the first code unit in its
michael@0 137 * iteration range, and returns that code unit.
michael@0 138 * This can be used to begin an iteration with next().
michael@0 139 * @return the first code unit in its iteration range.
michael@0 140 * @stable ICU 2.0
michael@0 141 */
michael@0 142 virtual UChar first(void);
michael@0 143
michael@0 144 /**
michael@0 145 * Sets the iterator to refer to the first code unit in its
michael@0 146 * iteration range, returns that code unit, and moves the position
michael@0 147 * to the second code unit. This is an alternative to setToStart()
michael@0 148 * for forward iteration with nextPostInc().
michael@0 149 * @return the first code unit in its iteration range
michael@0 150 * @stable ICU 2.0
michael@0 151 */
michael@0 152 virtual UChar firstPostInc(void);
michael@0 153
michael@0 154 /**
michael@0 155 * Sets the iterator to refer to the first code point in its
michael@0 156 * iteration range, and returns that code unit,
michael@0 157 * This can be used to begin an iteration with next32().
michael@0 158 * Note that an iteration with next32PostInc(), beginning with,
michael@0 159 * e.g., setToStart() or firstPostInc(), is more efficient.
michael@0 160 * @return the first code point in its iteration range
michael@0 161 * @stable ICU 2.0
michael@0 162 */
michael@0 163 virtual UChar32 first32(void);
michael@0 164
michael@0 165 /**
michael@0 166 * Sets the iterator to refer to the first code point in its
michael@0 167 * iteration range, returns that code point, and moves the position
michael@0 168 * to the second code point. This is an alternative to setToStart()
michael@0 169 * for forward iteration with next32PostInc().
michael@0 170 * @return the first code point in its iteration range.
michael@0 171 * @stable ICU 2.0
michael@0 172 */
michael@0 173 virtual UChar32 first32PostInc(void);
michael@0 174
michael@0 175 /**
michael@0 176 * Sets the iterator to refer to the last code unit in its
michael@0 177 * iteration range, and returns that code unit.
michael@0 178 * This can be used to begin an iteration with previous().
michael@0 179 * @return the last code unit in its iteration range.
michael@0 180 * @stable ICU 2.0
michael@0 181 */
michael@0 182 virtual UChar last(void);
michael@0 183
michael@0 184 /**
michael@0 185 * Sets the iterator to refer to the last code point in its
michael@0 186 * iteration range, and returns that code unit.
michael@0 187 * This can be used to begin an iteration with previous32().
michael@0 188 * @return the last code point in its iteration range.
michael@0 189 * @stable ICU 2.0
michael@0 190 */
michael@0 191 virtual UChar32 last32(void);
michael@0 192
michael@0 193 /**
michael@0 194 * Sets the iterator to refer to the "position"-th code unit
michael@0 195 * in the text-storage object the iterator refers to, and
michael@0 196 * returns that code unit.
michael@0 197 * @param position the position within the text-storage object
michael@0 198 * @return the code unit
michael@0 199 * @stable ICU 2.0
michael@0 200 */
michael@0 201 virtual UChar setIndex(int32_t position);
michael@0 202
michael@0 203 /**
michael@0 204 * Sets the iterator to refer to the beginning of the code point
michael@0 205 * that contains the "position"-th code unit
michael@0 206 * in the text-storage object the iterator refers to, and
michael@0 207 * returns that code point.
michael@0 208 * The current position is adjusted to the beginning of the code point
michael@0 209 * (its first code unit).
michael@0 210 * @param position the position within the text-storage object
michael@0 211 * @return the code unit
michael@0 212 * @stable ICU 2.0
michael@0 213 */
michael@0 214 virtual UChar32 setIndex32(int32_t position);
michael@0 215
michael@0 216 /**
michael@0 217 * Returns the code unit the iterator currently refers to.
michael@0 218 * @return the code unit the iterator currently refers to.
michael@0 219 * @stable ICU 2.0
michael@0 220 */
michael@0 221 virtual UChar current(void) const;
michael@0 222
michael@0 223 /**
michael@0 224 * Returns the code point the iterator currently refers to.
michael@0 225 * @return the code point the iterator currently refers to.
michael@0 226 * @stable ICU 2.0
michael@0 227 */
michael@0 228 virtual UChar32 current32(void) const;
michael@0 229
michael@0 230 /**
michael@0 231 * Advances to the next code unit in the iteration range (toward
michael@0 232 * endIndex()), and returns that code unit. If there are no more
michael@0 233 * code units to return, returns DONE.
michael@0 234 * @return the next code unit in the iteration range.
michael@0 235 * @stable ICU 2.0
michael@0 236 */
michael@0 237 virtual UChar next(void);
michael@0 238
michael@0 239 /**
michael@0 240 * Gets the current code unit for returning and advances to the next code unit
michael@0 241 * in the iteration range
michael@0 242 * (toward endIndex()). If there are
michael@0 243 * no more code units to return, returns DONE.
michael@0 244 * @return the current code unit.
michael@0 245 * @stable ICU 2.0
michael@0 246 */
michael@0 247 virtual UChar nextPostInc(void);
michael@0 248
michael@0 249 /**
michael@0 250 * Advances to the next code point in the iteration range (toward
michael@0 251 * endIndex()), and returns that code point. If there are no more
michael@0 252 * code points to return, returns DONE.
michael@0 253 * Note that iteration with "pre-increment" semantics is less
michael@0 254 * efficient than iteration with "post-increment" semantics
michael@0 255 * that is provided by next32PostInc().
michael@0 256 * @return the next code point in the iteration range.
michael@0 257 * @stable ICU 2.0
michael@0 258 */
michael@0 259 virtual UChar32 next32(void);
michael@0 260
michael@0 261 /**
michael@0 262 * Gets the current code point for returning and advances to the next code point
michael@0 263 * in the iteration range
michael@0 264 * (toward endIndex()). If there are
michael@0 265 * no more code points to return, returns DONE.
michael@0 266 * @return the current point.
michael@0 267 * @stable ICU 2.0
michael@0 268 */
michael@0 269 virtual UChar32 next32PostInc(void);
michael@0 270
michael@0 271 /**
michael@0 272 * Returns FALSE if there are no more code units or code points
michael@0 273 * at or after the current position in the iteration range.
michael@0 274 * This is used with nextPostInc() or next32PostInc() in forward
michael@0 275 * iteration.
michael@0 276 * @return FALSE if there are no more code units or code points
michael@0 277 * at or after the current position in the iteration range.
michael@0 278 * @stable ICU 2.0
michael@0 279 */
michael@0 280 virtual UBool hasNext();
michael@0 281
michael@0 282 /**
michael@0 283 * Advances to the previous code unit in the iteration range (toward
michael@0 284 * startIndex()), and returns that code unit. If there are no more
michael@0 285 * code units to return, returns DONE.
michael@0 286 * @return the previous code unit in the iteration range.
michael@0 287 * @stable ICU 2.0
michael@0 288 */
michael@0 289 virtual UChar previous(void);
michael@0 290
michael@0 291 /**
michael@0 292 * Advances to the previous code point in the iteration range (toward
michael@0 293 * startIndex()), and returns that code point. If there are no more
michael@0 294 * code points to return, returns DONE.
michael@0 295 * @return the previous code point in the iteration range.
michael@0 296 * @stable ICU 2.0
michael@0 297 */
michael@0 298 virtual UChar32 previous32(void);
michael@0 299
michael@0 300 /**
michael@0 301 * Returns FALSE if there are no more code units or code points
michael@0 302 * before the current position in the iteration range.
michael@0 303 * This is used with previous() or previous32() in backward
michael@0 304 * iteration.
michael@0 305 * @return FALSE if there are no more code units or code points
michael@0 306 * before the current position in the iteration range.
michael@0 307 * @stable ICU 2.0
michael@0 308 */
michael@0 309 virtual UBool hasPrevious();
michael@0 310
michael@0 311 /**
michael@0 312 * Moves the current position relative to the start or end of the
michael@0 313 * iteration range, or relative to the current position itself.
michael@0 314 * The movement is expressed in numbers of code units forward
michael@0 315 * or backward by specifying a positive or negative delta.
michael@0 316 * @param delta the position relative to origin. A positive delta means forward;
michael@0 317 * a negative delta means backward.
michael@0 318 * @param origin Origin enumeration {kStart, kCurrent, kEnd}
michael@0 319 * @return the new position
michael@0 320 * @stable ICU 2.0
michael@0 321 */
michael@0 322 virtual int32_t move(int32_t delta, EOrigin origin);
michael@0 323
michael@0 324 /**
michael@0 325 * Moves the current position relative to the start or end of the
michael@0 326 * iteration range, or relative to the current position itself.
michael@0 327 * The movement is expressed in numbers of code points forward
michael@0 328 * or backward by specifying a positive or negative delta.
michael@0 329 * @param delta the position relative to origin. A positive delta means forward;
michael@0 330 * a negative delta means backward.
michael@0 331 * @param origin Origin enumeration {kStart, kCurrent, kEnd}
michael@0 332 * @return the new position
michael@0 333 * @stable ICU 2.0
michael@0 334 */
michael@0 335 virtual int32_t move32(int32_t delta, EOrigin origin);
michael@0 336
michael@0 337 /**
michael@0 338 * Sets the iterator to iterate over a new range of text
michael@0 339 * @stable ICU 2.0
michael@0 340 */
michael@0 341 void setText(const UChar* newText, int32_t newTextLength);
michael@0 342
michael@0 343 /**
michael@0 344 * Copies the UChar array under iteration into the UnicodeString
michael@0 345 * referred to by "result". Even if this iterator iterates across
michael@0 346 * only a part of this string, the whole string is copied.
michael@0 347 * @param result Receives a copy of the text under iteration.
michael@0 348 * @stable ICU 2.0
michael@0 349 */
michael@0 350 virtual void getText(UnicodeString& result);
michael@0 351
michael@0 352 /**
michael@0 353 * Return a class ID for this class (not really public)
michael@0 354 * @return a class ID for this class
michael@0 355 * @stable ICU 2.0
michael@0 356 */
michael@0 357 static UClassID U_EXPORT2 getStaticClassID(void);
michael@0 358
michael@0 359 /**
michael@0 360 * Return a class ID for this object (not really public)
michael@0 361 * @return a class ID for this object.
michael@0 362 * @stable ICU 2.0
michael@0 363 */
michael@0 364 virtual UClassID getDynamicClassID(void) const;
michael@0 365
michael@0 366 protected:
michael@0 367 /**
michael@0 368 * Protected constructor
michael@0 369 * @stable ICU 2.0
michael@0 370 */
michael@0 371 UCharCharacterIterator();
michael@0 372 /**
michael@0 373 * Protected member text
michael@0 374 * @stable ICU 2.0
michael@0 375 */
michael@0 376 const UChar* text;
michael@0 377
michael@0 378 };
michael@0 379
michael@0 380 U_NAMESPACE_END
michael@0 381 #endif

mercurial