SourcePro® API Reference Guide

 
List of all members | Public Member Functions

Stores preprocessed comparison information for a Unicode string to speed repeated string comparisons. More...

#include <rw/i18n/RWUCollationKey.h>

Public Member Functions

 RWUCollationKey (void)
 
 RWUCollationKey (const RWUCollationKey &original)
 
 ~RWUCollationKey (void)
 
RWUString getString (void) const
 
unsigned hash () const
 
bool isValid (void) const
 
bool operator!= (const RWUCollationKey &rhs) const
 
bool operator< (const RWUCollationKey &rhs) const
 
RWUCollationKeyoperator= (const RWUCollationKey &rhs)
 
bool operator== (const RWUCollationKey &rhs) const
 

Detailed Description

RWUCollationKey stores preprocessed comparison information for a Unicode string, and can be used to speed repeated string comparisons. For example, you might choose to use collation keys when sorting a set of strings.

To create a valid RWUCollationKey, call RWUCollator::getCollationKey(). Generating a key is a non-trivial operation, since it involves determining the collation elements and weights for an entire string. Comparing two RWUCollationKey objects, however, is fast.

Note
Collation keys can only meaningfully be compared if they are created by the same collator, or by collators with the same attributes.
Example
#include <rw/i18n/RWUCollationKey.h>
#include <rw/i18n/RWUCollator.h>
#include <rw/i18n/RWUConversionContext.h>
#include <rw/tvsrtvec.h>
#include <iostream>
using std::cout;
using std::endl;
int
main()
{
// Indicate that source and target strings are
// encoded as UTF-8.
RWUConversionContext context("UTF-8");
// Create an array of country names.
RWUString array[] = {
"United States",
"Netherlands",
"United Kingdom",
"Germany",
"France",
"Italy",
"Japan",
"Australia",
""
};
size_t max_array_length = 20;
// Create a collator based on the "en" locale.
RWUCollator collator("en");
// Create an empty vector. An RWTValSortedVector<T>
// will automatically keep its contents in sorted
// order.
std::less<RWUCollationKey> > vector(max_array_length);
// Populate the vector with RWUCollationKey objects.
// Note that the vector will use
// RWUCollationKey::operator<() and operator==().
size_t i;
for (i = 0; array[i].isNull() == false; ++i) {
vector.insert(collator.getCollationKey(array[i]));
} // for
// Print the sorted vector. Obtain RWUString objects
// from the stored RWUCollationKey objects, implicitly
// convert them to UTF-8, and print the UTF-8.
cout << "Rogue Wave has offices in the following "
"countries:" << endl;
for (i = 0; i < vector.entries(); ++i) {
cout << " " << vector[i].getString() << endl;
} // for
return 0;
} // main

Program output:

Rogue Wave has offices in the following countries:
Australia
France
Germany
Italy
Japan
Netherlands
United Kingdom
United States
See also
RWUCollator

Constructor & Destructor Documentation

RWUCollationKey::RWUCollationKey ( void  )
inline

Default constructor. Creates an invalid key.

Invalid keys are equal to each other, and not equal to any other key. They are less than all other keys. Calling getString() on an invalid key results in an RWUException.

This constructor exists only as a convenience–for example, when creating an array of RWUCollationKey objects. To create a valid, usable RWUCollationKey, call RWUCollator::getCollationKey().

RWUCollationKey::RWUCollationKey ( const RWUCollationKey original)

Copy constructor. Makes self a deep copy of original.

RWUCollationKey::~RWUCollationKey ( void  )
inline

Destructor.

Member Function Documentation

RWUString RWUCollationKey::getString ( void  ) const

Returns the string whose collation value self holds. Throws RWUException if self is an invalid key.

unsigned RWUCollationKey::hash ( ) const
inline

Returns a hash value for self.

bool RWUCollationKey::isValid ( void  ) const
inline

Returns true if self is a valid key; otherwise, false.

bool RWUCollationKey::operator!= ( const RWUCollationKey rhs) const

Returns true if self does not compare equal to collation key rhs; otherwise false.

Note
collation keys can only meaningfully be compared if they are created by the same collator, or by collators with the same attributes.
bool RWUCollationKey::operator< ( const RWUCollationKey rhs) const

Returns true if self compares less than collation key rhs; otherwise false.

Note
collation keys can only meaningfully be compared if they are created by the same collator, or by collators with the same attributes.
RWUCollationKey& RWUCollationKey::operator= ( const RWUCollationKey rhs)

Assignment operator. Makes self a deep copy of rhs.

bool RWUCollationKey::operator== ( const RWUCollationKey rhs) const

Returns true if self compares equal to collation key rhs; otherwise false.

Note
collation keys can only meaningfully be compared if they are created by the same collator, or by collators with the same attributes.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.