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

  1. /******************************************************************************
  2.  * COPYRIGHT:                                                               
  3.  *  (C) Copyright Taligent, Inc., 1996
  4.  *  (C) Copyright IBM Corp. 1996-1999
  5.  *  Licensed Material - Program-Property of IBM - All Rights Reserved.
  6.  *  US Government Users Restricted Rights - Use, duplication, or disclosure
  7.  *  restricted by GSA ADP Schedule Contact with IBM Corp.
  8.  *
  9.  ******************************************************************************
  10.  */
  11. //=============================================================================
  12. //
  13. // File mergecol.h
  14. //
  15. // 
  16. //
  17. // Created by: Helena Shih
  18. //
  19. // Modification History:
  20. //
  21. //  Date        Name        Description
  22. //  3/5/97      mark        Cleaned up fixEntry().  Added constants BYTEPOWER
  23. //                          and BYTEMASK to replace BYTESIZE.
  24. //  6/17/97     helena      In getPattern, added the queue-up list for entries 
  25. //                          with the same extension chars.
  26. //  8/18/97     helena      Added internal API documentation.
  27. //  8/13/98     erm         Synched up with 1.2 version of MergeCollation.java
  28. // 04/23/99     stephen     Removed EDecompositionMode, merged with
  29. //                          Normalizer::EMode
  30. //=============================================================================
  31.  
  32. #ifndef MERGECOL_H
  33. #define MERGECOL_H
  34.  
  35. #include "unistr.h"
  36. #include "ptnentry.h"
  37. #include "tables.h"
  38. #include "coll.h"
  39. #include "normlzr.h"
  40.  
  41.  
  42. /**
  43.  * Utility class for normalizing and merging patterns for collation.
  44.  * Patterns are strings of the form <entry>*, where <entry> has the
  45.  * form:
  46.  * <pre>
  47.  * <pattern> := <entry>*
  48.  * <entry> := <separator><chars>{"/"<extension>}
  49.  * <separator> := "=", ",", ";", "<", "&"
  50.  * <chars>, and <extension> are both arbitrary strings.
  51.  * </pre>
  52.  * <P>Unquoted whitespaces are ignored.
  53.  * 'xxx' can be used to quote characters.
  54.  * <P>
  55.  * One difference from Collation is that & is used to reset to a current
  56.  * point. Or, in other words, it introduces a new sequence which is to
  57.  * be added to the old.
  58.  * <P>
  59.  * That is: "a < b < c < d" is the same as "a < b & b < c & c < d" OR
  60.  * "a < b < d & b < c"
  61.  * XXX: make '' be a single quote.
  62.  * @see        PatternEntry
  63.  * @version    1.4 1/7/97
  64.  * @author     Mark Davis, Helena Shih
  65.  */
  66.  
  67. class MergeCollation 
  68. {
  69. public:
  70.  
  71.     /**
  72.      * Creates a merged collation table from a pattern string.
  73.      * @param pattern the pattern string.
  74.      * @param status the error code status.  If the input pattern is incorrect,
  75.      * this will be set to U_INVALID_FORMAT_ERROR.
  76.      */
  77.   MergeCollation( const   UnicodeString&  pattern,
  78.           Normalizer::EMode decompMode,
  79.           UErrorCode&      success);
  80.   /**
  81.      * Copy constructor.
  82.      */
  83.   MergeCollation( const   MergeCollation& other);
  84.  
  85.   /**
  86.      * Destructor.
  87.      */
  88.   ~MergeCollation();
  89.  
  90.   /** Assignment operator
  91.      */
  92.   const   MergeCollation&     operator=(const MergeCollation& other);
  93.   /**
  94.      * Recovers current pattern from this merged collation object.
  95.      * @param pattern the result buffer.
  96.      * @return the recovered result.
  97.      */
  98.   UnicodeString& getPattern(UnicodeString& pattern) const;
  99.  
  100.   /**
  101.      * Recovers current pattern with white spaces.
  102.      * @param pattern the result buffer.
  103.      * @param withWhiteSpace puts spacing around the entries, and \n
  104.      * before & and <
  105.      * @return the recovered result.
  106.      */
  107.   UnicodeString& getPattern(UnicodeString& pattern, bool_t withWhiteSpace) const;
  108.  
  109.   /**
  110.      * Emits the pattern for collation builder.
  111.      * @param pattern the result buffer.
  112.      * @return Emits the string in the format understable to the collation
  113.      * builder.
  114.      */
  115.   UnicodeString& emitPattern(UnicodeString& pattern) const;
  116.  
  117.   /**
  118.      * Emits the pattern for collation builder.
  119.      * @param pattern the result buffer.
  120.      * @param withWhiteSpace puts spacing around the entries, and \n
  121.      * before & and <
  122.      * @return Emits the string in the format understable to the collation
  123.      * builder.
  124.      */
  125.   UnicodeString& emitPattern(UnicodeString& pattern, bool_t withWhiteSpace) const;
  126.  
  127.   /**
  128.      * Sets the pattern.
  129.      * @param pattern string.
  130.      * @param status the error code status, it will be set to U_INVALID_FORMAT_ERROR
  131.      * if the pattern is incorrect.
  132.      */
  133.   void setPattern(const   UnicodeString&  pattern,
  134.           Normalizer::EMode decompMode,
  135.           UErrorCode&      status);
  136.  
  137.   /**
  138.      * Adds a pattern to the current merge collation object.
  139.      * @param pattern the new pattern to be added.
  140.      * @param status the error code status, it will be set to U_INVALID_FORMAT_ERROR
  141.      * if the pattern is incorrect.
  142.      */
  143.   void addPattern(const   UnicodeString&  pattern,
  144.           Normalizer::EMode decompMode,
  145.           UErrorCode&      status);
  146.  
  147.   /**
  148.      * Gets count of separate entries in the merge collation object.
  149.      * @return the number of pattern entries
  150.      */
  151.   int32_t getCount(void) const;
  152.  
  153.   /**
  154.      * Gets the specified pattern entry out of the merge collation object.
  155.      * @param index the offset of the desired pattern entry
  156.      * @return the requested pattern entry
  157.      */
  158.   const PatternEntry* getItemAt(UTextOffset index) const;
  159.  
  160. private:
  161.  
  162.     //============================================================
  163.     // privates
  164.     //============================================================
  165.  
  166.   VectorOfPointersToPatternEntry* patterns; // a vector of PatternEntries
  167.   static  const   int32_t         BITARRAYSIZE;
  168.   static  const   uint8_t         BITARRAYMASK;
  169.   static  const   int32_t         BYTEPOWER;
  170.   static  const   int32_t         BYTEMASK;
  171.  
  172.   PatternEntry*   lastEntry;
  173.   PatternEntry*   saveEntry;
  174.   uint8_t*        statusArray;
  175.  
  176.  
  177.     /**
  178.      * Finds the last pattern entry before the specified offset that does not have 
  179.      * extension chars.
  180.      * @param i the offset.
  181.      * @return the pattern entry.
  182.      */
  183.   const PatternEntry* findLastWithNoExtension(int32_t i) const;
  184.  
  185.   /** 
  186.      * Fixes the new pattern entry in the merge collation table.
  187.      * If the strength is RESET, then just change the lastEntry to
  188.      * be the current. (If the current is not in patterns, signal an error).
  189.      * If not, then remove the current entry, and add it after lastEntry
  190.      * (which is usually at the end).  Strength indicates the text order
  191.      * weight for an entry.
  192.      * @param newEntry the new pattern entry
  193.      * @param status the error code status, it will be set to U_INVALID_FORMAT_ERROR
  194.      * if the strength is RESET and a previous entry can't be found.
  195.      */
  196.   void fixEntry(  PatternEntry*   newEntry,
  197.           UErrorCode&      status);
  198.  
  199.   /**
  200.      * Finds the offset of the specified entry that was previously installed in the
  201.      * merge collation object.
  202.      * @param lastEntry the entry that was previously installed.
  203.      * @param excess the extra characters 
  204.      * @param status the error code status, it will be set to U_INVALID_FORMAT_ERROR
  205.      * if the strength is RESET and a previous entry can't be found.
  206.      * @return the offset of the found entry
  207.      */
  208.   int32_t findLastEntry(  const PatternEntry* lastEntry, 
  209.               UnicodeString&  excess,
  210.               UErrorCode&      success) const;
  211. };
  212.  
  213. inline UnicodeString& MergeCollation::getPattern(UnicodeString& result) const
  214. {
  215.   return getPattern(result, TRUE);
  216. }
  217.  
  218. inline UnicodeString& MergeCollation::emitPattern(UnicodeString& result) const
  219. {
  220.   return emitPattern(result, TRUE);
  221. }
  222.  
  223.  
  224. #endif // _MERGECOL
  225.