home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / ptnentry.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  5.1 KB  |  191 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. #ifndef PTNENTRY_H
  13. #define PTNENTRY_H
  14.  
  15. #include "utypes.h"
  16. #include "unistr.h"
  17. #include "coll.h"
  18. #include "normlzr.h"
  19.  
  20. /**
  21.  *
  22.  * Utility class for normalizing and merging patterns for collation.
  23.  * This is to be used with MergeCollation for adding patterns to an
  24.  * existing rule table.
  25.  */
  26.  /*
  27.  * Created by:     Mark Davis, Helena Shih
  28.  *
  29.  * Modification History:
  30.  * Date        Name        Description
  31.  *
  32.  *  8/18/97     helena      Added internal API documentation.
  33.  *  8/14/98     erm         Synched with 1.2 version of PatternEntry.java
  34.  * 04/23/99     stephen     Removed EDecompositionMode, merged with
  35.  *                          Normalizer::EMode
  36.  */
  37. class PatternEntry 
  38. {
  39.  
  40.   friend class MergeCollation;
  41.   friend class PointerToPatternEntry;
  42.   friend class VectorOfPointersToPatternEntry;
  43.  
  44.  public:
  45.  
  46.   /**
  47.      * Gets the extension, quoted if necessary, of this pattern entry.
  48.      * @param toAddTo the result string buffer.
  49.      */
  50.   void appendQuotedExtension(UnicodeString& toAddTo) const;
  51.  
  52.   /**
  53.      * Gets the current chars, quoted if necessary, of this pattern entry.
  54.      */
  55.   void appendQuotedChars(UnicodeString& toAddTo) const;
  56.  
  57.   /**
  58.      * Compares two pattern entry objects.
  59.      * @param other the other pattern entry object.
  60.      * @return TRUE if the pattern entry objects are the same, FALSE otherwise.
  61.      */
  62.   bool_t equals(const PatternEntry& other) const;
  63.  
  64.   /**
  65.      * Gets the strength of this entry.
  66.      * @return the strength of this pattern entry.
  67.      */
  68.  
  69.   int32_t getStrength(void)   const;
  70.  
  71.   /**
  72.      * Gets the extension characters.
  73.      * @param the extension string reference.
  74.      * @return the extension chars of this pattern entry.
  75.      */
  76.   const   UnicodeString&  getExtension(UnicodeString& ext) const;
  77.  
  78.   /**
  79.      * Gets the core characters.
  80.      * @param the char string reference.
  81.      * @return the char string of this pattern entry.
  82.      */
  83.   const   UnicodeString&  getChars(UnicodeString& chars) const;
  84.  
  85.   /**
  86.      * Used to parse a pattern into a list
  87.      * of PatternEntry's.
  88.      */
  89.  
  90.   class Parser
  91.     {
  92.     public:
  93.       Parser(const UnicodeString &pattern, Normalizer::EMode decompMode);
  94.       
  95.       Parser(const Parser &that);
  96.       
  97.       Parser &operator=(const Parser &that);
  98.       
  99.       ~Parser();
  100.       
  101.       PatternEntry *next(UErrorCode &status);
  102.  
  103.     private:
  104.       UnicodeString pattern;
  105.       int32_t index;
  106.       Normalizer::EMode fDecompMode;
  107.  
  108.       UnicodeString newChars;
  109.       UnicodeString newExtensions;
  110.     };
  111.  
  112.   friend class Parser;
  113.  
  114.  
  115.     /**
  116.      * For debugging only.
  117.      */
  118.   UnicodeString& toString(UnicodeString&) const;
  119.  
  120.  private:
  121.  
  122.     /** Constructor and destructor
  123.      */
  124.   PatternEntry();
  125.  
  126.   /**
  127.      * Creates a new pattern entry object.
  128.      */
  129.   PatternEntry(int32_t strength,
  130.            const UnicodeString& chars,
  131.            const UnicodeString& extension,
  132.            Normalizer::EMode decompMode);
  133.   /**
  134.      * Copy constructor.
  135.      */
  136.   PatternEntry(const  PatternEntry& other);
  137.   /**
  138.      * Destructor.
  139.      */
  140.   ~PatternEntry();
  141.  
  142.   /** assignment 
  143.      */
  144.   const   PatternEntry&       operator=(const PatternEntry&   other);
  145.  
  146.   /**
  147.      * Transforms the pattern entry into displayable text and adds
  148.      * the text to the buffer, toAddTo.
  149.      * @param toAddTo the result buffer.
  150.      * @param showExtension whether to add the extension chars or not.
  151.      * @param showWhiteSpace whether to add the white spaces or not.
  152.      * @param lastEntry the last pattern entry that was referenced.
  153.      */
  154.   void addToBuffer(UnicodeString& toAddTo,
  155.            bool_t showExtension,
  156.            bool_t showWhiteSpace,
  157.            const PatternEntry* lastEntry) const;
  158.  
  159.   /**
  160.      * Gets the extension, quoted if necessary, of this pattern entry.
  161.      * @param chars the chars string
  162.      * @param toAddTo the result string buffer.
  163.      */
  164.   static void appendQuoted(const UnicodeString& chars, UnicodeString& toAddTo);
  165.  
  166.   /**
  167.      * Checks if the Unicode character is a special character, for example, '@'
  168.      * is considered a special character.  The values of a special character is
  169.      * of the following range,
  170.      * <pre>punctuation symbols :
  171.      *                          0x0020 - 0x002F
  172.      *                          0x003A - 0x003F 
  173.      *                          0x005B - 0x0060
  174.      *                          0x007B - 0x007E
  175.      * </pre>
  176.      * @param the Unicode character
  177.      * @return TRUE if the character is a special character, FALSE otherwise.
  178.      */
  179.   static bool_t isSpecialChar(UChar ch);
  180.  
  181.   int32_t strength;
  182.   UnicodeString chars;
  183.   UnicodeString extension;
  184.  
  185.   static const int32_t RESET;
  186.   static const int32_t UNSET;
  187. };
  188.  
  189.  
  190. #endif // _PTNENTRY
  191.