home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / compitr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  5.4 KB  |  135 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   IBM Open Class Library                                                    *
  6. *   (C) Copyright Taligent, Inc.,  1996                                       *
  7. *   (C) Copyright International Business Machines Corporation,  1996-1998     *
  8. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  9. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  10. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  11. *                                                                             *
  12. *******************************************************************************
  13. */
  14.  
  15. #ifndef COMPITR_H
  16. #define COMPITR_H
  17.  
  18.  
  19. #include "utypes.h"
  20. #include "unistr.h"
  21.  
  22.  
  23. /**
  24.  * <tt>ComposedCharIter</tt> is an iterator class that returns all
  25.  * of the precomposed characters defined in the Unicode standard, along
  26.  * with their decomposed forms.  This is often useful when building
  27.  * data tables (<i>e.g.</i> collation tables) which need to treat composed
  28.  * and decomposed characters equivalently.
  29.  * <p>
  30.  * For example, imagine that you have built a collation table with ordering
  31.  * rules for the {@link Normalizer#DECOMP canonically decomposed} forms of all
  32.  * characters used in a particular language.  When you process input text using
  33.  * this table, the text must first be decomposed so that it matches the form
  34.  * used in the table.  This can impose a performance penalty that may be
  35.  * unacceptable in some situations.
  36.  * <p>
  37.  * You can avoid this problem by ensuring that the collation table contains
  38.  * rules for both the decomposed <i>and</i> composed versions of each character.
  39.  * To do so, use a <tt>ComposedCharIter</tt> to iterate through all of the
  40.  * composed characters in Unicode.  If the decomposition for that character
  41.  * consists solely of characters that are listed in your ruleset, you can
  42.  * add a new rule for the composed character that makes it equivalent to
  43.  * its decomposition sequence.
  44.  * <p>
  45.  * Note that <tt>ComposedCharIter</tt> iterates over a <em>static</em> table
  46.  * of the composed characters in Unicode.  If you want to iterate over the
  47.  * composed characters in a particular string, use {@link Normalizer} instead.
  48.  * <p>
  49.  * When constructing a <tt>ComposedCharIter</tt> there is one
  50.  * optional feature that you can enable or disable:
  51.  * <ul>
  52.  *   <li>{@link Normalizer#IGNORE_HANGUL} - Do not iterate over the Hangul
  53.  *          characters and their corresponding Jamo decompositions.
  54.  *          This option is off by default (<i>i.e.</i> Hangul processing is enabled)
  55.  *          since the Unicode standard specifies that Hangul to Jamo 
  56.  *          is a canonical decomposition.
  57.  * </ul>
  58.  * <p>
  59.  * <tt>ComposedCharIter</tt> is currently based on version 2.1.8 of the
  60.  * <a href="http://www.unicode.org" target="unicode">Unicode Standard</a>.
  61.  * It will be updated as later versions of Unicode are released.
  62.  */
  63. class U_COMMON_API ComposedCharIter 
  64. {
  65.  public:
  66.   /**
  67.    * Constant that indicates the iteration has completed.
  68.    * {@link #next} returns this value when there are no more composed
  69.    * characters over which to iterate.
  70.    */
  71.   static const UChar    DONE;
  72.     
  73.   /**
  74.    * Construct a new <tt>ComposedCharIter</tt>.  The iterator will return
  75.    * all Unicode characters with canonical decompositions, including Korean
  76.    * Hangul characters.
  77.    */
  78.   ComposedCharIter();
  79.     
  80.   
  81.   /**
  82.    * Constructs a non-default <tt>ComposedCharIter</tt> with optional behavior.
  83.    * <p>
  84.    * @param compat    <tt>false</tt> for canonical decompositions only;
  85.    *                  <tt>true</tt> for both canonical and compatibility
  86.    *                  decompositions.
  87.    *
  88.    * @param options   Optional decomposition features.  Currently, the only
  89.    *                  supported option is {@link Normalizer#IGNORE_HANGUL}, which
  90.    *                  causes this <tt>ComposedCharIter</tt> not to iterate
  91.    *                  over the Hangul characters and their corresponding
  92.    *                  Jamo decompositions.
  93.    */
  94.   ComposedCharIter(bool_t compat, int32_t options);
  95.   
  96.   /**
  97.    * Determines whether there any precomposed Unicode characters not yet returned
  98.    * by {@link #next}.
  99.    */
  100.   bool_t hasNext(void) const;
  101.   
  102.   /**
  103.    * Returns the next precomposed Unicode character.
  104.    * Repeated calls to <tt>next</tt> return all of the precomposed characters defined
  105.    * by Unicode, in ascending order.  After all precomposed characters have
  106.    * been returned, {@link #hasNext} will return <tt>false</tt> and further calls
  107.    * to <tt>next</tt> will return {@link #DONE}.
  108.    */
  109.   UChar next(void);
  110.   
  111.   /**
  112.    * Returns the Unicode decomposition of the current character.
  113.    * This method returns the decomposition of the precomposed character most
  114.    * recently returned by {@link #next}.  The resulting decomposition is
  115.    * affected by the settings of the options passed to the constructor.
  116.    * {@link Normalizer#COMPATIBILITY COMPATIBILITY}
  117.    * and {@link Normalizer#NO_HANGUL NO_HANGUL} options passed to the constructor.
  118.    */
  119.   void getDecomposition(UnicodeString& result) const;
  120.   
  121.  private:
  122.   void    findNextChar(void);
  123.   
  124.   int32_t    minDecomp;
  125.   bool_t    hangul;
  126.   
  127.   UChar    curChar;
  128.   UChar    nextChar;
  129. };
  130.  
  131. #endif // _COMPITR
  132.  
  133.  
  134.  
  135.