SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
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 & | operator= (const RWUCollationKey &rhs) |
~RWUCollationKey (void) | |
bool | isValid (void) const |
bool | operator== (const RWUCollationKey &rhs) const |
bool | operator!= (const RWUCollationKey &rhs) const |
bool | operator< (const RWUCollationKey &rhs) const |
unsigned | hash () const |
RWUString | getString (void) const |
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.
#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. RWTValSortedVector<RWUCollationKey, 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
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.
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
.
bool RWUCollationKey::operator< | ( | const RWUCollationKey & | rhs | ) | const |
Returns true
if self compares less than collation key rhs; otherwise false
.
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
.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.