Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module User's Guide

4.10 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 wchar_t.

The Essential Tools Module 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:

Basically, you convert from a multibyte string to a wide string by using the special RWWString constructor:

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:

Note how the member functions RWCString::isAscii() and RWWString::isAscii() are used to ensure that the strings consist entirely of ASCII characters. The RWWString constructor:

is used to convert from ASCII to wide characters. The parameter ascii_ is an enum with a single possible value, ascii.

The member function RWWString::toAscii() is used to convert back.

Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.