Module: Internationalization Module Group: Character Encoding Scheme Conversion
Does Not Inherit
#include <rw/i18n/RWUFromUnicodeConversionContext.h>
RWUFromUnicodeConversionContext specifies the character encoding scheme to use for subsequent implicit conversions from UTF-16 encoded Unicode strings into another encoding.
RWUFromUnicodeConversionContext uses the resource acquisition is initialization idiom to manage internal, per-thread stacks of RWUFromUnicodeConversionContext instances, each containing an RWUFromUnicodeConverter object. The RWUFromUnicodeConversionContext constructor pushes a reference to the new instance onto the context stack. The RWUFromUnicodeConversionContext destructor pops the instance off the context stack. The top-level element of each thread's stack defines the conversion required to translate implicitly a UTF-16 encoded Unicode string into another encoding.
Instances of this class 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/RWUFromUnicodeConversionContext.h> #include <rw/i18n/RWUToUnicodeConverter.h> #include <rw/i18n/RWUString.h> #include <iostream> int main() { // Indicate that strings should be implicitly converted // to ISO-8859-1 when output to std::cout. RWUFromUnicodeConversionContext toIso_8859_1("ISO-8859-1"); // NOTE! This won't work: RWUFromUnicodeConversionContext("ISO-8859-1"); // Use explicit conversion to construct `str' RWUToUnicodeConverter fromAscii("ASCII"); RWUString str("ASCII source: ", fromAscii); // 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 RWUFromUnicodeConversionContext toShiftJis("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: ======== ASCII source: in ISO-8859-1 ASCII source: in Shift-JIS
RWUFromUnicodeConverter, RWUToUnicodeConversionContext, RWUConversionContext
static RWUFromUnicodeConversionContext& getContext();
Returns a reference to the current RWUFromUnicodeConversionContext.
Note: Using this method to access a user-defined or root context after the program has exited main() may produce unpredictable or erroneous behavior. Do not use conversion contexts during the destruction of static-duration objects.
RWUFromUnicodeConversionContext(const char* encoding = RWUConverterBase::getDefaultEncodingName());
Constructs an RWUFromUnicodeConversionContext for the specified encoding. The from-Unicode conversion context specifies the converter to use when implicitly converting a sequence of UTF-16 code units into a sequence of bytes encoded according to the specified encoding.
The encoding name is encoded in ASCII and must specify one of the names or aliases recognized by the Internationalization Module (see RWUAvailableEncodingList and RWUEncodingAliasList).
The conversion context remains in effect until another conversion context 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.
~RWUFromUnicodeConversionContext();
Destructor. Destroys self and restores the conversion context that was in effect prior to the construction of this instance.
RWUFromUnicodeConverter& getConverter();
Returns a reference to the internal RWUFromUnicodeConverter instance used in converting UTF-16 encoded strings to another encoding.
© 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.