Tools.h++ Manual
21-72 104011 Tandem Computers Incorporated
21
RWCString
Synopsis
#include <rw/cstring.h>
RWCString a;
Description
Class RWCString
offers very powerful and convenient facilities for
manipulating strings that are just as efficient as the familiar standard C
<string.h>
functions.
Although the class is primarily intended to be used to handle single-byte
character sets (SBCS; such as ASCII or ISO Latin-1), with care it can be used to
handle multibyte character sets (MBCS). There are two things that must be
kept in mind when working with MBCS:
• Because characters can be more than one byte long, the number of bytes in a
string can, in general, be greater than the number of characters in the string.
Use function
RWCString::length()
to get the number of bytes in a string,
function
RWCString::mbLength()
to get the number of characters. Note
that the latter is much slower because it must determine the number of
bytes in every character. Hence, if the string is known to be nothing but
SBCS, then
RWCString::length()
is much to be preferred.
• In general, one or more bytes of a multibyte character can be zero. Hence,
MBCS cannot be counted on being null terminated. In practice, it is a rare
MBCS that uses embedded nulls. Nevertheless, you should be aware of this
and program defensively.
Parameters of type "
const char
*" must not be passed a value of zero. This is
detected in the debug version of the library.
The class is implemented using a technique called copy on write. With this
technique, the copy constructor and assignment operators still reference the
old object and hence are very fast. An actual copy is made only when a
“write” is performed, that is if the object is about to be changed. The net result
is excellent performance, but with easy-to-understand copy semantics.
A separate class
RWCSubString
supports substring extraction and
modification operations.