Sorting Strings with Collation Keys
A common use of collation keys is in sorting a set of strings, where string comparisons are made repeatedly, as demonstrated in the code below:
RWUConversionContext context("UTF-8"); //1
RWUString array[] = { //2
"United States",
"Netherlands",
"United Kingdom",
"Germany",
"France",
"Italy",
"Japan",
"Australia",
""
};
RWUCollator collator; //3
RWTValSortedVector<RWUCollationKey, //4
std::less<RWUCollationKey> > vector;
int i;
for (i = 0; array[i].isNull() == false; ++i) {
vector.insert(collator.getCollationKey(array[i])); //5
}
for (i = 0; i < vector.entries(); ++i) { //6
std::cout << " " << vector[i].getString() << std::endl;
}