home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / include / normlzr.h < prev    next >
C/C++ Source or Header  |  1999-11-12  |  27KB  |  703 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-1999     *
  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 NORMLZR_H
  16. #define NORMLZR_H
  17.  
  18. #include "utypes.h"
  19. #include "unistr.h"
  20. #include "chariter.h"
  21.  
  22. /**
  23.  * <tt>Normalizer</tt> transforms Unicode text into an equivalent composed or
  24.  * decomposed form, allowing for easier sorting and searching of text.
  25.  * <tt>Normalizer</tt> supports the standard normalization forms described in
  26.  * <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
  27.  * Unicode Technical Report #15</a>.
  28.  * <p>
  29.  * Characters with accents or other adornments can be encoded in
  30.  * several different ways in Unicode.  For example, take the character "Á"
  31.  * (A-acute).   In Unicode, this can be encoded as a single character (the
  32.  * "composed" form):
  33.  * <pre>
  34.  *      00C1    LATIN CAPITAL LETTER A WITH ACUTE</pre>
  35.  * or as two separate characters (the "decomposed" form):
  36.  * <pre>
  37.  *      0041    LATIN CAPITAL LETTER A
  38.  *      0301    COMBINING ACUTE ACCENT</pre>
  39.  * <p>
  40.  * To a user of your program, however, both of these sequences should be
  41.  * treated as the same "user-level" character "Á".  When you are searching or
  42.  * comparing text, you must ensure that these two sequences are treated 
  43.  * equivalently.  In addition, you must handle characters with more than one
  44.  * accent.  Sometimes the order of a character's combining accents is
  45.  * significant, while in other cases accent sequences in different orders are
  46.  * really equivalent.
  47.  * <p>
  48.  * Similarly, the string "ffi" can be encoded as three separate letters:
  49.  * <pre>
  50.  *      0066    LATIN SMALL LETTER F
  51.  *      0066    LATIN SMALL LETTER F
  52.  *      0069    LATIN SMALL LETTER I</pre>
  53.  * or as the single character
  54.  * <pre>
  55.  *      FB03    LATIN SMALL LIGATURE FFI</pre>
  56.  * <p>
  57.  * The ffi ligature is not a distinct semantic character, and strictly speaking
  58.  * it shouldn't be in Unicode at all, but it was included for compatibility
  59.  * with existing character sets that already provided it.  The Unicode standard
  60.  * identifies such characters by giving them "compatibility" decompositions
  61.  * into the corresponding semantic characters.  When sorting and searching, you
  62.  * will often want to use these mappings.
  63.  * <p>
  64.  * <tt>Normalizer</tt> helps solve these problems by transforming text into the
  65.  * canonical composed and decomposed forms as shown in the first example above.  
  66.  * In addition, you can have it perform compatibility decompositions so that 
  67.  * you can treat compatibility characters the same as their equivalents.
  68.  * Finally, <tt>Normalizer</tt> rearranges accents into the proper canonical
  69.  * order, so that you do not have to worry about accent rearrangement on your
  70.  * own.
  71.  * <p>
  72.  * <tt>Normalizer</tt> adds one optional behavior, {@link #IGNORE_HANGUL},
  73.  * that differs from
  74.  * the standard Unicode Normalization Forms.  This option can be passed
  75.  * to the {@link #Normalizer constructors} and to the static
  76.  * {@link #compose compose} and {@link #decompose decompose} methods.  This
  77.  * option, and any that are added in the future, will be turned off by default.
  78.  * <p>
  79.  * There are three common usage models for <tt>Normalizer</tt>.  In the first,
  80.  * the static {@link #normalize normalize()} method is used to process an
  81.  * entire input string at once.  Second, you can create a <tt>Normalizer</tt>
  82.  * object and use it to iterate through the normalized form of a string by
  83.  * calling {@link #first} and {@link #next}.  Finally, you can use the
  84.  * {@link #setIndex setIndex()} and {@link #getIndex} methods to perform
  85.  * random-access iteration, which is very useful for searching.
  86.  * <p>
  87.  * <b>Note:</b> <tt>Normalizer</tt> objects behave like iterators and have
  88.  * methods such as <tt>setIndex</tt>, <tt>next</tt>, <tt>previous</tt>, etc.
  89.  * You should note that while the <tt>setIndex</tt> and <tt>getIndex</tt> refer
  90.  * to indices in the underlying <em>input</em> text being processed, the
  91.  * <tt>next</tt> and <tt>previous</tt> methods it iterate through characters
  92.  * in the normalized <em>output</em>.  This means that there is not
  93.  * necessarily a one-to-one correspondence between characters returned
  94.  * by <tt>next</tt> and <tt>previous</tt> and the indices passed to and
  95.  * returned from <tt>setIndex</tt> and <tt>getIndex</tt>.  It is for this
  96.  * reason that <tt>Normalizer</tt> does not implement the
  97.  * {@link CharacterIterator} interface.
  98.  * <p>
  99.  * <b>Note:</b> <tt>Normalizer</tt> is currently based on version 2.1.8
  100.  * of the <a href="http://www.unicode.org" target="unicode">Unicode Standard</a>.
  101.  * It will be updated as later versions of Unicode are released.  If you are
  102.  * using this class on a JDK that supports an earlier version of Unicode, it
  103.  * is possible that <tt>Normalizer</tt> may generate composed or dedecomposed
  104.  * characters for which your JDK's {@link java.lang.Character} class does not
  105.  * have any data.
  106.  * <p>
  107.  * @author Laura Werner, Mark Davis
  108.  */
  109. class U_COMMON_API Normalizer
  110. {
  111.  
  112.  public:
  113.   // This tells us what the bits in the "mode" mean.
  114.   enum {
  115.     COMPAT_BIT         = 1,
  116.     DECOMP_BIT         = 2,
  117.     COMPOSE_BIT     = 4
  118.   };
  119.  
  120.  
  121.  
  122.   /** */
  123.   static const UChar DONE;
  124.   
  125.   /** The mode of a Normalizer object */
  126.   enum EMode {
  127.  
  128.     /**
  129.      * Null operation for use with the {@link #Normalizer constructors}
  130.      * and the static {@link #normalize normalize} method.  This value tells
  131.      * the <tt>Normalizer</tt> to do nothing but return unprocessed characters
  132.      * from the underlying String or CharacterIterator.  If you have code which
  133.      * requires raw text at some times and normalized text at others, you can
  134.      * use <tt>NO_OP</tt> for the cases where you want raw text, rather
  135.      * than having a separate code path that bypasses <tt>Normalizer</tt>
  136.      * altogether.
  137.      * <p>
  138.      * @see #setMode
  139.      */
  140.     NO_OP         = 0,
  141.     
  142.     /**
  143.      * Canonical decomposition followed by canonical composition.  Used with 
  144.      * the {@link #Normalizer constructors} and the static 
  145.      * {@link #normalize normalize}
  146.      * method to determine the operation to be performed.
  147.      * <p>
  148.      * If all optional features (<i>e.g.</i> {@link #IGNORE_HANGUL}) are turned
  149.      * off, this operation produces output that is in
  150.      * <a href=http://www.unicode.org/unicode/reports/tr15/>Unicode Canonical
  151.      * Form</a>
  152.      * <b>C</b>.
  153.      * <p>
  154.      * @see #setMode
  155.      */
  156.     COMPOSE         = COMPOSE_BIT,
  157.     
  158.     /**
  159.      * Compatibility decomposition followed by canonical composition.
  160.      * Used with the {@link #Normalizer constructors} and the static
  161.      * {@link #normalize normalize} method to determine the operation to be
  162.      * performed.
  163.      * <p>
  164.      * If all optional features (<i>e.g.</i> {@link #IGNORE_HANGUL}) are turned
  165.      * off, this operation produces output that is in
  166.      * <a href=http://www.unicode.org/unicode/reports/tr15/>Unicode Canonical
  167.      * Form</a>
  168.      * <b>KC</b>.
  169.      * <p>
  170.      * @see #setMode
  171.      */
  172.     COMPOSE_COMPAT     = COMPOSE_BIT | COMPAT_BIT,
  173.     
  174.     /**
  175.      * Canonical decomposition.  This value is passed to the
  176.      * {@link #Normalizer constructors} and the static 
  177.      * {@link #normalize normalize}
  178.      * method to determine the operation to be performed.
  179.      * <p>
  180.      * If all optional features (<i>e.g.</i> {@link #IGNORE_HANGUL}) are turned
  181.      * off, this operation produces output that is in
  182.      * <a href=http://www.unicode.org/unicode/reports/tr15/>Unicode Canonical 
  183.      * Form</a>
  184.      * <b>D</b>.
  185.      * <p>
  186.      * @see #setMode
  187.      */
  188.     DECOMP         = DECOMP_BIT,
  189.     
  190.     /**
  191.      * Compatibility decomposition.  This value is passed to the
  192.      * {@link #Normalizer constructors} and the static 
  193.      * {@link #normalize normalize}
  194.      * method to determine the operation to be performed.
  195.      * <p>
  196.      * If all optional features (<i>e.g.</i> {@link #IGNORE_HANGUL}) are turned
  197.      * off, this operation produces output that is in
  198.      * <a href=http://www.unicode.org/unicode/reports/tr15/>Unicode Canonical 
  199.      * Form</a>
  200.      * <b>KD</b>.
  201.      * <p>
  202.      * @see #setMode
  203.      */
  204.     DECOMP_COMPAT     = DECOMP_BIT | COMPAT_BIT
  205.   };
  206.  
  207.   /** The options for a Normalizer object */
  208.   enum {
  209.  
  210.     /**
  211.      * Option to disable Hangul/Jamo composition and decomposition.
  212.      * This option applies to Korean text, 
  213.      * which can be represented either in the Jamo alphabet or in Hangul
  214.      * characters, which are really just two or three Jamo combined
  215.      * into one visual glyph.  Since Jamo takes up more storage space than
  216.      * Hangul, applications that process only Hangul text may wish to turn
  217.      * this option on when decomposing text.
  218.      * <p>
  219.      * The Unicode standard treates Hangul to Jamo conversion as a 
  220.      * canonical decomposition, so this option must be turned <b>off</b> if you
  221.      * wish to transform strings into one of the standard
  222.      * <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
  223.      * Unicode Normalization Forms</a>.
  224.      * <p>
  225.      * @see #setOption
  226.      */
  227.     IGNORE_HANGUL     = 0x001
  228.   };
  229.  
  230.   // Constructors
  231.   
  232.   /**
  233.    * Creates a new <tt>Normalizer</tt> object for iterating over the
  234.    * normalized form of a given string.
  235.    * <p>
  236.    * @param str   The string to be normalized.  The normalization
  237.    *              will start at the beginning of the string.
  238.    *
  239.    * @param mode  The normalization mode.
  240.    */
  241.   Normalizer(const UnicodeString& str, 
  242.          EMode mode);
  243.     
  244.   /**
  245.    * Creates a new <tt>Normalizer</tt> object for iterating over the
  246.    * normalized form of a given string.
  247.    * <p>
  248.    * The <tt>options</tt> parameter specifies which optional
  249.    * <tt>Normalizer</tt> features are to be enabled for this object.
  250.    * <p>
  251.    * @param str   The string to be normalized.  The normalization
  252.    *              will start at the beginning of the string.
  253.    *
  254.    * @param mode  The normalization mode.
  255.    *
  256.    * @param opt   Any optional features to be enabled.
  257.    *              Currently the only available option is {@link #IGNORE_HANGUL}
  258.    *              If you want the default behavior corresponding to one of the
  259.    *              standard Unicode Normalization Forms, use 0 for this argument
  260.    */
  261.   Normalizer(const UnicodeString& str, 
  262.          EMode mode, 
  263.          int32_t opt);
  264.   
  265.   /**
  266.    * Creates a new <tt>Normalizer</tt> object for iterating over the
  267.    * normalized form of the given text.
  268.    * <p>
  269.    * @param iter  The input text to be normalized.  The normalization
  270.    *              will start at the beginning of the string.
  271.    *
  272.    * @param mode  The normalization mode.
  273.    *
  274.    */
  275.   Normalizer(const CharacterIterator& iter, 
  276.          EMode mode);
  277.   
  278.   /**
  279.    * Creates a new <tt>Normalizer</tt> object for iterating over the
  280.    * normalized form of the given text.
  281.    * <p>
  282.    * @param iter  The input text to be normalized.  The normalization
  283.    *              will start at the beginning of the string.
  284.    *
  285.    * @param mode  The normalization mode.
  286.    *
  287.    * @param opt   Any optional features to be enabled.
  288.    *              Currently the only available option is {@link #IGNORE_HANGUL}
  289.    *              If you want the default behavior corresponding to one of the
  290.    *              standard Unicode Normalization Forms, use 0 for this argument
  291.    */
  292.   Normalizer(const CharacterIterator& iter, 
  293.          EMode mode, 
  294.          int32_t opt);
  295.   
  296.   /**
  297.    * Copy constructor.
  298.    */
  299.   Normalizer(const Normalizer& copy);
  300.   
  301.   /**
  302.    * Destructor
  303.    */
  304.   ~Normalizer();
  305.   
  306.   
  307.   //-------------------------------------------------------------------------
  308.   // Static utility methods
  309.   //-------------------------------------------------------------------------
  310.   
  311.   /**
  312.    * Normalizes a <tt>String</tt> using the given normalization operation.
  313.    * <p>
  314.    * The <tt>options</tt> parameter specifies which optional
  315.    * <tt>Normalizer</tt> features are to be enabled for this operation.
  316.    * Currently the only available option is {@link #IGNORE_HANGUL}.
  317.    * If you want the default behavior corresponding to one of the standard
  318.    * Unicode Normalization Forms, use 0 for this argument.
  319.    * <p>
  320.    * @param source    the input string to be normalized.
  321.    *
  322.    * @param aMode     the normalization mode
  323.    *
  324.    * @param options   the optional features to be enabled.
  325.    *
  326.    * @param result    The normalized string (on output).
  327.    *
  328.    * @param status    The error code.
  329.    */
  330.   static void normalize(const UnicodeString& source, 
  331.             EMode mode, 
  332.             int32_t options,
  333.             UnicodeString& result, 
  334.             UErrorCode &status);
  335.   
  336.   /**
  337.    * Compose a <tt>String</tt>.
  338.    * <p>
  339.    * The <tt>options</tt> parameter specifies which optional
  340.    * <tt>Normalizer</tt> features are to be enabled for this operation.
  341.    * Currently the only available option is {@link #IGNORE_HANGUL}.
  342.    * If you want the default behavior corresponding
  343.    * to Unicode Normalization Form <b>C</b> or <b>KC</b>,
  344.    * use 0 for this argument.
  345.    * <p>
  346.    * @param source    the string to be composed.
  347.    *
  348.    * @param compat    Perform compatibility decomposition before composition.
  349.    *                  If this argument is <tt>false</tt>, only canonical
  350.    *                  decomposition will be performed.
  351.    *
  352.    * @param options   the optional features to be enabled.
  353.    *
  354.    * @param result    The composed string (on output).
  355.    *
  356.    * @param status    The error code.
  357.    */
  358.   static void compose(const UnicodeString& source, 
  359.               bool_t compat,
  360.               int32_t options,
  361.               UnicodeString& result, 
  362.               UErrorCode &status);
  363.   
  364.   /**
  365.    * Static method to decompose a <tt>String</tt>.
  366.    * <p>
  367.    * The <tt>options</tt> parameter specifies which optional
  368.    * <tt>Normalizer</tt> features are to be enabled for this operation.
  369.    * Currently the only available option is {@link #IGNORE_HANGUL}.
  370.    * The desired options should be OR'ed together to determine the value
  371.    * of this argument.  If you want the default behavior corresponding
  372.    * to Unicode Normalization Form <b>D</b> or <b>KD</b>,
  373.    * use 0 for this argument.
  374.    * <p>
  375.    * @param str   the string to be decomposed.
  376.    *
  377.    * @param compat    Perform compatibility decomposition.
  378.    *                  If this argument is <tt>false</tt>, only canonical
  379.    *                  decomposition will be performed.
  380.    *
  381.    * @param options   the optional features to be enabled.
  382.    *
  383.    * @param result    The composed string (on output).
  384.    *
  385.    * @param status    The error code.
  386.    *
  387.    * @return      the decomposed string.
  388.    */
  389.   static void decompose(const UnicodeString& source, 
  390.             bool_t compat,
  391.             int32_t options,
  392.             UnicodeString& result, 
  393.             UErrorCode &status);
  394.  
  395.  
  396.   //-------------------------------------------------------------------------
  397.   // CharacterIterator overrides
  398.   //-------------------------------------------------------------------------
  399.   
  400.   /**
  401.    * Return the current character in the normalized text.
  402.    */
  403.   UChar                current(void) const;
  404.   
  405.   /**
  406.    * Return the first character in the normalized text.  This resets
  407.    * the <tt>Normalizer's</tt> position to the beginning of the text.
  408.    */
  409.   UChar                first(void);
  410.  
  411.   /**
  412.    * Return the last character in the normalized text.  This resets
  413.    * the <tt>Normalizer's</tt> position to be just before the
  414.    * the input text corresponding to that normalized character.
  415.    */
  416.   UChar                last(void);
  417.   
  418.   /**
  419.    * Return the next character in the normalized text and advance
  420.    * the iteration position by one.  If the end
  421.    * of the text has already been reached, {@link #DONE} is returned.
  422.    */
  423.   UChar                next(void);
  424.   
  425.   /**
  426.    * Return the previous character in the normalized text and decrement
  427.    * the iteration position by one.  If the beginning
  428.    * of the text has already been reached, {@link #DONE} is returned.
  429.    */
  430.   UChar                previous(void);
  431.   
  432.   /**
  433.    * Set the iteration position in the input text that is being normalized
  434.    * and return the first normalized character at that position.
  435.    * <p>
  436.    * <b>Note:</b> This method sets the position in the <em>input</em> text,
  437.    * while {@link #next} and {@link #previous} iterate through characters
  438.    * in the normalized <em>output</em>.  This means that there is not
  439.    * necessarily a one-to-one correspondence between characters returned
  440.    * by <tt>next</tt> and <tt>previous</tt> and the indices passed to and
  441.    * returned from <tt>setIndex</tt> and {@link #getIndex}.
  442.    * <p>
  443.    * @param index the desired index in the input text.
  444.    *
  445.    * @return      the first normalized character that is the result of iterating
  446.    *              forward starting at the given index.
  447.    *
  448.    * @throws IllegalArgumentException if the given index is less than
  449.    *          {@link #getBeginIndex} or greater than {@link #getEndIndex}.
  450.    */
  451.   UChar                setIndex(UTextOffset index);
  452.   
  453.   /**
  454.    * Reset the iterator so that it is in the same state that it was just after
  455.    * it was constructed.  A subsequent call to <tt>next</tt> will return the first
  456.    * character in the normalized text.  In contrast, calling <tt>setIndex(0)</tt> followed
  457.    * by <tt>next</tt> will return the <em>second</em> character in the normalized text,
  458.    * because <tt>setIndex</tt> itself returns the first character
  459.    */
  460.   void                reset(void);
  461.   
  462.   /**
  463.    * Retrieve the current iteration position in the input text that is
  464.    * being normalized.  This method is useful in applications such as
  465.    * searching, where you need to be able to determine the position in
  466.    * the input text that corresponds to a given normalized output character.
  467.    * <p>
  468.    * <b>Note:</b> This method sets the position in the <em>input</em>, while
  469.    * {@link #next} and {@link #previous} iterate through characters in the
  470.    * <em>output</em>.  This means that there is not necessarily a one-to-one
  471.    * correspondence between characters returned by <tt>next</tt> and
  472.    * <tt>previous</tt> and the indices passed to and returned from
  473.    * <tt>setIndex</tt> and {@link #getIndex}.
  474.    *
  475.    */
  476.   UTextOffset            getIndex(void) const;
  477.   
  478.   /**
  479.    * Retrieve the index of the start of the input text.  This is the begin index
  480.    * of the <tt>CharacterIterator</tt> or the start (i.e. 0) of the <tt>String</tt>
  481.    * over which this <tt>Normalizer</tt> is iterating
  482.    */
  483.   UTextOffset            startIndex(void) const;
  484.   
  485.   /**
  486.    * Retrieve the index of the end of the input text.  This is the end index
  487.    * of the <tt>CharacterIterator</tt> or the length of the <tt>String</tt>
  488.    * over which this <tt>Normalizer</tt> is iterating
  489.    */
  490.   UTextOffset            endIndex(void) const;
  491.   
  492.   
  493.   /**
  494.    * Returns true when both iterators refer to the same character in the same
  495.    * character-storage object.
  496.    */
  497.   //  virtual bool_t    operator==(const CharacterIterator& that) const;
  498.   bool_t        operator==(const Normalizer& that) const;
  499.   inline bool_t        operator!=(const Normalizer& that) const;
  500.   
  501.   /**
  502.    * Returns a pointer to a new Normalizer that is a clone of this one.
  503.    * The caller is responsible for deleting the new clone.
  504.    */
  505.   Normalizer*        clone(void) const;
  506.   
  507.   /**
  508.    * Generates a hash code for this iterator.
  509.    */
  510.   int32_t                hashCode(void) const;
  511.  
  512.   //-------------------------------------------------------------------------
  513.   // Property access methods
  514.   //-------------------------------------------------------------------------
  515.   
  516.   /**
  517.    * Set the normalization mode for this object.
  518.    * <p>
  519.    * <b>Note:</b>If the normalization mode is changed while iterating
  520.    * over a string, calls to {@link #next} and {@link #previous} may
  521.    * return previously buffers characters in the old normalization mode
  522.    * until the iteration is able to re-sync at the next base character.
  523.    * It is safest to call {@link #setText setText()}, {@link #first},
  524.    * {@link #last}, etc. after calling <tt>setMode</tt>.
  525.    * <p>
  526.    * @param newMode the new mode for this <tt>Normalizer</tt>.
  527.    * The supported modes are:
  528.    * <ul>
  529.    *  <li>{@link #COMPOSE}        - Unicode canonical decompositiion
  530.    *                                  followed by canonical composition.
  531.    *  <li>{@link #COMPOSE_COMPAT} - Unicode compatibility decompositiion
  532.    *                                  follwed by canonical composition.
  533.    *  <li>{@link #DECOMP}         - Unicode canonical decomposition
  534.    *  <li>{@link #DECOMP_COMPAT}  - Unicode compatibility decomposition.
  535.    *  <li>{@link #NO_OP}          - Do nothing but return characters
  536.    *                                  from the underlying input text.
  537.    * </ul>
  538.    *
  539.    * @see #getMode
  540.    */
  541.   void setMode(EMode newMode);
  542.   
  543.   /**
  544.    * Return the basic operation performed by this <tt>Normalizer</tt>
  545.    *
  546.    * @see #setMode
  547.    */
  548.   EMode getMode(void) const;
  549.   
  550.   /**
  551.    * Set options that affect this <tt>Normalizer</tt>'s operation.
  552.    * Options do not change the basic composition or decomposition operation
  553.    * that is being performed , but they control whether
  554.    * certain optional portions of the operation are done.
  555.    * Currently the only available option is:
  556.    * <p>
  557.    * <ul>
  558.    *   <li>{@link #IGNORE_HANGUL} - Do not decompose Hangul syllables into the
  559.    *       Jamo alphabet and vice-versa.  This option is off by default 
  560.    *       (<i>i.e.</i> Hangul processing is enabled) since the Unicode 
  561.    *       standard specifies that Hangul to Jamo is a canonical decomposition.
  562.    *       For any of the standard Unicode Normalization
  563.    *       Forms, you should leave this option off.
  564.    * </ul>
  565.    * <p>
  566.    * @param   option  the option whose value is to be set.
  567.    * @param   value   the new setting for the option.  Use <tt>true</tt> to
  568.    *                  turn the option on and <tt>false</tt> to turn it off.
  569.    *
  570.    * @see #getOption
  571.    */
  572.   void setOption(int32_t option, 
  573.          bool_t value);
  574.   
  575.   /**
  576.    * Determine whether an option is turned on or off.
  577.    * <p>
  578.    * @see #setOption
  579.    */
  580.   bool_t getOption(int32_t option) const;
  581.   
  582.   /**
  583.    * Set the input text over which this <tt>Normalizer</tt> will iterate.
  584.    * The iteration position is set to the beginning.
  585.    */
  586.   void setText(const UnicodeString& newText, 
  587.            UErrorCode &status);
  588.   
  589.   /**
  590.    * Set the input text over which this <tt>Normalizer</tt> will iterate.
  591.    * The iteration position is set to the beginning.
  592.    */
  593.   void setText(const CharacterIterator& newText, 
  594.            UErrorCode &status);
  595.   
  596.   /**
  597.    * Copies the text under iteration into the UnicodeString referred to by 
  598.    * "result".
  599.    * @param result Receives a copy of the text under iteration.
  600.    */
  601.   void            getText(UnicodeString&  result);
  602.   
  603. private:
  604.   // Private utility methods for iteration
  605.   // For documentation, see the source code
  606.   UChar nextCompose(void);
  607.   UChar prevCompose(void);
  608.   UChar nextDecomp(void);
  609.   UChar prevDecomp(void);
  610.   
  611.   UChar curForward(void);
  612.   UChar curBackward(void);
  613.   
  614.   void    init(CharacterIterator* iter, 
  615.          EMode mode, 
  616.          int32_t option);
  617.   void    initBuffer(void);
  618.   void    clearBuffer(void);
  619.   
  620.   // Utilities used by Compose
  621.   static void        bubbleAppend(UnicodeString& target, 
  622.                      UChar ch, 
  623.                      uint32_t cclass);
  624.   static uint32_t     getComposeClass(UChar ch);
  625.   static uint16_t    composeLookup(UChar ch);
  626.   static uint16_t    composeAction(uint16_t baseIndex, 
  627.                       uint16_t comIndex);
  628.   static void        explode(UnicodeString& target, 
  629.                 uint16_t index);
  630.   static UChar    pairExplode(UnicodeString& target, 
  631.                     uint16_t action);
  632.   
  633.   // Utilities used by Decompose
  634.   static void        fixCanonical(UnicodeString& result);    // Reorders combining marks
  635.   static uint8_t    getClass(UChar ch);                    // Gets char's combining class
  636.   
  637.   // Other static utility methods
  638.   static void doAppend(const UChar source[], 
  639.                uint16_t offset, 
  640.                UnicodeString& dest);
  641.   static void doInsert(const UChar source[], 
  642.                uint16_t offset, 
  643.                UnicodeString& dest, 
  644.                UTextOffset pos);
  645.   
  646.   static void hangulToJamo(UChar ch, 
  647.                UnicodeString& result, 
  648.                uint16_t decompLimit);
  649.   static void jamoAppend(UChar ch, 
  650.              uint16_t decompLimit, 
  651.              UnicodeString& dest);
  652.   static void jamoToHangul(UnicodeString& buffer, 
  653.                UTextOffset start);
  654.   
  655.   //-------------------------------------------------------------------------
  656.   // Private data
  657.   //-------------------------------------------------------------------------
  658.   
  659.   EMode         fMode;
  660.   int32_t       fOptions;
  661.   int16_t    minDecomp;
  662.   
  663.   // The input text and our position in it
  664.   CharacterIterator*  text;
  665.   
  666.   // A buffer for holding intermediate results
  667.   UnicodeString       buffer;
  668.   UTextOffset          bufferPos;
  669.   UTextOffset          bufferLimit;
  670.   UChar             currentChar;
  671.   
  672.   // Another buffer for use during iterative composition
  673.   UnicodeString       explodeBuf;
  674.   
  675.   enum {
  676.     EMPTY = -1,
  677.     STR_INDEX_SHIFT = 2, //Must agree with the constants used in NormalizerBuilder
  678.     STR_LENGTH_MASK = 0x0003
  679.   };
  680.   
  681.   static const UChar    HANGUL_BASE;
  682.   static const UChar    HANGUL_LIMIT;
  683.   static const UChar    JAMO_LBASE;
  684.   static const UChar    JAMO_VBASE;
  685.   static const UChar    JAMO_TBASE;
  686.   static const int16_t    JAMO_LCOUNT;
  687.   static const int16_t    JAMO_VCOUNT;
  688.   static const int16_t    JAMO_TCOUNT;
  689.   static const int16_t    JAMO_NCOUNT;
  690.   
  691.   friend class ComposedCharIter;
  692. };
  693.  
  694. inline bool_t
  695. Normalizer::operator!= (const Normalizer& other) const
  696. { return ! operator==(other); }
  697.  
  698. #endif // _NORMLZR
  699.  
  700.  
  701.  
  702.  
  703.