Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNo next file
Advanced Tools Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

8.4 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 Section 8.2.

8.4.1 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 Section 8.2, "Determining your Character Encoding Needs."

8.4.1.1 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 C++ API Reference Guide for more information.

8.4.2 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.

8.4.2.1 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.

//1

Include the header file for the "to Unicode" converter class.

//2

Create a converter for converting from Shift-JIS to UTF-16.

//3

Create the compact object output stream.

//4

Using the constructor that takes a second "converter" parameter, construct an RWUString from the RWCString containing characters encoded in Shift-JIS. The Shift-JIS characters will be converted to UTF-16 as part of the construction. Then shift out the RWUString.

8.4.2.2 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.

//1

Use the toBytes() method of the RWUString to convert from UTF-16 to Shift-JIS.



Previous fileTop of DocumentContentsNo linkNo next file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.