The C++98 iconv String Converter
For Linux, macOS and Unix platforms, Ice
provides a string converter implementation that uses the iconv
conversion facility to convert between the native encoding and UTF-8.
To use this string converter, you specify whether the conversion you want is for narrow or wide characters via the template argument, and you specify the corresponding native encoding with the constructor argument. For example, to create a converter that converts between ISO Latin-1 and UTF-8, you can instantiate the converter as follows:
StringConverterPtr stringConverter = Ice::createIconvStringConverter<char>("ISO-8859-1");
Similarly, to convert between the internal wide character encoding and UTF-8, you can instantiate a converter as follows:
WstringConverterPtr wstringConverter = Ice::createIconvStringConverter<wchar_t>("WCHAR_T");
The string you pass to the factory function must be one of the values returned by iconv -l
, which lists all the available character encodings for your machine. Passing no parameter or an empty string is equivalent to passing nl_langinfo(CODESET).