International Features of the Serial Package
This section discusses how to use the Serial package with or without the Internationalization Module.
To determine if you need to use the Internationalization Module, see
“Determining your Character Encoding Needs”.
Using the Serial Package without the Internationalization Module
The Serial package of the Advanced Tools Module provides
RWWString and wide-character inserters and extractors for object streams. You may use these inserters and extractors when your string contains wide characters but you have determined that you do not need the Internationalization Module. For more information on how to determine if you need the Internationalization Module, see
“Determining your Character Encoding Needs.”Compact Object Streams
You may insert or extract a wide character in any character encoding to and from a compact object stream.
The compact object streams of the Serial package rely on the virtual streams from the Essential Tools Module to provide formatting for all types, so the encoding of
RWWString and
wchar_t is dependent on those classes. See the Essential Tools Module classes in the
SourcePro API Reference Guide for more information.
Using the Serial Package with the Internationalization Module
The Serial package of the Advanced Tools Module provides an
RWUString inserter and extractor interface to object streams.
To use this interface, include the header file
RWObjectStreamI18n.h and then use
operator<< or
operator>> to shift
RWUStrings in or out of compact object streams. The
RWUString interface takes and produces UTF-16 encoded characters. The Streams package of the Advanced Tools Module and the Internationalization Module provide methods for converting to and from UTF-16 as shown in the next two sections.
Converting from a Local Encoding to UTF-16
To provide a convenient method for translation between character encodings,
RWUString works directly with character-encoding converters in the Internationalization Module.
For example, if you want to write out to UTF-16 a string encoded in the Japanese Shift-JIS, you would use the following.
#include "rw/i18n/RWUToUnicodeConverter.h" // 1
RWCString myString;
// Initialize myString with characters encoded in Shift-JIS
RWUToUnicodeConverter fromShiftJis("Shift-JIS"); // 2
RWByteOutputStream& tmpBStream =
RWByteToStreambufOutputStreamImp::make(cout.rdbuf());
RWDataOutputStream tmpDStream =
RWNativeDataToByteOutputStreamImp::make(tmpBStream);
RWObjectOutputStream out =
RWCompactObjectOutputStreamImp::make(tmpDStream); // 3
out << RWUString(myString, fromShiftJis); // 4
Converting from UTF-16 to a Local Encoding
Similarly, if you want to read in a document containing a string encoded in UTF-16, and then convert the string to Shift-JIS, use the following code.
#include "rw/i18n/RWUFromUnicodeConverter.h"
RWUFromUnicodeConverter toShiftJis("Shift-JIS");
RWByteInputStream& tmpBStream =
RWByteFromStreambufInputStreamImp::make(cin.rdbuf());
RWDataInputStream tmpStream =
RWNativeDataFromByteInputStreamImp::make(tmpBStream);
RWObjectInputStream in =
RWCompactObjectInputStreamImp::make(tmpStream);
RWUString someRWUString;
in >> someRWUString;
someRWUString.toBytes(toShiftJis); // 1