Tools.h++ Manual

104011 Tandem Computers Incorporated 5-11
5
RWCString Sun(“\306\374\315\313\306\374”);
RWWString wSun(Sun, RWWString::multiByte);
// MBCS to wide string
RWCString check = wSun.toMultiByte();
assert(Sun==check); // OK
You convert from a multibyte string to a wide string by using the special
RWWString
constructor
RWWString(const char*, multiByte_);
The parameter
multiByte_
is an enum with a single possible value:
multiByte
, as shown in the example above.
This is a relatively expensive conversion and the
multiByte
argument ensures
that it is not done inadvertently. The conversion from a wide character string
back to a multibyte string is done using function
toMultiByte()
. Again, this
is a relatively expensive operation.
If you know that your
RWCString
consists entirely of Ascii characters then the
cost of the conversion in both direction can be greatly reduced. This is because
the conversion involves a simple manipulation of high-order bits:
RWCString EnglishSun(“Sunday”); // Ascii string
assert(EnglishSun.isAscii()); // OK
// Now convert from Ascii to wide characters:
RWWString wEnglishSun(EnglishSun, RWWString::ascii);
assert(wEnglishSun.isAscii()); // OK
RWCString check = wEnglishSun.toAscii();
assert(check==EnglishSun); // OK
Note how member functions
RWCString::isAscii()
and
RWWString::isAscii()
were used in ensure that the strings, in fact,
consisted entirely of Ascii characters. The
RWWString
constructor
RWWString(const char*, ascii_);
was used to convert from Ascii to wide characters. The parameter
ascii_
is
an enum with a single possible value:
ascii
, as shown in the example above.
Member function
RWWString::toAscii()
was used to convert back.