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

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1996-1998                    *
  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. //=============================================================================
  14. //
  15. // File coll.cpp
  16. //
  17. // 
  18. //
  19. // Created by: Helena Shih
  20. //
  21. // Modification History:
  22. //
  23. //  Date        Name        Description
  24. //  2/5/97      aliu        Modified createDefault to load collation data from
  25. //                          binary files when possible.  Added related methods
  26. //                          createCollationFromFile, chopLocale, createPathName.
  27. //  2/11/97     aliu        Added methods addToCache, findInCache, which implement
  28. //                          a Collation cache.  Modified createDefault to look in
  29. //                          cache first, and also to store newly created Collation
  30. //                          objects in the cache.  Modified to not use gLocPath.
  31. //  2/12/97     aliu        Modified to create objects from RuleBasedCollator cache.
  32. //                          Moved cache out of Collation class.
  33. //  2/13/97     aliu        Moved several methods out of this class and into
  34. //                          RuleBasedCollator, with modifications.  Modified
  35. //                          createDefault() to call new RuleBasedCollator(Locale&)
  36. //                          constructor.  General clean up and documentation.
  37. //  2/20/97     helena      Added clone, operator==, operator!=, operator=, and copy
  38. //                          constructor.
  39. // 05/06/97     helena      Added memory allocation error detection.
  40. // 05/08/97     helena      Added createInstance().
  41. //  6/20/97     helena      Java class name change.
  42. // 04/23/99     stephen     Removed EDecompositionMode, merged with 
  43. //                          Normalizer::EMode
  44. //=============================================================================
  45.  
  46. #include "colcache.h"
  47.  
  48. #include "coll.h"
  49.  
  50. #include "tblcoll.h"
  51. #include "sortkey.h"
  52. #include "resbund.h"
  53. #include "mutex.h"
  54. #include "normlzr.h"
  55.  
  56. //-----------------------------------------------------------------------------
  57.  
  58. Collator::Collator()
  59.   : strength(Collator::TERTIARY), decmp(Normalizer::DECOMP)
  60. {
  61. }
  62.  
  63. Collator::Collator(ECollationStrength collationStrength,
  64.            Normalizer::EMode decompositionMode)
  65.   : strength(collationStrength), decmp(decompositionMode)
  66. {
  67. }
  68.  
  69. Collator::~Collator()
  70. {
  71. }
  72.  
  73. Collator::Collator(const    Collator&   other)
  74.   : strength(other.strength), decmp(other.decmp)
  75. {
  76. }
  77.  
  78. const Collator&
  79. Collator::operator=(const   Collator&   other)
  80. {
  81.   if (this != &other) {
  82.     strength = other.strength;
  83.     decmp = other.decmp;
  84.   }
  85.   return *this;
  86. }
  87.  
  88. Collator*
  89. Collator::createInstance(UErrorCode& success) {
  90.   if (U_FAILURE(success))
  91.     return 0;
  92.   return createInstance(Locale::getDefault(), success);
  93. }
  94.  
  95. Collator*
  96. Collator::createInstance(const Locale&  desiredLocale, 
  97.                          UErrorCode&     status)
  98. {
  99.   if (U_FAILURE(status)) return 0;
  100.  
  101.   /**
  102.    * A bit of explanation is required here.  Although in the current implementation
  103.    * Collator::createInstance() is just turning around and calling RuleBasedCollator(Locale&),
  104.    * this will not necessarily always be the case.  For example, suppose we modify
  105.    * this code to handle a non-table-based Collator, such as that for Thai.  In this
  106.    * case, createInstance() will have to be modified to somehow determine this fact
  107.    * (perhaps a field in the resource bundle).  Then it can construct the non-table-based
  108.    * Collator in some other way, when it sees that it needs to.
  109.    *
  110.    * The specific caution is this:  RuleBasedCollator(Locale&) will ALWAYS return a
  111.    * valid collation object, if the system if functioning properly.  The reason
  112.    * is that it will fall back, use the default locale, and even use the built-in
  113.    * default collation rules.  THEREFORE, createInstance() should in general ONLY CALL
  114.    * RuleBasedCollator(Locale&) IF IT KNOWS IN ADVANCE that the given locale's collation
  115.    * is properly implemented as a RuleBasedCollator.
  116.    *
  117.    * Currently, we don't do this...we always return a RuleBasedCollator, whether it
  118.    * is strictly correct to do so or not, without checking, because we currently
  119.    * have no way of checking.
  120.    */
  121.   RuleBasedCollator* collation = new RuleBasedCollator(desiredLocale, status);
  122.   if (U_FAILURE(status))
  123.     {
  124.       delete collation;
  125.       collation = 0;
  126.     }
  127.   return collation;
  128. }
  129.  
  130. bool_t
  131. Collator::equals(const UnicodeString& source, 
  132.          const UnicodeString& target) const
  133. {
  134.   return (compare(source, target) == Collator::EQUAL);
  135. }
  136. bool_t
  137. Collator::greaterOrEqual(const UnicodeString& source, 
  138.              const UnicodeString& target) const
  139. {
  140.   return (compare(source, target) != Collator::LESS);
  141. }
  142. bool_t
  143. Collator::greater(const UnicodeString& source, 
  144.           const UnicodeString& target) const
  145. {
  146.   return (compare(source, target) == Collator::GREATER);
  147. }
  148.  
  149. Collator::ECollationStrength 
  150. Collator::getStrength() const
  151. {
  152.   return strength;
  153. }
  154.  
  155. void 
  156. Collator::setStrength(Collator::ECollationStrength newStrength)
  157. {
  158.   strength = newStrength;
  159. }
  160.  
  161. Normalizer::EMode
  162. Collator::getDecomposition() const
  163. {
  164.   return decmp;
  165. }
  166. void 
  167. Collator::setDecomposition(Normalizer::EMode decompositionMode)
  168. {
  169.   decmp = decompositionMode;
  170. }
  171.  
  172.  
  173. const Locale*
  174. Collator::getAvailableLocales(int32_t& count) 
  175. {
  176.   return Locale::getAvailableLocales(count);
  177. }
  178.  
  179. UnicodeString&
  180. Collator::getDisplayName(   const   Locale&     objectLocale,
  181.                             const   Locale&     displayLocale,
  182.                 UnicodeString& name)
  183. {
  184.   return objectLocale.getDisplayName(displayLocale, name);
  185. }
  186.  
  187. UnicodeString& 
  188. Collator::getDisplayName(   const   Locale&     objectLocale,
  189.                 UnicodeString& name)
  190. {   
  191.   return objectLocale.getDisplayName(Locale::getDefault(), name);
  192. }
  193.  
  194. //eof
  195.