Rogue Wave Banner

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Lexicographic Comparisons

If you're putting together a dictionary, you'll find the lexicographics comparison operators of RWCString particularly useful. They are:

RWBoolean operator==(const RWCString&, const RWCString&);
RWBoolean operator!=(const RWCString&, const RWCString&);
RWBoolean operator< (const RWCString&, const RWCString&);
RWBoolean operator<=(const RWCString&, const RWCString&);
RWBoolean operator> (const RWCString&, const RWCString&);
RWBoolean operator>=(const RWCString&, const RWCString&);

These operators are case sensitive. If you wish to make case insensitive comparisons, you can use the member function:

int RWCString::compareTo(const RWCString& str, 
                         caseCompare = RWCString::exact) const;

Here the function returns an integer less than zero, equal to zero, or greater than zero, depending on whether str is lexicographically less than, equal to, or greater than self. The type caseCompare is an enum with values:

exact Case sensitive

ignoreCase Case insensitive

Its default setting is exact, which gives the same result as the logical operators ==, !=, etc.

For locale-specific string collations, you would use the member function:

int RWCString::collate(const RWCString& str) const;

which is an encapsulation of the Standard C library function strcoll(). This function returns results computed according to the locale-specific collating conventions set by category LC_COLLATE of the Standard C library function setlocale(). Because this is a relatively expensive calculation, you may want to pretransform one or more strings using the global function:

RWCString strXForm(const RWCString&);

then use compareTo() or one of the logical operators, ==, !=, etc., on the results. See the Class Reference entry for RWCString: the function strxForm appears under related global functions.


Previous file Table of Contents Next file