ICU 69.1  69.1
chariter.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************
5 *
6 * Copyright (C) 1997-2011, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 ********************************************************************
10 */
11 
12 #ifndef CHARITER_H
13 #define CHARITER_H
14 
15 #include "unicode/utypes.h"
16 
17 #if U_SHOW_CPLUSPLUS_API
18 
19 #include "unicode/uobject.h"
20 #include "unicode/unistr.h"
26 U_NAMESPACE_BEGIN
95 public:
101  enum { DONE = 0xffff };
102 
108 
117  virtual UBool operator==(const ForwardCharacterIterator& that) const = 0;
118 
129  inline UBool operator!=(const ForwardCharacterIterator& that) const;
130 
136  virtual int32_t hashCode(void) const = 0;
137 
145  virtual UClassID getDynamicClassID(void) const = 0;
146 
155  virtual char16_t nextPostInc(void) = 0;
156 
165  virtual UChar32 next32PostInc(void) = 0;
166 
176  virtual UBool hasNext() = 0;
177 
178 protected:
181 
184 
190 };
191 
362 public:
367  enum EOrigin { kStart, kCurrent, kEnd };
368 
374 
383  virtual CharacterIterator* clone() const = 0;
384 
392  virtual char16_t first(void) = 0;
393 
402  virtual char16_t firstPostInc(void);
403 
413  virtual UChar32 first32(void) = 0;
414 
423  virtual UChar32 first32PostInc(void);
424 
432  inline int32_t setToStart();
433 
441  virtual char16_t last(void) = 0;
442 
450  virtual UChar32 last32(void) = 0;
451 
459  inline int32_t setToEnd();
460 
469  virtual char16_t setIndex(int32_t position) = 0;
470 
482  virtual UChar32 setIndex32(int32_t position) = 0;
483 
489  virtual char16_t current(void) const = 0;
490 
496  virtual UChar32 current32(void) const = 0;
497 
505  virtual char16_t next(void) = 0;
506 
517  virtual UChar32 next32(void) = 0;
518 
526  virtual char16_t previous(void) = 0;
527 
535  virtual UChar32 previous32(void) = 0;
536 
546  virtual UBool hasPrevious() = 0;
547 
558  inline int32_t startIndex(void) const;
559 
569  inline int32_t endIndex(void) const;
570 
579  inline int32_t getIndex(void) const;
580 
587  inline int32_t getLength() const;
588 
600  virtual int32_t move(int32_t delta, EOrigin origin) = 0;
601 
613 #ifdef move32
614  // One of the system headers right now is sometimes defining a conflicting macro we don't use
615 #undef move32
616 #endif
617  virtual int32_t move32(int32_t delta, EOrigin origin) = 0;
618 
625  virtual void getText(UnicodeString& result) = 0;
626 
627 protected:
633 
638  CharacterIterator(int32_t length);
639 
644  CharacterIterator(int32_t length, int32_t position);
645 
650  CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position);
651 
659 
668 
674  int32_t textLength;
675 
680  int32_t pos;
681 
686  int32_t begin;
687 
692  int32_t end;
693 };
694 
695 inline UBool
697  return !operator==(that);
698 }
699 
700 inline int32_t
701 CharacterIterator::setToStart() {
702  return move(0, kStart);
703 }
704 
705 inline int32_t
706 CharacterIterator::setToEnd() {
707  return move(0, kEnd);
708 }
709 
710 inline int32_t
711 CharacterIterator::startIndex(void) const {
712  return begin;
713 }
714 
715 inline int32_t
716 CharacterIterator::endIndex(void) const {
717  return end;
718 }
719 
720 inline int32_t
721 CharacterIterator::getIndex(void) const {
722  return pos;
723 }
724 
725 inline int32_t
726 CharacterIterator::getLength(void) const {
727  return textLength;
728 }
729 
730 U_NAMESPACE_END
731 
732 #endif /* U_SHOW_CPLUSPLUS_API */
733 
734 #endif
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
EOrigin
Origin enumeration for the move() and move32() functions.
Definition: chariter.h:367
int32_t textLength
Base class text length field.
Definition: chariter.h:674
virtual UChar32 first32PostInc(void)
Sets the iterator to refer to the first code point in its iteration range, returns that code point,...
CharacterIterator(int32_t length, int32_t position)
Constructor, just setting the length and position fields in this base class.
virtual char16_t first(void)=0
Sets the iterator to refer to the first code unit in its iteration range, and returns that code unit.
virtual void getText(UnicodeString &result)=0
Copies the text under iteration into the UnicodeString referred to by "result".
virtual int32_t move(int32_t delta, EOrigin origin)=0
Moves the current position relative to the start or end of the iteration range, or relative to the cu...
virtual char16_t current(void) const =0
Returns the code unit the iterator currently refers to.
virtual UChar32 next32(void)=0
Advances to the next code point in the iteration range (toward endIndex()), and returns that code poi...
virtual ~CharacterIterator()
Destructor.
virtual char16_t firstPostInc(void)
Sets the iterator to refer to the first code unit in its iteration range, returns that code unit,...
virtual UChar32 setIndex32(int32_t position)=0
Sets the iterator to refer to the beginning of the code point that contains the "position"-th code un...
virtual UChar32 last32(void)=0
Sets the iterator to refer to the last code point in its iteration range, and returns that code unit.
virtual char16_t previous(void)=0
Advances to the previous code unit in the iteration range (toward startIndex()), and returns that cod...
virtual char16_t next(void)=0
Advances to the next code unit in the iteration range (toward endIndex()), and returns that code unit...
virtual UChar32 first32(void)=0
Sets the iterator to refer to the first code point in its iteration range, and returns that code unit...
int32_t begin
Base class field for the start of the iteration range.
Definition: chariter.h:686
CharacterIterator(int32_t length)
Constructor, just setting the length field in this base class.
virtual UChar32 current32(void) const =0
Returns the code point the iterator currently refers to.
virtual CharacterIterator * clone() const =0
Returns a pointer to a new CharacterIterator of the same concrete class as this one,...
int32_t pos
Base class field for the current position.
Definition: chariter.h:680
int32_t end
Base class field for the end of the iteration range.
Definition: chariter.h:692
virtual UChar32 previous32(void)=0
Advances to the previous code point in the iteration range (toward startIndex()), and returns that co...
virtual int32_t move32(int32_t delta, EOrigin origin)=0
Moves the current position relative to the start or end of the iteration range, or relative to the cu...
CharacterIterator(const CharacterIterator &that)
Copy constructor.
virtual UBool hasPrevious()=0
Returns false if there are no more code units or code points before the current position in the itera...
virtual char16_t setIndex(int32_t position)=0
Sets the iterator to refer to the "position"-th code unit in the text-storage object the iterator ref...
CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position)
Constructor, just setting the length, start, end, and position fields in this base class.
virtual char16_t last(void)=0
Sets the iterator to refer to the last code unit in its iteration range, and returns that code unit.
CharacterIterator()
Empty constructor.
CharacterIterator & operator=(const CharacterIterator &that)
Assignment operator.
Abstract class that defines an API for forward-only iteration on text objects.
Definition: chariter.h:94
virtual ~ForwardCharacterIterator()
Destructor.
virtual UBool operator==(const ForwardCharacterIterator &that) const =0
Returns true when both iterators refer to the same character in the same character-storage object.
virtual UClassID getDynamicClassID(void) const =0
Returns a UClassID for this ForwardCharacterIterator ("poor man's RTTI").
ForwardCharacterIterator & operator=(const ForwardCharacterIterator &)
Assignment operator to be overridden in the implementing class.
Definition: chariter.h:189
ForwardCharacterIterator(const ForwardCharacterIterator &other)
Copy constructor to be overridden in the implementing class.
ForwardCharacterIterator()
Default constructor to be overridden in the implementing class.
virtual int32_t hashCode(void) const =0
Generates a hash code for this iterator.
virtual UBool hasNext()=0
Returns false if there are no more code units or code points at or after the current position in the ...
virtual char16_t nextPostInc(void)=0
Gets the current code unit for returning and advances to the next code unit in the iteration range (t...
virtual UChar32 next32PostInc(void)=0
Gets the current code point for returning and advances to the next code point in the iteration range ...
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:467
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300