diff options
Diffstat (limited to 'cpp/include/IceUtil/Unicode.h')
-rw-r--r-- | cpp/include/IceUtil/Unicode.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cpp/include/IceUtil/Unicode.h b/cpp/include/IceUtil/Unicode.h index 366e673b220..8e85c93b49e 100644 --- a/cpp/include/IceUtil/Unicode.h +++ b/cpp/include/IceUtil/Unicode.h @@ -82,6 +82,49 @@ ICE_UTIL_API std::wstring stringToWstring(const std::string&); #endif + +// +// Converts UTF-8 byte-sequences to and from UTF-16 or UTF-32 (with native +// endianness) depending on sizeof(wchar_t). +// +// These are thin wrappers over the UTF8/16/32 converters provided by +// unicode.org +// +// +// TODO: provide the same support for /Zc:wchar_t as the functions above +// + +enum ConversionResult +{ + conversionOK, /* conversion successful */ + sourceExhausted, /* partial character in source, but hit end */ + targetExhausted, /* insuff. room in target for conversion */ + sourceIllegal /* source sequence is illegal/malformed */ +}; + +enum ConversionFlags +{ + strictConversion = 0, + lenientConversion +}; + +typedef unsigned char Byte; + +ICE_UTIL_API bool +isLegalUTF8Sequence(const Byte* source, const Byte* end); + +ICE_UTIL_API ConversionResult +convertUTFWstringToUTF8(const wchar_t*& sourceStart, const wchar_t* sourceEnd, + Byte*& targetStart, Byte* targetEnd, ConversionFlags flags); + +ICE_UTIL_API ConversionResult +convertUTF8ToUTFWstring(const Byte*& sourceStart, const Byte* sourceEnd, + wchar_t*& targetStart, wchar_t* targetEnd, ConversionFlags flags); + +ICE_UTIL_API ConversionResult +convertUTF8ToUTFWstring(const Byte*& sourceStart, const Byte* sourceEnd, + std::wstring& target, ConversionFlags flags); + } #endif |