Module: Internationalization Module Group: Character Encoding Scheme Conversion
RWUToUnicodeConversionContext RWUConversionContext RWUFromUnicodeConversionContext
#include <rw/i18n/RWUConversionContext.h>
RWUConversionContext specifies the default character encoding scheme to use for subsequent implicit conversions between narrow character strings and UTF-16 encoded Unicode strings.
RWUConversionContext combines the functionality provided by the RWUToUnicodeConversionContext and RWUFromUnicodeConversionContext to provide a single convenient means for specifying the encoding for conversions to and from Unicode.
RWUConversionContext uses the resource acquisition is initialization idiom to manage two internal, per-thread stacks of RWUFromUnicodeConversionContext instances and RWUToUnicodeConversionContext.
NOTE -- Instances of RWUConversionContext can only be constructed with static or automatic storage duration; dynamic allocation is not allowed. Do not create unnamed, temporary instances. The destructors for such objects pop the context off the context stack prematurely.
#include <rw/i18n/RWUConversionContext.h> #include <rw/i18n/RWUString.h> #include <iostream> int main() { // Indicate that source and target strings // are encoded according to ISO-8859-1 RWUConversionContext context("ISO-8859-1"); // NOTE! This won't work: RWUConversionContext("ISO-8859-1"); // Use implicit conversion to construct `str' RWUString str("ISO-8859-1"); // Use implicit conversion to initialize `str2' RWUString str2 = " source: "; str += str2; // Write an ISO-8859-1 encoded representation of // `str' to std::cout std::cout << str << "in ISO-8859-1" << std::endl; { // Create a nested conversion context RWUConversionContext nestedContext("Shift-JIS"); // Write a Shift-JIS encoded representation of // `str' to std::cout std::cout << str << "in Shift-JIS" << std::endl; // Nested context goes out of scope } // Original context goes out of scope return 0; } Results: ======== ISO-8859-1 source: in ISO-8859-1 ISO-8859-1 source: in Shift-JIS
RWUToUnicodeConversionContext, RWUFromUnicodeConversionContext
RWUConversionContext(const char* encoding = RWUConverterBase::getDefaultEncodingName());
Constructs an RWUConversionContext for the specified encoding. The conversion context specifies the default implicit conversion to use when automatically converting a sequence of bytes into an RWUString, an RWUString into a sequence of bytes, or both. The encoding name is encoded in ASCII, and must specify one of the names or aliases currently recognized by the Internationalization Module (see RWUAvailableEncodingList and RWUEncodingAliasList).
The specified conversion context remains in effect until another conversion of the same direction is specified, or until the conversion context instance goes out of scope and is destroyed.
Throws RWUException to indicate that a converter could not be constructed for the specified encoding. The exception carries one of the following status codes:
RWUMemoryAllocationError
Indicates that the memory required by the converter could not be allocated.
RWUFileAccessError
Indicates that the requested converter could not be found.
~RWUConversionContext();
Destructor. Destroys self and restores the conversion context that was in effect prior to the construction of this instance.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, 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.