SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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

#include <rw/i18n/RWUCollationKey.h>

Public Member Functions

 RWUCollationKey (const RWUCollationKey &original)
 
 RWUCollationKey (void)
 
 ~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
 

Friends

class RWUCollator
 

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.
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;
}
return 0;
}
bool isNull() const
Definition bustring.h:5330
Maintains a sorted collection of values implemented as a vector.
Definition tvsrtvec.h:116
Performs locale-sensitive string comparison for use in searching and sorting natural language text.
Definition RWUCollator.h:296
Specifies the default character encoding scheme for conversions between narrow character strings and ...
Definition RWUConversionContext.h:101
Stores and manipulates Unicode character sequences encoded as UTF-16 code units.
Definition RWUString.h:187

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() [1/2]

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() [2/2]

RWUCollationKey::RWUCollationKey ( const RWUCollationKey & original)

Copy constructor. Makes self a deep copy of original.

◆ ~RWUCollationKey()

RWUCollationKey::~RWUCollationKey ( void )
inline

Destructor.

Member Function Documentation

◆ getString()

RWUString RWUCollationKey::getString ( void ) const

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

◆ hash()

unsigned RWUCollationKey::hash ( ) const
inline

Returns a hash value for self.

◆ isValid()

bool RWUCollationKey::isValid ( void ) const
inline

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

◆ operator!=()

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.

◆ operator<()

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.

◆ operator=()

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

Assignment operator. Makes self a deep copy of rhs.

◆ operator==()

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.