unicode.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*! \addtogroup UNICODE
  2. * @{
  3. */
  4. /*!
  5. *
  6. * @file unicode.h
  7. *
  8. * @brief This file specifies the Unicode translation APIs
  9. *
  10. * @note Copyright (c) 2009 Sunplus Technology Co., Ltd. \n
  11. * All rights reserved.
  12. *
  13. * @author
  14. *
  15. ******************************************************************************/
  16. #ifndef __UNICODE_CODE_PAGE_H__
  17. #define __UNICODE_CODE_PAGE_H__
  18. /******************************************************************************/
  19. /*!
  20. * @brief Enumeration of all supported Unicode code pages
  21. *
  22. * @note Because codepages BIG5 and GB2312 can be replaced with CP950 and CP936,
  23. * BIG5 and GB2312 codepages are removed.
  24. * But uiDesign tool has used name "BIG5" and "GB2312" in its codebase,
  25. * it is not suggested to remove these two codepage name here. (by mandy.wu)
  26. * Everyone is still able to use these 2 codepages, but it will be transferred
  27. * to call CP950 and CP936 translations inside UNI_Utf162Chr() and UNI_Chr2Utf16() APIs.
  28. * -- nicholas.lin 09-09-09
  29. *******************************************************************************/
  30. typedef enum
  31. {
  32. CP_437 = 0, // 0
  33. CP_932, // 1
  34. CP_936, // 2
  35. CP_950, // 3
  36. CP_1250, // 4
  37. CP_1251, // 5
  38. CP_1252, // 6
  39. CP_1253, // 7
  40. CP_1254, // 8
  41. CP_1255, // 9
  42. CP_1256, // 10
  43. CP_1257, // 11
  44. CP_1258, // 12
  45. CP_8256, // 13
  46. CP_8257, // 14
  47. CP_8258, // 15
  48. BIG5, // 16
  49. GB2312, // 17
  50. KSC5601, // 18
  51. ISO6937, // 19
  52. ISO8859_1, // 20
  53. ISO8859_2, // 21
  54. ISO8859_3, // 22
  55. ISO8859_4, // 23
  56. ISO8859_5, // 24
  57. ISO8859_6, // 25
  58. ISO8859_7, // 26
  59. ISO8859_8, // 27
  60. ISO8859_9, // 28
  61. ISO8859_10, // 29
  62. ISO8859_11, // 30
  63. ISO8859_12, // 31
  64. ISO8859_13, // 32
  65. ISO8859_14, // 33
  66. ISO8859_15, // 34
  67. ISO8859_16, // 35
  68. UTF8, // 36
  69. UNICODE, // 37
  70. UTF16_LE, //38
  71. UTF16_BE, //39
  72. CP_874, // 40
  73. CODE_PAGE_MAX //ENCODETYPE_AUTO
  74. }UNICODE_SUPPORT_CODE_PAGE;
  75. /*!
  76. * @defgroup Unicode Unicode character and string translation APIs
  77. * @brief Unicode Unicode character and string translation APIs
  78. * @{
  79. */
  80. /******************************************************************************/
  81. /*!
  82. * @brief Translation from unicode(UTF-16) to native code
  83. *
  84. * @param codepage native code page
  85. * @param uni source unicode character
  86. * @param out output native code character
  87. *
  88. * @return @a length of output native code character in bytes
  89. * @return @a -1 on failure
  90. *
  91. * @note Use UINT16 array to store unicode strings instead of UINT8 array
  92. *******************************************************************************/
  93. INT32 UNI_Utf162Chr(const UINT32 codepage, const UINT16 uni, UINT8 *out);
  94. /******************************************************************************/
  95. /*!
  96. * @brief Translation from native code to unicode(UTF-16)
  97. *
  98. * @param codepage native code page
  99. * @param rawchr source native code character
  100. * @param uni output unicode character
  101. *
  102. * @return @a length of output unicodecode character in bytes
  103. * @return @a -1 on failure
  104. *
  105. * @note Use UINT16 array to store unicode strings instead of UINT8 array
  106. *******************************************************************************/
  107. INT32 UNI_Chr2Utf16(const UINT32 codepage, const UINT8 *rawchr, UINT16 *uni);
  108. /******************************************************************************/
  109. /*!
  110. * @brief Translate a UTF-16 coded string to UTF-8 coded string
  111. *
  112. * @param src pointer of source UTF-16 coded string
  113. * @param srcLen string length of source UTF-16 coded string in dual-bytes.
  114. * @param dest pointer to destination UTF-8 coded string
  115. * @param destLen return value of string length of destination UTF-8 coded string in bytes
  116. *
  117. * @return @a 0 on success
  118. * @return @a -1 on failure
  119. *
  120. * @note Use UINT16 array to store UTF-16 strings instead of UINT8 array;
  121. * @note currently we can only process 16-bit length UTF-16 string;
  122. *******************************************************************************/
  123. INT32 UNI_Utf16S2Utf8S(const UINT16 *src, const UINT32 srcLen, UINT8 *dest, UINT32 *destLen);
  124. /******************************************************************************/
  125. /*!
  126. * @brief Translate a UTF-8 coded string to UTF-16 coded string
  127. *
  128. * @param src pointer of source UTF-8 coded string
  129. * @param srcLen string length of source UTF-8 coded string in bytes.
  130. * @param dest pointer to destination UTF-16 coded string
  131. * @param destLen return value of string length of destination UTF-16 coded string in dual-bytes
  132. *
  133. * @return @a 0 on success
  134. * @return @a -1 on failure
  135. *
  136. * @note Use UINT16 array to store UTF-16 strings instead of UINT8 array;
  137. * @note currently we can only process 16-bit length UTF-16 string;
  138. *******************************************************************************/
  139. INT32 UNI_Utf8S2Utf16S(const UINT8 *src, const UINT32 srcLen, UINT16 *dest, UINT32 *destLen);
  140. /******************************************************************************/
  141. /*!
  142. * @brief Translation from UTF-16 character to UTF-8 character
  143. *
  144. * @param utf16 source UTF-16 character
  145. * @param utf8 output UTF-8 character
  146. *
  147. * @return @a length of output UTF-8 character in bytes
  148. * @return @a -1 on failure
  149. *
  150. * @note Use UINT16 array to store UTF-16 strings instead of UINT8 array
  151. *******************************************************************************/
  152. INT32 UNI_Utf162Utf8(const UINT16 utf16, UINT8 *utf8);
  153. /******************************************************************************/
  154. /*!
  155. * @brief Translation from UTF-8 character to UTF-16 character
  156. *
  157. * @param utf8 source UTF-8 character
  158. * @param utf16 output UTF-16 character
  159. *
  160. * @return @a length of source UTF-8 character in bytes
  161. * @return @a -1 on failure
  162. *
  163. * @note Use UINT16 array to store UTF-16 strings instead of UINT8 array
  164. *******************************************************************************/
  165. INT32 UNI_Utf82Utf16(const UINT8 *utf8, UINT16 *utf16);
  166. #ifdef CONFIG_SUPPORT_CHARSETDET
  167. /******************************************************************************/
  168. /*!
  169. * @brief Guess a codepage by a raw character stream
  170. *
  171. * @param rawchr raw character stream
  172. * @param size of raw character stream
  173. *
  174. * @return guessed code page number
  175. *******************************************************************************/
  176. UINT32 UNI_GuessCodePage(const UINT8 *rawchr, UINT32 size);
  177. UINT32 UNI_FontType2CodePage(UINT32 font);
  178. #endif
  179. UINT8* UNI_StringToUtf8(UINT32 codepage, UINT8* string_ptr, INT32* len_ptr, bool skip_ctrl);
  180. void UNI_GetUTF8EncodeSize(UINT8 *pString, UINT16 *pEncodeSize);
  181. UINT8* UNI_SetUTF8Position(UINT8 *pString, INT32 *pLen, UINT32 *pPosition);
  182. INT32 UNI_GetCodePage(UINT32 *pCodePage, UINT8 *rawchr, INT32 *size);
  183. /*! @} end of defgroup Unicode */
  184. #endif // __UNICODE_CODE_PAGE_H__
  185. /*! @} end of addtogroup UNICODE */