The IceUtil namespace contains two helper functions that allow you to convert between wide strings containing Unicode characters (either 16‑ or 32‑bit, depending on your native
wchar_t size) and narrow strings in UTF‑8 encoding:
These functions always convert to and from UTF‑8 encoding, that is, they ignore any locale setting that might specify a different encoding.
Byte sequence that are illegal, such as 0xF4908080, result in a
UTFConversionException. For other errors, the
ConversionFlags parameter determines how rigorously the functions check for errors. When set to
lenientConversion (the default), the functions tolerate isolated surrogates and irregular sequences, and substitute the UTF‑32 replacement character
0x0000FFFD for character values above
0x10FFFF. When set to
strictConversion, the functions do not tolerate such errors and throw a
UTFConversionException instead:
The conversionError member function returns the reason for the failure: