Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

3.2 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 t he 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 fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.