Wide character strings – HP Integrity NonStop J-Series User Manual
Page 62

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Wide Character Strings
Class
RWWString
, also used in representing various alphabets, is similar to
RWCString
except it
works with wide characters. These are much easier to manipulate than multibyte characters
because they are all the same size: the size of a wchar_t.
Tools.h++ makes it easy to convert back and forth between multibyte and wide character strings.
Here's an example of how to do it, built on the Sun example in the previous section:
#include
#include
#include
main() {
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
return 0; }
Basically, 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. The multiByte argument ensures that this relatively expensive conversion is not done
inadvertently. The conversion from a wide character string back to a multibyte string, using the
function toMultiByte(), is similarly expensive.
If you know that your
RWCString
consists entirely of ASCII characters, you can greatly reduce
the cost of the conversion in both directions. This is because the conversion involves a simple
manipulation of high-order bits:
#include
#include
#include