Converting RWWStrings to and from UTF-8
RWBasicUString does not provide a complete
RWWString or
wchar_t interface. (Its method
towide() converts from UTF-16 to an
RWWString, but it does not take a
wchar_t and return a Unicode UTF-16 string.)
To perform these wide character conversions, you may use the UTF-8 converter classes provided in the Advanced Tools Module’s Stream package.
From UTF-8 to a UTF-16 Wide Character
To convert from a UTF-8 encoded
RWCString to a UTF-16 encoded
RWWString, use
RWFromUTF8Converter as shown in this example.
RWWString destination; // 1
RWCString source(“My UTF8 characters”);
RWFromUTF8Converter converter; // 2
converter.convert(source,destination); // 3
From a UTF-16 Wide Character to UTF-8
To convert from a UTF-16 encoded
RWWString to a UTF-8 encoded
RWCString, use
RWToUTF8Converter as shown in this example.
RWWString newSource(”My UTF16 characters”);
RWCString newDestination; // 1
RWToUTF8Converter converter; // 2
converter.convert(newSource,newDestination); // 3
NOTE: Note that these wide character conversions are suitable only on systems where wchar_t’s native encoding is UTF-16.