Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:10

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 **********************************************************************
0005 *   Copyright (C) 1998-2005, International Business Machines
0006 *   Corporation and others.  All Rights Reserved.
0007 **********************************************************************
0008 */
0009 
0010 #ifndef UCHRITER_H
0011 #define UCHRITER_H
0012 
0013 #include "unicode/utypes.h"
0014 
0015 #if U_SHOW_CPLUSPLUS_API
0016 
0017 #include "unicode/chariter.h"
0018 
0019 /**
0020  * \file 
0021  * \brief C++ API: char16_t Character Iterator
0022  */
0023  
0024 U_NAMESPACE_BEGIN
0025 
0026 /**
0027  * A concrete subclass of CharacterIterator that iterates over the
0028  * characters (code units or code points) in a char16_t array.
0029  * It's possible not only to create an
0030  * iterator that iterates over an entire char16_t array, but also to
0031  * create one that iterates over only a subrange of a char16_t array
0032  * (iterators over different subranges of the same char16_t array don't
0033  * compare equal).
0034  * @see CharacterIterator
0035  * @see ForwardCharacterIterator
0036  * @stable ICU 2.0
0037  */
0038 class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
0039 public:
0040   /**
0041    * Create an iterator over the char16_t array referred to by "textPtr".
0042    * The iteration range is 0 to <code>length-1</code>.
0043    * text is only aliased, not adopted (the
0044    * destructor will not delete it).
0045    * @param textPtr The char16_t array to be iterated over
0046    * @param length The length of the char16_t array
0047    * @stable ICU 2.0
0048    */
0049   UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length);
0050 
0051   /**
0052    * Create an iterator over the char16_t array referred to by "textPtr".
0053    * The iteration range is 0 to <code>length-1</code>.
0054    * text is only aliased, not adopted (the
0055    * destructor will not delete it).
0056    * The starting
0057    * position is specified by "position". If "position" is outside the valid
0058    * iteration range, the behavior of this object is undefined.
0059    * @param textPtr The char16_t array to be iterated over
0060    * @param length The length of the char16_t array
0061    * @param position The starting position of the iteration
0062    * @stable ICU 2.0
0063    */
0064   UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
0065                          int32_t position);
0066 
0067   /**
0068    * Create an iterator over the char16_t array referred to by "textPtr".
0069    * The iteration range is 0 to <code>end-1</code>.
0070    * text is only aliased, not adopted (the
0071    * destructor will not delete it).
0072    * The starting
0073    * position is specified by "position". If begin and end do not
0074    * form a valid iteration range or "position" is outside the valid
0075    * iteration range, the behavior of this object is undefined.
0076    * @param textPtr The char16_t array to be iterated over
0077    * @param length The length of the char16_t array
0078    * @param textBegin  The begin position of the iteration range
0079    * @param textEnd    The end position of the iteration range
0080    * @param position    The starting position of the iteration
0081    * @stable ICU 2.0
0082    */
0083   UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
0084                          int32_t textBegin,
0085                          int32_t textEnd,
0086                          int32_t position);
0087 
0088   /**
0089    * Copy constructor.  The new iterator iterates over the same range
0090    * of the same string as "that", and its initial position is the
0091    * same as "that"'s current position.
0092    * @param that The UCharCharacterIterator to be copied
0093    * @stable ICU 2.0
0094    */
0095   UCharCharacterIterator(const UCharCharacterIterator&  that);
0096 
0097   /**
0098    * Destructor.
0099    * @stable ICU 2.0
0100    */
0101   virtual ~UCharCharacterIterator();
0102 
0103   /**
0104    * Assignment operator.  *this is altered to iterate over the sane
0105    * range of the same string as "that", and refers to the same
0106    * character within that string as "that" does.
0107    * @param that The object to be copied
0108    * @return the newly created object
0109    * @stable ICU 2.0
0110    */
0111   UCharCharacterIterator&
0112   operator=(const UCharCharacterIterator&    that);
0113 
0114   /**
0115    * Returns true if the iterators iterate over the same range of the
0116    * same string and are pointing at the same character.
0117    * @param that The ForwardCharacterIterator used to be compared for equality
0118    * @return true if the iterators iterate over the same range of the
0119    * same string and are pointing at the same character.
0120    * @stable ICU 2.0
0121    */
0122   virtual bool           operator==(const ForwardCharacterIterator& that) const override;
0123 
0124   /**
0125    * Generates a hash code for this iterator.
0126    * @return the hash code.
0127    * @stable ICU 2.0
0128    */
0129   virtual int32_t         hashCode(void) const override;
0130 
0131   /**
0132    * Returns a new UCharCharacterIterator referring to the same
0133    * character in the same range of the same string as this one.  The
0134    * caller must delete the new iterator.
0135    * @return the CharacterIterator newly created
0136    * @stable ICU 2.0
0137    */
0138   virtual UCharCharacterIterator* clone() const override;
0139 
0140   /**
0141    * Sets the iterator to refer to the first code unit in its
0142    * iteration range, and returns that code unit.
0143    * This can be used to begin an iteration with next().
0144    * @return the first code unit in its iteration range.
0145    * @stable ICU 2.0
0146    */
0147   virtual char16_t         first(void) override;
0148 
0149   /**
0150    * Sets the iterator to refer to the first code unit in its
0151    * iteration range, returns that code unit, and moves the position
0152    * to the second code unit. This is an alternative to setToStart()
0153    * for forward iteration with nextPostInc().
0154    * @return the first code unit in its iteration range
0155    * @stable ICU 2.0
0156    */
0157   virtual char16_t         firstPostInc(void) override;
0158 
0159   /**
0160    * Sets the iterator to refer to the first code point in its
0161    * iteration range, and returns that code unit,
0162    * This can be used to begin an iteration with next32().
0163    * Note that an iteration with next32PostInc(), beginning with,
0164    * e.g., setToStart() or firstPostInc(), is more efficient.
0165    * @return the first code point in its iteration range
0166    * @stable ICU 2.0
0167    */
0168   virtual UChar32       first32(void) override;
0169 
0170   /**
0171    * Sets the iterator to refer to the first code point in its
0172    * iteration range, returns that code point, and moves the position
0173    * to the second code point. This is an alternative to setToStart()
0174    * for forward iteration with next32PostInc().
0175    * @return the first code point in its iteration range.
0176    * @stable ICU 2.0
0177    */
0178   virtual UChar32       first32PostInc(void) override;
0179 
0180   /**
0181    * Sets the iterator to refer to the last code unit in its
0182    * iteration range, and returns that code unit.
0183    * This can be used to begin an iteration with previous().
0184    * @return the last code unit in its iteration range.
0185    * @stable ICU 2.0
0186    */
0187   virtual char16_t         last(void) override;
0188 
0189   /**
0190    * Sets the iterator to refer to the last code point in its
0191    * iteration range, and returns that code unit.
0192    * This can be used to begin an iteration with previous32().
0193    * @return the last code point in its iteration range.
0194    * @stable ICU 2.0
0195    */
0196   virtual UChar32       last32(void) override;
0197 
0198   /**
0199    * Sets the iterator to refer to the "position"-th code unit
0200    * in the text-storage object the iterator refers to, and
0201    * returns that code unit.
0202    * @param position the position within the text-storage object
0203    * @return the code unit
0204    * @stable ICU 2.0
0205    */
0206   virtual char16_t         setIndex(int32_t position) override;
0207 
0208   /**
0209    * Sets the iterator to refer to the beginning of the code point
0210    * that contains the "position"-th code unit
0211    * in the text-storage object the iterator refers to, and
0212    * returns that code point.
0213    * The current position is adjusted to the beginning of the code point
0214    * (its first code unit).
0215    * @param position the position within the text-storage object
0216    * @return the code unit
0217    * @stable ICU 2.0
0218    */
0219   virtual UChar32       setIndex32(int32_t position) override;
0220 
0221   /**
0222    * Returns the code unit the iterator currently refers to.
0223    * @return the code unit the iterator currently refers to.
0224    * @stable ICU 2.0
0225    */
0226   virtual char16_t         current(void) const override;
0227 
0228   /**
0229    * Returns the code point the iterator currently refers to.
0230    * @return the code point the iterator currently refers to.
0231    * @stable ICU 2.0
0232    */
0233   virtual UChar32       current32(void) const override;
0234 
0235   /**
0236    * Advances to the next code unit in the iteration range (toward
0237    * endIndex()), and returns that code unit.  If there are no more
0238    * code units to return, returns DONE.
0239    * @return the next code unit in the iteration range.
0240    * @stable ICU 2.0
0241    */
0242   virtual char16_t         next(void) override;
0243 
0244   /**
0245    * Gets the current code unit for returning and advances to the next code unit
0246    * in the iteration range
0247    * (toward endIndex()).  If there are
0248    * no more code units to return, returns DONE.
0249    * @return the current code unit.
0250    * @stable ICU 2.0
0251    */
0252   virtual char16_t         nextPostInc(void) override;
0253 
0254   /**
0255    * Advances to the next code point in the iteration range (toward
0256    * endIndex()), and returns that code point.  If there are no more
0257    * code points to return, returns DONE.
0258    * Note that iteration with "pre-increment" semantics is less
0259    * efficient than iteration with "post-increment" semantics
0260    * that is provided by next32PostInc().
0261    * @return the next code point in the iteration range.
0262    * @stable ICU 2.0
0263    */
0264   virtual UChar32       next32(void) override;
0265 
0266   /**
0267    * Gets the current code point for returning and advances to the next code point
0268    * in the iteration range
0269    * (toward endIndex()).  If there are
0270    * no more code points to return, returns DONE.
0271    * @return the current point.
0272    * @stable ICU 2.0
0273    */
0274   virtual UChar32       next32PostInc(void) override;
0275 
0276   /**
0277    * Returns false if there are no more code units or code points
0278    * at or after the current position in the iteration range.
0279    * This is used with nextPostInc() or next32PostInc() in forward
0280    * iteration.
0281    * @return false if there are no more code units or code points
0282    * at or after the current position in the iteration range.
0283    * @stable ICU 2.0
0284    */
0285   virtual UBool        hasNext() override;
0286 
0287   /**
0288    * Advances to the previous code unit in the iteration range (toward
0289    * startIndex()), and returns that code unit.  If there are no more
0290    * code units to return, returns DONE.
0291    * @return the previous code unit in the iteration range.
0292    * @stable ICU 2.0
0293    */
0294   virtual char16_t         previous(void) override;
0295 
0296   /**
0297    * Advances to the previous code point in the iteration range (toward
0298    * startIndex()), and returns that code point.  If there are no more
0299    * code points to return, returns DONE.
0300    * @return the previous code point in the iteration range.
0301    * @stable ICU 2.0
0302    */
0303   virtual UChar32       previous32(void) override;
0304 
0305   /**
0306    * Returns false if there are no more code units or code points
0307    * before the current position in the iteration range.
0308    * This is used with previous() or previous32() in backward
0309    * iteration.
0310    * @return false if there are no more code units or code points
0311    * before the current position in the iteration range.
0312    * @stable ICU 2.0
0313    */
0314   virtual UBool        hasPrevious() override;
0315 
0316   /**
0317    * Moves the current position relative to the start or end of the
0318    * iteration range, or relative to the current position itself.
0319    * The movement is expressed in numbers of code units forward
0320    * or backward by specifying a positive or negative delta.
0321    * @param delta the position relative to origin. A positive delta means forward;
0322    * a negative delta means backward.
0323    * @param origin Origin enumeration {kStart, kCurrent, kEnd}
0324    * @return the new position
0325    * @stable ICU 2.0
0326    */
0327   virtual int32_t      move(int32_t delta, EOrigin origin) override;
0328 
0329   /**
0330    * Moves the current position relative to the start or end of the
0331    * iteration range, or relative to the current position itself.
0332    * The movement is expressed in numbers of code points forward
0333    * or backward by specifying a positive or negative delta.
0334    * @param delta the position relative to origin. A positive delta means forward;
0335    * a negative delta means backward.
0336    * @param origin Origin enumeration {kStart, kCurrent, kEnd}
0337    * @return the new position
0338    * @stable ICU 2.0
0339    */
0340 #ifdef move32
0341    // One of the system headers right now is sometimes defining a conflicting macro we don't use
0342 #undef move32
0343 #endif
0344   virtual int32_t      move32(int32_t delta, EOrigin origin) override;
0345 
0346   /**
0347    * Sets the iterator to iterate over a new range of text
0348    * @stable ICU 2.0
0349    */
0350   void setText(ConstChar16Ptr newText, int32_t newTextLength);
0351 
0352   /**
0353    * Copies the char16_t array under iteration into the UnicodeString
0354    * referred to by "result".  Even if this iterator iterates across
0355    * only a part of this string, the whole string is copied.
0356    * @param result Receives a copy of the text under iteration.
0357    * @stable ICU 2.0
0358    */
0359   virtual void            getText(UnicodeString& result) override;
0360 
0361   /**
0362    * Return a class ID for this class (not really public)
0363    * @return a class ID for this class
0364    * @stable ICU 2.0
0365    */
0366   static UClassID         U_EXPORT2 getStaticClassID(void);
0367 
0368   /**
0369    * Return a class ID for this object (not really public)
0370    * @return a class ID for this object.
0371    * @stable ICU 2.0
0372    */
0373   virtual UClassID        getDynamicClassID(void) const override;
0374 
0375 protected:
0376   /**
0377    * Protected constructor
0378    * @stable ICU 2.0
0379    */
0380   UCharCharacterIterator();
0381   /**
0382    * Protected member text
0383    * @stable ICU 2.0
0384    */
0385   const char16_t*            text;
0386 
0387 };
0388 
0389 U_NAMESPACE_END
0390 
0391 #endif /* U_SHOW_CPLUSPLUS_API */
0392 
0393 #endif