Module: Internationalization Module Group: Character Encoding Scheme Conversion
Base Class
#include <rw/i18n/RWUConverterBase.h>
RWUConverterBase provides a common base for the RWUToUnicodeConverter and RWUFromUnicodeConverter classes.
RWUToUnicodeConverter, RWUFromUnicodeConverter
static RWCString getCurrentLocaleEncodingName();
Returns the name of the encoding associated with the current native locale. The name returned by this method may be used to define a conversion that translates narrow characters and strings that have been encoded for the native locale into Unicode, and vice versa.
Some locales do not specify an encoding, so the execution environment must use a default encoding. For most platforms, this default is an ASCII encoding. If the active locale does not name an encoding, this method returns a value of ANSI_X3.4-1986, the standard encoding name for the ASCII character set.
On UNIX and Linux, this method returns an RWCString containing the charmap name associated with the current ISO/POSIX LC_CTYPE locale.
On Windows, this method returns an RWCString containing the name of the ANSI code page associated with the current thread locale. The name consists of the letters cp followed by the decimal number of the code page (for example, cp1252).
Note: When used under UNIX or Linux, this method determines the current charmap by using popen() to launch a new shell in which to execute the command locale -k charmap. The command is executed with the same LC_CTYPE locale setting as the calling process. This action is much more expensive than a simple function call, so you may want to cache the value. If the shell cannot be created, or if the command fails with an error, the default value ANSI_X3.4-1986 is returned.
static RWCString getDefaultEncodingName();
Returns a string containing the name of the current default encoding. This string may be empty if the framework was unable to determine the default encoding from the process environment.
If a default encoding name has not been set using setDefaultEncodingName(), the internationalization framework first attempts to retrieve the default encoding name from the execution environment, and if unable to do so, uses the value returned from getCurrentLocaleEncodingName() as the default.
static void setDefaultEncodingName(const char* encoding);
Sets the current default encoding name. The name must identify a valid encoding, but no attempt is made to validate the name.
NOTE -- This method is not thread-safe.
~RWUConverterBase();
Destructor.
bool operator==(const RWUConverterBase& rhs) const;
Returns true if self provides the same conversion as rhs; otherwise, false.
The name of self does not need to match the name of the other converter; two converters are considered equal if their names are aliases for the same conversion.
bool operator!=(const RWUConverterBase& rhs) const;
Returns true if self provides a different conversion than rhs; otherwise, false.
Two converters are considered not equal if their names are aliases for two different conversions.
RWCString getCanonicalName() const;
Returns the canonical name of the external character encoding scheme associated with this converter.
void getLocalizedName(const RWULocale& locale, RWUString& result) const;
Sets the given RWUString result with the localized name of the converter, if one exists for the given locale, or the internal ASCII name of the converter if no localized name exists.
size_t getMaxBytesPerChar() const;
Returns an integer value from 1 to 4 representing the maximum number of bytes required to describe a code point in the external character encoding scheme.
size_t getMinBytesPerChar() const;
Returns an integer value of 1 or 2 representing the minimum number of bytes required to describe a code point in the external character encoding scheme.
RWUConverterBase(const char* encoding = getDefaultEncodingName());
Constructs a converter for the character encoding scheme given by encoding, the ASCII name or alias of a character encoding scheme. See RWUAvailableEncodingList and RWUEncodingAliasList for lists the encodings and aliases recognized by the Internationalization Module.
Throws RWUException to indicate that the converter could not be constructed. 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.
RWUConverterBase(const RWUConverterBase& original);
Constructs a converter that is a deep copy of another converter. The new converter uses the same character encoding scheme as the original converter, and possesses the same internal state as the original converter.
Exercise care when copying converters, especially those used for stateful or multibyte encodings. The resulting converter may be in a state that causes the converter to produce errors if used to convert a new chunk of text. Consider using reset() to restore the converter to a known state before use.
Throws RWUException to indicate that the construction could not be completed because memory could not be allocated for the underlying implementation object.
RWUConverterBase& operator=(const RWUConverterBase& rhs);
Assignment operator. Makes self a deep copy of rhs. Self uses the same character encoding scheme as rhs, and possesses the same internal state as rhs.
Exercise care when copying converters, especially those used for stateful or multibyte encodings. The resulting converter may be in a state that causes the converter to produce errors if used to convert a new chunk of text. Consider using reset() to restore the converter to a known state before use.
Throws RWUException to indicate that the assignment could not be completed because memory could not be allocated for the underlying implementation object.
© 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.