Logo Search packages:      
Sourcecode: icu version File versions

Collator * Collator::createInstance ( const Locale &  loc,
UErrorCode err 
) [static, inherited]

Gets the table-based collation object for the desired locale. The resource of the desired locale will be loaded by ResourceLoader. Locale::ENGLISH is the base collation table and all other languages are built on top of it with additional language-specific modifications. The UErrorCode& err parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_ERROR indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.

Parameters:
desiredLocale the desired locale to create the collation table with.
Returns:
the created table-based collation object based on the desired locale.
See also:
Locale

ResourceLoader

Definition at line 55 of file coll.cpp.

References NULL, and U_FAILURE.

{
  if (U_FAILURE(status)) 
    return 0;

  // A bit of explanation is required here. Although in the current 
  // implementation
  // Collator::createInstance() is just turning around and calling 
  // RuleBasedCollator(Locale&), this will not necessarily always be the 
  // case. For example, suppose we modify this code to handle a 
  // non-table-based Collator, such as that for Thai. In this case, 
  // createInstance() will have to be modified to somehow determine this fact
  // (perhaps a field in the resource bundle). Then it can construct the 
  // non-table-based Collator in some other way, when it sees that it needs 
  // to.
  // The specific caution is this: RuleBasedCollator(Locale&) will ALWAYS 
  // return a valid collation object, if the system if functioning properly.  
  // The reason is that it will fall back, use the default locale, and even 
  // use the built-in default collation rules. THEREFORE, createInstance() 
  // should in general ONLY CALL RuleBasedCollator(Locale&) IF IT KNOWS IN 
  // ADVANCE that the given locale's collation is properly implemented as a 
  // RuleBasedCollator.
  // Currently, we don't do this...we always return a RuleBasedCollator, 
  // whether it is strictly correct to do so or not, without checking, because 
  // we currently have no way of checking.

  RuleBasedCollator* collation = new RuleBasedCollator(desiredLocale, 
                                                             status);
  if (U_FAILURE(status))
  {
    delete collation;
    collation = NULL;
  }
  return collation;
}


Generated by  Doxygen 1.6.0   Back to index