gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

637 lines
24KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_wchar.h
  4. * multibyte-character support
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/mb/pg_wchar.h
  10. *
  11. * NOTES
  12. * This is used both by the backend and by libpq, but should not be
  13. * included by libpq client programs. In particular, a libpq client
  14. * should not assume that the encoding IDs used by the version of libpq
  15. * it's linked to match up with the IDs declared here.
  16. *
  17. *-------------------------------------------------------------------------
  18. */
  19. #ifndef PG_WCHAR_H
  20. #define PG_WCHAR_H
  21. /*
  22. * The pg_wchar type
  23. */
  24. typedef unsigned int pg_wchar;
  25. /*
  26. * Maximum byte length of multibyte characters in any backend encoding
  27. */
  28. #define MAX_MULTIBYTE_CHAR_LEN 4
  29. /*
  30. * various definitions for EUC
  31. */
  32. #define SS2 0x8e /* single shift 2 (JIS0201) */
  33. #define SS3 0x8f /* single shift 3 (JIS0212) */
  34. /*
  35. * SJIS validation macros
  36. */
  37. #define ISSJISHEAD(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc))
  38. #define ISSJISTAIL(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
  39. /*----------------------------------------------------
  40. * MULE Internal Encoding (MIC)
  41. *
  42. * This encoding follows the design used within XEmacs; it is meant to
  43. * subsume many externally-defined character sets. Each character includes
  44. * identification of the character set it belongs to, so the encoding is
  45. * general but somewhat bulky.
  46. *
  47. * Currently PostgreSQL supports 5 types of MULE character sets:
  48. *
  49. * 1) 1-byte ASCII characters. Each byte is below 0x80.
  50. *
  51. * 2) "Official" single byte charsets such as ISO-8859-1 (Latin1).
  52. * Each MULE character consists of 2 bytes: LC1 + C1, where LC1 is
  53. * an identifier for the charset (in the range 0x81 to 0x8d) and C1
  54. * is the character code (in the range 0xa0 to 0xff).
  55. *
  56. * 3) "Private" single byte charsets such as SISHENG. Each MULE
  57. * character consists of 3 bytes: LCPRV1 + LC12 + C1, where LCPRV1
  58. * is a private-charset flag, LC12 is an identifier for the charset,
  59. * and C1 is the character code (in the range 0xa0 to 0xff).
  60. * LCPRV1 is either 0x9a (if LC12 is in the range 0xa0 to 0xdf)
  61. * or 0x9b (if LC12 is in the range 0xe0 to 0xef).
  62. *
  63. * 4) "Official" multibyte charsets such as JIS X0208. Each MULE
  64. * character consists of 3 bytes: LC2 + C1 + C2, where LC2 is
  65. * an identifier for the charset (in the range 0x90 to 0x99) and C1
  66. * and C2 form the character code (each in the range 0xa0 to 0xff).
  67. *
  68. * 5) "Private" multibyte charsets such as CNS 11643-1992 Plane 3.
  69. * Each MULE character consists of 4 bytes: LCPRV2 + LC22 + C1 + C2,
  70. * where LCPRV2 is a private-charset flag, LC22 is an identifier for
  71. * the charset, and C1 and C2 form the character code (each in the range
  72. * 0xa0 to 0xff). LCPRV2 is either 0x9c (if LC22 is in the range 0xf0
  73. * to 0xf4) or 0x9d (if LC22 is in the range 0xf5 to 0xfe).
  74. *
  75. * "Official" encodings are those that have been assigned code numbers by
  76. * the XEmacs project; "private" encodings have Postgres-specific charset
  77. * identifiers.
  78. *
  79. * See the "XEmacs Internals Manual", available at http://www.xemacs.org,
  80. * for more details. Note that for historical reasons, Postgres'
  81. * private-charset flag values do not match what XEmacs says they should be,
  82. * so this isn't really exactly MULE (not that private charsets would be
  83. * interoperable anyway).
  84. *
  85. * Note that XEmacs's implementation is different from what emacs does.
  86. * We follow emacs's implementation, rather than XEmacs's.
  87. *----------------------------------------------------
  88. */
  89. /*
  90. * Charset identifiers (also called "leading bytes" in the MULE documentation)
  91. */
  92. /*
  93. * Charset IDs for official single byte encodings (0x81-0x8e)
  94. */
  95. #define LC_ISO8859_1 0x81 /* ISO8859 Latin 1 */
  96. #define LC_ISO8859_2 0x82 /* ISO8859 Latin 2 */
  97. #define LC_ISO8859_3 0x83 /* ISO8859 Latin 3 */
  98. #define LC_ISO8859_4 0x84 /* ISO8859 Latin 4 */
  99. #define LC_TIS620 0x85 /* Thai (not supported yet) */
  100. #define LC_ISO8859_7 0x86 /* Greek (not supported yet) */
  101. #define LC_ISO8859_6 0x87 /* Arabic (not supported yet) */
  102. #define LC_ISO8859_8 0x88 /* Hebrew (not supported yet) */
  103. #define LC_JISX0201K 0x89 /* Japanese 1 byte kana */
  104. #define LC_JISX0201R 0x8a /* Japanese 1 byte Roman */
  105. /* Note that 0x8b seems to be unused as of Emacs 20.7.
  106. * However, there might be a chance that 0x8b could be used
  107. * in later versions of Emacs.
  108. */
  109. #define LC_KOI8_R 0x8b /* Cyrillic KOI8-R */
  110. #define LC_ISO8859_5 0x8c /* ISO8859 Cyrillic */
  111. #define LC_ISO8859_9 0x8d /* ISO8859 Latin 5 (not supported yet) */
  112. #define LC_ISO8859_15 0x8e /* ISO8859 Latin 15 (not supported yet) */
  113. /* #define CONTROL_1 0x8f control characters (unused) */
  114. /* Is a leading byte for "official" single byte encodings? */
  115. #define IS_LC1(c) ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
  116. /*
  117. * Charset IDs for official multibyte encodings (0x90-0x99)
  118. * 0x9a-0x9d are free. 0x9e and 0x9f are reserved.
  119. */
  120. #define LC_JISX0208_1978 0x90 /* Japanese Kanji, old JIS (not supported) */
  121. #define LC_GB2312_80 0x91 /* Chinese */
  122. #define LC_JISX0208 0x92 /* Japanese Kanji (JIS X 0208) */
  123. #define LC_KS5601 0x93 /* Korean */
  124. #define LC_JISX0212 0x94 /* Japanese Kanji (JIS X 0212) */
  125. #define LC_CNS11643_1 0x95 /* CNS 11643-1992 Plane 1 */
  126. #define LC_CNS11643_2 0x96 /* CNS 11643-1992 Plane 2 */
  127. #define LC_JISX0213_1 0x97 /* Japanese Kanji (JIS X 0213 Plane 1)
  128. * (not supported) */
  129. #define LC_BIG5_1 0x98 /* Plane 1 Chinese traditional (not
  130. * supported) */
  131. #define LC_BIG5_2 0x99 /* Plane 1 Chinese traditional (not
  132. * supported) */
  133. /* Is a leading byte for "official" multibyte encodings? */
  134. #define IS_LC2(c) ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
  135. /*
  136. * Postgres-specific prefix bytes for "private" single byte encodings
  137. * (According to the MULE docs, we should be using 0x9e for this)
  138. */
  139. #define LCPRV1_A 0x9a
  140. #define LCPRV1_B 0x9b
  141. #define IS_LCPRV1(c) ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)
  142. #define IS_LCPRV1_A_RANGE(c) \
  143. ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf)
  144. #define IS_LCPRV1_B_RANGE(c) \
  145. ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef)
  146. /*
  147. * Postgres-specific prefix bytes for "private" multibyte encodings
  148. * (According to the MULE docs, we should be using 0x9f for this)
  149. */
  150. #define LCPRV2_A 0x9c
  151. #define LCPRV2_B 0x9d
  152. #define IS_LCPRV2(c) ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B)
  153. #define IS_LCPRV2_A_RANGE(c) \
  154. ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4)
  155. #define IS_LCPRV2_B_RANGE(c) \
  156. ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe)
  157. /*
  158. * Charset IDs for private single byte encodings (0xa0-0xef)
  159. */
  160. #define LC_SISHENG 0xa0 /* Chinese SiSheng characters for
  161. * PinYin/ZhuYin (not supported) */
  162. #define LC_IPA 0xa1 /* IPA (International Phonetic
  163. * Association) (not supported) */
  164. #define LC_VISCII_LOWER 0xa2 /* Vietnamese VISCII1.1 lower-case (not
  165. * supported) */
  166. #define LC_VISCII_UPPER 0xa3 /* Vietnamese VISCII1.1 upper-case (not
  167. * supported) */
  168. #define LC_ARABIC_DIGIT 0xa4 /* Arabic digit (not supported) */
  169. #define LC_ARABIC_1_COLUMN 0xa5 /* Arabic 1-column (not supported) */
  170. #define LC_ASCII_RIGHT_TO_LEFT 0xa6 /* ASCII (left half of ISO8859-1) with
  171. * right-to-left direction (not
  172. * supported) */
  173. #define LC_LAO 0xa7 /* Lao characters (ISO10646 0E80..0EDF)
  174. * (not supported) */
  175. #define LC_ARABIC_2_COLUMN 0xa8 /* Arabic 1-column (not supported) */
  176. /*
  177. * Charset IDs for private multibyte encodings (0xf0-0xff)
  178. */
  179. #define LC_INDIAN_1_COLUMN 0xf0 /* Indian charset for 1-column width
  180. * glyphs (not supported) */
  181. #define LC_TIBETAN_1_COLUMN 0xf1 /* Tibetan 1-column width glyphs (not
  182. * supported) */
  183. #define LC_UNICODE_SUBSET_2 0xf2 /* Unicode characters of the range
  184. * U+2500..U+33FF. (not supported) */
  185. #define LC_UNICODE_SUBSET_3 0xf3 /* Unicode characters of the range
  186. * U+E000..U+FFFF. (not supported) */
  187. #define LC_UNICODE_SUBSET 0xf4 /* Unicode characters of the range
  188. * U+0100..U+24FF. (not supported) */
  189. #define LC_ETHIOPIC 0xf5 /* Ethiopic characters (not supported) */
  190. #define LC_CNS11643_3 0xf6 /* CNS 11643-1992 Plane 3 */
  191. #define LC_CNS11643_4 0xf7 /* CNS 11643-1992 Plane 4 */
  192. #define LC_CNS11643_5 0xf8 /* CNS 11643-1992 Plane 5 */
  193. #define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */
  194. #define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */
  195. #define LC_INDIAN_2_COLUMN 0xfb /* Indian charset for 2-column width
  196. * glyphs (not supported) */
  197. #define LC_TIBETAN 0xfc /* Tibetan (not supported) */
  198. /* #define FREE 0xfd free (unused) */
  199. /* #define FREE 0xfe free (unused) */
  200. /* #define FREE 0xff free (unused) */
  201. /*----------------------------------------------------
  202. * end of MULE stuff
  203. *----------------------------------------------------
  204. */
  205. /*
  206. * PostgreSQL encoding identifiers
  207. *
  208. * WARNING: the order of this enum must be same as order of entries
  209. * in the pg_enc2name_tbl[] array (in mb/encnames.c), and
  210. * in the pg_wchar_table[] array (in mb/wchar.c)!
  211. *
  212. * If you add some encoding don't forget to check
  213. * PG_ENCODING_BE_LAST macro.
  214. *
  215. * PG_SQL_ASCII is default encoding and must be = 0.
  216. *
  217. * XXX We must avoid renumbering any backend encoding until libpq's major
  218. * version number is increased beyond 5; it turns out that the backend
  219. * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and
  220. * psql are concerned.
  221. */
  222. typedef enum pg_enc
  223. {
  224. PG_SQL_ASCII = 0, /* SQL/ASCII */
  225. PG_EUC_JP, /* EUC for Japanese */
  226. PG_EUC_CN, /* EUC for Chinese */
  227. PG_EUC_KR, /* EUC for Korean */
  228. PG_EUC_TW, /* EUC for Taiwan */
  229. PG_EUC_JIS_2004, /* EUC-JIS-2004 */
  230. PG_UTF8, /* Unicode UTF8 */
  231. PG_MULE_INTERNAL, /* Mule internal code */
  232. PG_LATIN1, /* ISO-8859-1 Latin 1 */
  233. PG_LATIN2, /* ISO-8859-2 Latin 2 */
  234. PG_LATIN3, /* ISO-8859-3 Latin 3 */
  235. PG_LATIN4, /* ISO-8859-4 Latin 4 */
  236. PG_LATIN5, /* ISO-8859-9 Latin 5 */
  237. PG_LATIN6, /* ISO-8859-10 Latin6 */
  238. PG_LATIN7, /* ISO-8859-13 Latin7 */
  239. PG_LATIN8, /* ISO-8859-14 Latin8 */
  240. PG_LATIN9, /* ISO-8859-15 Latin9 */
  241. PG_LATIN10, /* ISO-8859-16 Latin10 */
  242. PG_WIN1256, /* windows-1256 */
  243. PG_WIN1258, /* Windows-1258 */
  244. PG_WIN866, /* (MS-DOS CP866) */
  245. PG_WIN874, /* windows-874 */
  246. PG_KOI8R, /* KOI8-R */
  247. PG_WIN1251, /* windows-1251 */
  248. PG_WIN1252, /* windows-1252 */
  249. PG_ISO_8859_5, /* ISO-8859-5 */
  250. PG_ISO_8859_6, /* ISO-8859-6 */
  251. PG_ISO_8859_7, /* ISO-8859-7 */
  252. PG_ISO_8859_8, /* ISO-8859-8 */
  253. PG_WIN1250, /* windows-1250 */
  254. PG_WIN1253, /* windows-1253 */
  255. PG_WIN1254, /* windows-1254 */
  256. PG_WIN1255, /* windows-1255 */
  257. PG_WIN1257, /* windows-1257 */
  258. PG_KOI8U, /* KOI8-U */
  259. /* PG_ENCODING_BE_LAST points to the above entry */
  260. /* followings are for client encoding only */
  261. PG_SJIS, /* Shift JIS (Windows-932) */
  262. PG_BIG5, /* Big5 (Windows-950) */
  263. PG_GBK, /* GBK (Windows-936) */
  264. PG_UHC, /* UHC (Windows-949) */
  265. PG_GB18030, /* GB18030 */
  266. PG_JOHAB, /* EUC for Korean JOHAB */
  267. PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
  268. _PG_LAST_ENCODING_ /* mark only */
  269. } pg_enc;
  270. #define PG_ENCODING_BE_LAST PG_KOI8U
  271. /*
  272. * Please use these tests before access to pg_encconv_tbl[]
  273. * or to other places...
  274. */
  275. #define PG_VALID_BE_ENCODING(_enc) \
  276. ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
  277. #define PG_ENCODING_IS_CLIENT_ONLY(_enc) \
  278. ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)
  279. #define PG_VALID_ENCODING(_enc) \
  280. ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
  281. /* On FE are possible all encodings */
  282. #define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc)
  283. /*
  284. * When converting strings between different encodings, we assume that space
  285. * for converted result is 4-to-1 growth in the worst case. The rate for
  286. * currently supported encoding pairs are within 3 (SJIS JIS X0201 half width
  287. * kanna -> UTF8 is the worst case). So "4" should be enough for the moment.
  288. *
  289. * Note that this is not the same as the maximum character width in any
  290. * particular encoding.
  291. */
  292. #define MAX_CONVERSION_GROWTH 4
  293. /*
  294. * Table for mapping an encoding number to official encoding name and
  295. * possibly other subsidiary data. Be careful to check encoding number
  296. * before accessing a table entry!
  297. *
  298. * if (PG_VALID_ENCODING(encoding))
  299. * pg_enc2name_tbl[ encoding ];
  300. */
  301. typedef struct pg_enc2name
  302. {
  303. const char *name;
  304. pg_enc encoding;
  305. #ifdef WIN32
  306. unsigned codepage; /* codepage for WIN32 */
  307. #endif
  308. } pg_enc2name;
  309. extern const pg_enc2name pg_enc2name_tbl[];
  310. /*
  311. * Encoding names for gettext
  312. */
  313. typedef struct pg_enc2gettext
  314. {
  315. pg_enc encoding;
  316. const char *name;
  317. } pg_enc2gettext;
  318. extern const pg_enc2gettext pg_enc2gettext_tbl[];
  319. /*
  320. * Encoding names for ICU
  321. */
  322. extern bool is_encoding_supported_by_icu(int encoding);
  323. extern const char *get_encoding_name_for_icu(int encoding);
  324. /*
  325. * pg_wchar stuff
  326. */
  327. typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
  328. pg_wchar *to,
  329. int len);
  330. typedef int (*wchar2mb_with_len_converter) (const pg_wchar *from,
  331. unsigned char *to,
  332. int len);
  333. typedef int (*mblen_converter) (const unsigned char *mbstr);
  334. typedef int (*mbdisplaylen_converter) (const unsigned char *mbstr);
  335. typedef bool (*mbcharacter_incrementer) (unsigned char *mbstr, int len);
  336. typedef int (*mbverifier) (const unsigned char *mbstr, int len);
  337. typedef struct
  338. {
  339. mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multibyte
  340. * string to a wchar */
  341. wchar2mb_with_len_converter wchar2mb_with_len; /* convert a wchar string
  342. * to a multibyte */
  343. mblen_converter mblen; /* get byte length of a char */
  344. mbdisplaylen_converter dsplen; /* get display width of a char */
  345. mbverifier mbverify; /* verify multibyte sequence */
  346. int maxmblen; /* max bytes for a char in this encoding */
  347. } pg_wchar_tbl;
  348. extern const pg_wchar_tbl pg_wchar_table[];
  349. /*
  350. * Data structures for conversions between UTF-8 and other encodings
  351. * (UtfToLocal() and LocalToUtf()). In these data structures, characters of
  352. * either encoding are represented by uint32 words; hence we can only support
  353. * characters up to 4 bytes long. For example, the byte sequence 0xC2 0x89
  354. * would be represented by 0x0000C289, and 0xE8 0xA2 0xB4 by 0x00E8A2B4.
  355. *
  356. * There are three possible ways a character can be mapped:
  357. *
  358. * 1. Using a radix tree, from source to destination code.
  359. * 2. Using a sorted array of source -> destination code pairs. This
  360. * method is used for "combining" characters. There are so few of
  361. * them that building a radix tree would be wasteful.
  362. * 3. Using a conversion function.
  363. */
  364. /*
  365. * Radix tree for character conversion.
  366. *
  367. * Logically, this is actually four different radix trees, for 1-byte,
  368. * 2-byte, 3-byte and 4-byte inputs. The 1-byte tree is a simple lookup
  369. * table from source to target code. The 2-byte tree consists of two levels:
  370. * one lookup table for the first byte, where the value in the lookup table
  371. * points to a lookup table for the second byte. And so on.
  372. *
  373. * Physically, all the trees are stored in one big array, in 'chars16' or
  374. * 'chars32', depending on the maximum value that needs to be represented. For
  375. * each level in each tree, we also store lower and upper bound of allowed
  376. * values - values outside those bounds are considered invalid, and are left
  377. * out of the tables.
  378. *
  379. * In the intermediate levels of the trees, the values stored are offsets
  380. * into the chars[16|32] array.
  381. *
  382. * In the beginning of the chars[16|32] array, there is always a number of
  383. * zeros, so that you safely follow an index from an intermediate table
  384. * without explicitly checking for a zero. Following a zero any number of
  385. * times will always bring you to the dummy, all-zeros table in the
  386. * beginning. This helps to shave some cycles when looking up values.
  387. */
  388. typedef struct
  389. {
  390. /*
  391. * Array containing all the values. Only one of chars16 or chars32 is
  392. * used, depending on how wide the values we need to represent are.
  393. */
  394. const uint16 *chars16;
  395. const uint32 *chars32;
  396. /* Radix tree for 1-byte inputs */
  397. uint32 b1root; /* offset of table in the chars[16|32] array */
  398. uint8 b1_lower; /* min allowed value for a single byte input */
  399. uint8 b1_upper; /* max allowed value for a single byte input */
  400. /* Radix tree for 2-byte inputs */
  401. uint32 b2root; /* offset of 1st byte's table */
  402. uint8 b2_1_lower; /* min/max allowed value for 1st input byte */
  403. uint8 b2_1_upper;
  404. uint8 b2_2_lower; /* min/max allowed value for 2nd input byte */
  405. uint8 b2_2_upper;
  406. /* Radix tree for 3-byte inputs */
  407. uint32 b3root; /* offset of 1st byte's table */
  408. uint8 b3_1_lower; /* min/max allowed value for 1st input byte */
  409. uint8 b3_1_upper;
  410. uint8 b3_2_lower; /* min/max allowed value for 2nd input byte */
  411. uint8 b3_2_upper;
  412. uint8 b3_3_lower; /* min/max allowed value for 3rd input byte */
  413. uint8 b3_3_upper;
  414. /* Radix tree for 4-byte inputs */
  415. uint32 b4root; /* offset of 1st byte's table */
  416. uint8 b4_1_lower; /* min/max allowed value for 1st input byte */
  417. uint8 b4_1_upper;
  418. uint8 b4_2_lower; /* min/max allowed value for 2nd input byte */
  419. uint8 b4_2_upper;
  420. uint8 b4_3_lower; /* min/max allowed value for 3rd input byte */
  421. uint8 b4_3_upper;
  422. uint8 b4_4_lower; /* min/max allowed value for 4th input byte */
  423. uint8 b4_4_upper;
  424. } pg_mb_radix_tree;
  425. /*
  426. * UTF-8 to local code conversion map (for combined characters)
  427. */
  428. typedef struct
  429. {
  430. uint32 utf1; /* UTF-8 code 1 */
  431. uint32 utf2; /* UTF-8 code 2 */
  432. uint32 code; /* local code */
  433. } pg_utf_to_local_combined;
  434. /*
  435. * local code to UTF-8 conversion map (for combined characters)
  436. */
  437. typedef struct
  438. {
  439. uint32 code; /* local code */
  440. uint32 utf1; /* UTF-8 code 1 */
  441. uint32 utf2; /* UTF-8 code 2 */
  442. } pg_local_to_utf_combined;
  443. /*
  444. * callback function for algorithmic encoding conversions (in either direction)
  445. *
  446. * if function returns zero, it does not know how to convert the code
  447. */
  448. typedef uint32 (*utf_local_conversion_func) (uint32 code);
  449. /*
  450. * Support macro for encoding conversion functions to validate their
  451. * arguments. (This could be made more compact if we included fmgr.h
  452. * here, but we don't want to do that because this header file is also
  453. * used by frontends.)
  454. */
  455. #define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
  456. check_encoding_conversion_args(PG_GETARG_INT32(0), \
  457. PG_GETARG_INT32(1), \
  458. PG_GETARG_INT32(4), \
  459. (srcencoding), \
  460. (destencoding))
  461. /*
  462. * These functions are considered part of libpq's exported API and
  463. * are also declared in libpq-fe.h.
  464. */
  465. extern int pg_char_to_encoding(const char *name);
  466. extern const char *pg_encoding_to_char(int encoding);
  467. extern int pg_valid_server_encoding_id(int encoding);
  468. /*
  469. * Remaining functions are not considered part of libpq's API, though many
  470. * of them do exist inside libpq.
  471. */
  472. extern int pg_mb2wchar(const char *from, pg_wchar *to);
  473. extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
  474. extern int pg_encoding_mb2wchar_with_len(int encoding,
  475. const char *from, pg_wchar *to, int len);
  476. extern int pg_wchar2mb(const pg_wchar *from, char *to);
  477. extern int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len);
  478. extern int pg_encoding_wchar2mb_with_len(int encoding,
  479. const pg_wchar *from, char *to, int len);
  480. extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
  481. extern int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n);
  482. extern int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n);
  483. extern size_t pg_wchar_strlen(const pg_wchar *wstr);
  484. extern int pg_mblen(const char *mbstr);
  485. extern int pg_dsplen(const char *mbstr);
  486. extern int pg_encoding_mblen(int encoding, const char *mbstr);
  487. extern int pg_encoding_dsplen(int encoding, const char *mbstr);
  488. extern int pg_encoding_verifymb(int encoding, const char *mbstr, int len);
  489. extern int pg_mule_mblen(const unsigned char *mbstr);
  490. extern int pg_mic_mblen(const unsigned char *mbstr);
  491. extern int pg_mbstrlen(const char *mbstr);
  492. extern int pg_mbstrlen_with_len(const char *mbstr, int len);
  493. extern int pg_mbcliplen(const char *mbstr, int len, int limit);
  494. extern int pg_encoding_mbcliplen(int encoding, const char *mbstr,
  495. int len, int limit);
  496. extern int pg_mbcharcliplen(const char *mbstr, int len, int imit);
  497. extern int pg_encoding_max_length(int encoding);
  498. extern int pg_database_encoding_max_length(void);
  499. extern mbcharacter_incrementer pg_database_encoding_character_incrementer(void);
  500. extern int PrepareClientEncoding(int encoding);
  501. extern int SetClientEncoding(int encoding);
  502. extern void InitializeClientEncoding(void);
  503. extern int pg_get_client_encoding(void);
  504. extern const char *pg_get_client_encoding_name(void);
  505. extern void SetDatabaseEncoding(int encoding);
  506. extern int GetDatabaseEncoding(void);
  507. extern const char *GetDatabaseEncodingName(void);
  508. extern void SetMessageEncoding(int encoding);
  509. extern int GetMessageEncoding(void);
  510. #ifdef ENABLE_NLS
  511. extern int pg_bind_textdomain_codeset(const char *domainname);
  512. #endif
  513. extern int pg_valid_client_encoding(const char *name);
  514. extern int pg_valid_server_encoding(const char *name);
  515. extern unsigned char *unicode_to_utf8(pg_wchar c, unsigned char *utf8string);
  516. extern pg_wchar utf8_to_unicode(const unsigned char *c);
  517. extern int pg_utf_mblen(const unsigned char *);
  518. extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
  519. int src_encoding,
  520. int dest_encoding);
  521. extern char *pg_client_to_server(const char *s, int len);
  522. extern char *pg_server_to_client(const char *s, int len);
  523. extern char *pg_any_to_server(const char *s, int len, int encoding);
  524. extern char *pg_server_to_any(const char *s, int len, int encoding);
  525. extern unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc);
  526. extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc);
  527. extern void UtfToLocal(const unsigned char *utf, int len,
  528. unsigned char *iso,
  529. const pg_mb_radix_tree *map,
  530. const pg_utf_to_local_combined *cmap, int cmapsize,
  531. utf_local_conversion_func conv_func,
  532. int encoding);
  533. extern void LocalToUtf(const unsigned char *iso, int len,
  534. unsigned char *utf,
  535. const pg_mb_radix_tree *map,
  536. const pg_local_to_utf_combined *cmap, int cmapsize,
  537. utf_local_conversion_func conv_func,
  538. int encoding);
  539. extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
  540. extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
  541. bool noError);
  542. extern int pg_verify_mbstr_len(int encoding, const char *mbstr, int len,
  543. bool noError);
  544. extern void check_encoding_conversion_args(int src_encoding,
  545. int dest_encoding,
  546. int len,
  547. int expected_src_encoding,
  548. int expected_dest_encoding);
  549. extern void report_invalid_encoding(int encoding, const char *mbstr, int len) pg_attribute_noreturn();
  550. extern void report_untranslatable_char(int src_encoding, int dest_encoding,
  551. const char *mbstr, int len) pg_attribute_noreturn();
  552. extern void local2local(const unsigned char *l, unsigned char *p, int len,
  553. int src_encoding, int dest_encoding, const unsigned char *tab);
  554. extern void pg_ascii2mic(const unsigned char *l, unsigned char *p, int len);
  555. extern void pg_mic2ascii(const unsigned char *mic, unsigned char *p, int len);
  556. extern void latin2mic(const unsigned char *l, unsigned char *p, int len,
  557. int lc, int encoding);
  558. extern void mic2latin(const unsigned char *mic, unsigned char *p, int len,
  559. int lc, int encoding);
  560. extern void latin2mic_with_table(const unsigned char *l, unsigned char *p,
  561. int len, int lc, int encoding,
  562. const unsigned char *tab);
  563. extern void mic2latin_with_table(const unsigned char *mic, unsigned char *p,
  564. int len, int lc, int encoding,
  565. const unsigned char *tab);
  566. extern bool pg_utf8_islegal(const unsigned char *source, int length);
  567. #ifdef WIN32
  568. extern WCHAR *pgwin32_message_to_UTF16(const char *str, int len, int *utf16len);
  569. #endif
  570. #endif /* PG_WCHAR_H */
上海开阖软件有限公司 沪ICP备12045867号-1