Tools.h++ Manual
5-4 104011 Tandem Computers Incorporated
5
which is an encapsulation of the Standard C library function
strcoll()
. This
function will return 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&);
and then use
compareTo()
or one of the logical operators (==, !=, etc.) on the
results.
5.3 Substrings
A separate
RWCSubString
class supports substring extraction and
modification. There are no public constructors—
RWCSubStrings
are
constructed indirectly by various member functions of
RWCString
, and then
destroyed at the first opportunity. The resulting substring can be used in a
variety of situations.
For example, a substring can be created by an overloaded version of
operator()()
This can then be used to initialize an
RWCString
:
RWCString s("this is a string");
// Construct an RWCString from a substring:
RWCString s2 = s(0, 4); // "this"
The result is a string
s2
that contains a copy of the first four characters of
s
.
RWSubStrings
may also be used as lvalues in an assignment, either to a
character string, or to an
RWCString
or RWCSubString:
// Construct an RWCString:
RWCString article("the");
RWCString s("this is a string");
s(0, 4) = "that"; // "that is a string"
s(8, 1) = article; // "that is the string"
Note – Assignment is not a conformal operation: the two sides of the
assignment operator need not have the same number of characters.