Explicitly Converting from Unicode
Class
RWUFromUnicodeConverter converts text from
UTF-16 to any recognized
character encoding. An instance of this class can be used to convert
code unit sequences that represent characters in the UTF-16
character encoding form into the byte sequences required to represent those characters in a specific character encoding.
RWUString provides a
toBytes() method that accepts an
RWUFromUnicodeConverter instance, and returns an
RWCString containing the byte sequence produced when the contents of the
RWUString are converted using the given converter. For example, assuming
source is an
RWUString:
RWUFromUnicodeConverter toShiftJis("Shift-JIS");
RWCString target = source.toBytes(toShiftJis);
RWUFromUnicodeConverter also provides an explicit
convert() method that accepts UTF-16 source text and a reference to an object to hold the converted byte sequence. For example, assuming
source holds text encoded in UTF-16, this code converts its contents to Shift-JIS and holds the results in a Standard C++ Library string:
RWUFromUnicodeConverter toShiftJis("Shift-JIS");
std::string target;
toShiftJis.convert(source, target);
The
convert() method also accepts a Boolean
flush argument that may be used to flush the internal buffers of a converter and clear its internal state. The default value is
true. See
Explicitly Converting to Unicode for more information.