diff options
Diffstat (limited to 'ACEXML/common/Transcode.h')
-rw-r--r-- | ACEXML/common/Transcode.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ACEXML/common/Transcode.h b/ACEXML/common/Transcode.h new file mode 100644 index 00000000000..8547921aca3 --- /dev/null +++ b/ACEXML/common/Transcode.h @@ -0,0 +1,74 @@ +// -*- C++ -*- $Id$ +// This file declares functions to convert char string among different +// unicode encoding (utf8, utf16, utf32) + +#ifndef _ACEXML_TRANSCODE_H_ +#define _ACEXML_TRANSCODE_H_ +#include "Common/XML_Types.h" + +class ACEXML_Export ACEXML_Transcoder +{ +public: + enum + { + SUCCESS = 0, + DESTINATION_TOO_SHORT = -1, + END_OF_SOURCE = -2, + INVALID_ARGS = -3, + IS_SURROGATE = -4, + NON_UNICODE = -5 + }; + + + // The following functions translate a unicode characters + // into different encoding. Return number of characters put into + // destination or consumed from src if success without + // error, otherwise, return corresponding error code. + static int utf162utf8 (ACEXML_UTF16 src, + ACEXML_UTF8 *dst, + size_t len); + + static int ucs42utf8 (ACEXML_UCS4 src, + ACEXML_UTF8 *dst, + size_t len); + + static int ucs42utf16 (ACEXML_UCS4 src, + ACEXML_UTF16 *dst, + size_t len); + + static int surrogate2utf8 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UTF8 *dst, + size_t len); + + static int surrogate2ucs4 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UCS4 &dst); + + static int utf82ucs4 (const ACEXML_UTF8 *src, + size_t len, + ACEXML_UCS4 &dst); + + static int utf162ucs4 (const ACEXML_UTF16 *src, + size_t len, + ACEXML_UCS4 &dst); + +// static int utf82utf16 (const ACEXML_UTF8 *src, +// size_t len, +// ACEXML_UTF16 &dst); + // This function does not handle surrogates. + + // The following functions are non-inlined: + static int utf8s2utf16s (const ACEXML_UTF8 *src, + ACEXML_UTF16 *dst, + size_t len); + + static int utf16s2utf8s (const ACEXML_UTF16 *src, + ACEXML_UTF8 *dst, + size_t len); +}; + +#if defined (__ACEXML_INLINE__) +# include "Common/Transcode.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_TRANSCODE_H_ */ |