3 //=============================================================================
7 * This file declares functions to convert char string among different
8 * unicode encoding (utf8, utf16, utf32)
10 * @author Nanbor Wang <nanbor@cs.wustl.edu>
12 //=============================================================================
14 #ifndef _ACEXML_TRANSCODE_H_
15 #define _ACEXML_TRANSCODE_H_
17 #include /**/ "ace/pre.h"
18 #include "ACEXML/common/ACEXML_Export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ACEXML/common/XML_Types.h"
27 * @class ACEXML_Transcoder
29 * @brief ACEXML_Transcoder
31 * Wrapper class for performing transcoding among different UNICODE
34 class ACEXML_Export ACEXML_Transcoder
38 * Status of the conversion function.
43 ACEXML_DESTINATION_TOO_SHORT
= -1,
44 ACEXML_END_OF_SOURCE
= -2,
45 ACEXML_INVALID_ARGS
= -3,
46 ACEXML_IS_SURROGATE
= -4,
47 ACEXML_NON_UNICODE
= -5
51 // The following functions translate a unicode characters
52 // into different encoding. Return number of characters put into
53 // destination or consumed from src if success without
54 // error, otherwise, return corresponding error code.
56 * Convert a UTF-16 character into a string in UTF-8 encoding.
58 * @return number of characters the function uses to store the
59 * converted string if it succeeds or one of the error STATUS
62 static int utf162utf8 (ACEXML_UTF16 src
,
67 * Convert a UCS-4 character into a string in UTF-8 encoding.
69 * @return number of characters the function uses to store the
70 * converted string if it succeeds or one of the error STATUS
73 static int ucs42utf8 (ACEXML_UCS4 src
,
78 * Convert a UCS-4 character into a string in UTF-16 encoding.
80 * @return number of characters the function uses to store the
81 * converted string if it succeeds or one of the error STATUS
84 static int ucs42utf16 (ACEXML_UCS4 src
,
89 * Convert a UTF-16 surrogate character pair into a string in UTF-8 encoding.
91 * @return number of characters the function uses to store the
92 * converted string if it succeeds or one of the error STATUS
95 static int surrogate2utf8 (ACEXML_UTF16 high
,
101 * Convert a UTF-16 surrogate character pair into a UCS-4 character.
103 * @return SUCCESS if it succeeds or one of the error STATUS
106 static int surrogate2ucs4 (ACEXML_UTF16 high
,
111 * Convert the first UNICODE character in a UTF-8 character string
112 * into a UCS-4 character.
114 * @return number of characters the function consumed from the
115 * UTF-8 string if it succeeds or one of the error STATUS
118 static int utf82ucs4 (const ACEXML_UTF8
*src
,
123 * Convert the first UNICODE character in a UTF-16 character string
124 * into a UCS-4 character.
126 * @return number of characters the function consumed from the
127 * UTF-16 string if it succeeds or one of the error STATUS
130 static int utf162ucs4 (const ACEXML_UTF16
*src
,
134 // static int utf82utf16 (const ACEXML_UTF8 *src,
136 // ACEXML_UTF16 &dst);
137 // This function does not handle surrogates.
139 // = The following functions are non-inlined:
142 * Convert a UTF-8 string into a UTF-16 string.
144 * @param len The length of @a dst string.
146 * @return number of characters the function consumed from the
147 * UTF-8 string if it succeeds or one of the error STATUS
150 static int utf8s2utf16s (const ACEXML_UTF8
*src
,
155 * Convert a UTF-16 string into a UTF-8 string.
157 * @param len The length of @a dst string.
159 * @return number of characters the function uses in
160 * UTF-8 string if it succeeds or one of the error STATUS
163 static int utf16s2utf8s (const ACEXML_UTF16
*src
,
168 #include /**/ "ace/post.h"
170 #endif /* _ACEXML_TRANSCODE_H_ */