home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / simtxbd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  6.8 KB  |  204 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999               *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. *
  13. * File SIMTXBD.H
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   02/18/97    aliu        Converted from OpenClass.  Changed text() to getText() and
  19. *                           made return type const &.
  20. *   08/11/98    helena      Sync-up JDK1.2.
  21. *****************************************************************************************
  22. */
  23.  
  24. #ifndef SIMTXBD_H
  25. #define SIMTXBD_H
  26.  
  27.  
  28. #include "utypes.h"
  29. #include "unistr.h"
  30. #include "chariter.h"
  31. #include "brkiter.h"
  32. #include "txtbdat.h"
  33.  
  34.  
  35. /**
  36.  * SIMPLETEXTBOUNDARY is a concrete implementation of BreakIterator.
  37.  * SimpleTextBoundary uses a state machine to compute breaks.
  38.  * <P>
  39.  * Different state machines are available that compute breaks for
  40.  * sentences, words, lines, and characters.  They are accessable
  41.  * through static functions of BreakIterator.
  42.  */
  43. class SimpleTextBoundary: public BreakIterator {
  44. public:
  45.     /**
  46.      * Destructor.
  47.      */
  48.     virtual ~SimpleTextBoundary();
  49.  
  50.     /**
  51.      * Return true if another object is semantically equal to this
  52.      * one. The other object should be an instance of a subclass of
  53.      * TextBoundary. Objects of different subclasses are considered
  54.      * unequal.
  55.      * <P>
  56.      * Return true if this BreakIterator is at the same position in the
  57.      * same text, and is the same class and type (word, line, etc.) of
  58.      * BreakIterator, as the argument.  Text is considered the same if
  59.      * it contains the same characters, it need not be the same
  60.      * object, and styles are not considered.
  61.      */
  62.     virtual bool_t operator==(const BreakIterator&) const;
  63.  
  64.     /**
  65.      * Return a polymorphic copy of this object.  This is an abstract
  66.      * method which subclasses implement.
  67.      */
  68.     BreakIterator* clone(void) const;
  69.  
  70.     /**
  71.      * Return a polymorphic class ID for this object. Different subclasses
  72.      * will return distinct unequal values.
  73.      */
  74.     virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); }
  75.  
  76.     /**
  77.      * Return a static class ID for this class.
  78.      */
  79.     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
  80.  
  81.     /**
  82.      * Return the text iterator over which this operates.
  83.      * @return the caller of this method owns the returned object.
  84.      */
  85.     virtual CharacterIterator* createText(void) const;
  86.  
  87.     /**
  88.      * Change the text over which this operates. The text boundary is
  89.      * reset to the start.
  90.      */
  91.     virtual void  setText(const UnicodeString* it);
  92.  
  93.     /**
  94.      * Change the text over which this operates. The text boundary is
  95.      * reset to the start.
  96.      */
  97.     virtual void  adoptText(CharacterIterator* it);
  98.  
  99.     /**
  100.      * Return the index of the first character in the text being scanned.
  101.      */
  102.     virtual UTextOffset first(void);
  103.  
  104.     /**
  105.      * Return the index of the last character in the text being scanned.
  106.      */
  107.     virtual UTextOffset last(void);
  108.  
  109.     /**
  110.      * Return the character index of the previous text boundary, or kDone if all
  111.      * boundaries have been returned.
  112.      */
  113.     virtual UTextOffset previous(void);
  114.  
  115.     /**
  116.      * Return the character index of the next text boundary, or kDone if all
  117.      * boundaries have been returned.
  118.      */
  119.     virtual UTextOffset next(void);
  120.  
  121.     /**
  122.      * Return the character index of the text boundary that was most recently
  123.      * returned by next(), previous(), first(), or last().
  124.      */
  125.     virtual UTextOffset current(void) const;
  126.  
  127.     /**
  128.      * Return the first boundary following the specified offset.
  129.      * The value returned is always greater than the offset, or is kDone.
  130.      * @param offset the offset to begin scanning.
  131.      * @return The first boundary after the specified offset.
  132.      */
  133.     virtual UTextOffset following(UTextOffset offset);
  134.  
  135.     /**
  136.      * Return the first boundary preceding the specified offset.
  137.      * The value returned is always smaller than the offset, or is kDone.
  138.      * @param offset the offset to begin scanning.
  139.      * @return The first boundary before the specified offset.
  140.      */
  141.     virtual UTextOffset preceding(UTextOffset offset);
  142.  
  143.     /**
  144.      * Return true if the specfied position is a boundary position.
  145.      * @param offset the offset to check.
  146.      * @return True if "offset" is a boundary position.
  147.      */
  148.     virtual bool_t isBoundary(UTextOffset offset);
  149.  
  150.     /**
  151.      * Return the nth boundary from the current boundary.
  152.      * @param n the signed number of boundaries to traverse.
  153.      * Negative values move to previous boundaries
  154.      * and positive values move to later boundaries. A value of 0 does nothing.
  155.      * @return The character index of the nth boundary from the current position.
  156.      */
  157.     virtual UTextOffset next(int32_t n);
  158.  
  159. private:
  160.     /**
  161.      * Construct an SimpleTextBoundary from the provided state table.
  162.      * This protected constructor is called from the friend class
  163.      * BreakIterator.
  164.      */
  165.     SimpleTextBoundary(const TextBoundaryData* data);
  166.  
  167.     /**
  168.      * Copy constructor.
  169.      */
  170.     SimpleTextBoundary(const SimpleTextBoundary&); // only used by clone
  171.  
  172.     /**
  173.      * The assignment operator is required to satisfy the compiler, but never called.
  174.      */
  175.     SimpleTextBoundary operator=(const SimpleTextBoundary&) { return *this; } // do not call
  176.  
  177.     /**
  178.      * Internal utility used to locate the previous position from which it is safe
  179.      * to do a forward scan (state is known).
  180.      */
  181.     UTextOffset previousSafePosition(UTextOffset offset);
  182.  
  183.     /**
  184.      * Internal utility to get the next position.
  185.      */
  186.     UTextOffset nextPosition(UTextOffset offset);
  187.  
  188.     static char fgClassID;
  189.     static const UChar kEND_OF_STRING;
  190.  
  191.     const TextBoundaryData*     fData;
  192.     const WordBreakTable*       fForward;   // fData->forward()
  193.     const WordBreakTable*       fBackward;  // fData->backward()
  194.     const UnicodeClassMapping*  fMap;       // fData->map()
  195.     CharacterIterator*          fText;
  196.     UTextOffset                  fPos;
  197.  
  198.     /* Making BreakIterator a friend is somewhat messy. */
  199.     friend class BreakIterator;
  200. };
  201.  
  202. #endif // _SIMTXBD
  203. //eof
  204.