pg_wchar.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_wchar.h
  4. * multibyte-character support
  5. *
  6. * Portions Copyright (c) 1996-2016, 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) (not
  128. * supported) */
  129. #define LC_BIG5_1 0x98 /* Plane 1 Chinese traditional (not supported) */
  130. #define LC_BIG5_2 0x99 /* Plane 1 Chinese traditional (not supported) */
  131. /* Is a leading byte for "official" multibyte encodings? */
  132. #define IS_LC2(c) ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
  133. /*
  134. * Postgres-specific prefix bytes for "private" single byte encodings
  135. * (According to the MULE docs, we should be using 0x9e for this)
  136. */
  137. #define LCPRV1_A 0x9a
  138. #define LCPRV1_B 0x9b
  139. #define IS_LCPRV1(c) ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)
  140. #define IS_LCPRV1_A_RANGE(c) \
  141. ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf)
  142. #define IS_LCPRV1_B_RANGE(c) \
  143. ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef)
  144. /*
  145. * Postgres-specific prefix bytes for "private" multibyte encodings
  146. * (According to the MULE docs, we should be using 0x9f for this)
  147. */
  148. #define LCPRV2_A 0x9c
  149. #define LCPRV2_B 0x9d
  150. #define IS_LCPRV2(c) ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B)
  151. #define IS_LCPRV2_A_RANGE(c) \
  152. ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4)
  153. #define IS_LCPRV2_B_RANGE(c) \
  154. ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe)
  155. /*
  156. * Charset IDs for private single byte encodings (0xa0-0xef)
  157. */
  158. #define LC_SISHENG 0xa0/* Chinese SiSheng characters for
  159. * PinYin/ZhuYin (not supported) */
  160. #define LC_IPA 0xa1/* IPA (International Phonetic Association)
  161. * (not supported) */
  162. #define LC_VISCII_LOWER 0xa2/* Vietnamese VISCII1.1 lower-case (not
  163. * supported) */
  164. #define LC_VISCII_UPPER 0xa3/* Vietnamese VISCII1.1 upper-case (not
  165. * supported) */
  166. #define LC_ARABIC_DIGIT 0xa4 /* Arabic digit (not supported) */
  167. #define LC_ARABIC_1_COLUMN 0xa5 /* Arabic 1-column (not supported) */
  168. #define LC_ASCII_RIGHT_TO_LEFT 0xa6 /* ASCII (left half of ISO8859-1) with
  169. * right-to-left direction (not
  170. * supported) */
  171. #define LC_LAO 0xa7/* Lao characters (ISO10646 0E80..0EDF) (not
  172. * supported) */
  173. #define LC_ARABIC_2_COLUMN 0xa8 /* Arabic 1-column (not supported) */
  174. /*
  175. * Charset IDs for private multibyte encodings (0xf0-0xff)
  176. */
  177. #define LC_INDIAN_1_COLUMN 0xf0/* Indian charset for 1-column width glyphs
  178. * (not supported) */
  179. #define LC_TIBETAN_1_COLUMN 0xf1/* Tibetan 1-column width glyphs (not
  180. * supported) */
  181. #define LC_UNICODE_SUBSET_2 0xf2/* Unicode characters of the range
  182. * U+2500..U+33FF. (not supported) */
  183. #define LC_UNICODE_SUBSET_3 0xf3/* Unicode characters of the range
  184. * U+E000..U+FFFF. (not supported) */
  185. #define LC_UNICODE_SUBSET 0xf4/* Unicode characters of the range
  186. * U+0100..U+24FF. (not supported) */
  187. #define LC_ETHIOPIC 0xf5 /* Ethiopic characters (not supported) */
  188. #define LC_CNS11643_3 0xf6 /* CNS 11643-1992 Plane 3 */
  189. #define LC_CNS11643_4 0xf7 /* CNS 11643-1992 Plane 4 */
  190. #define LC_CNS11643_5 0xf8 /* CNS 11643-1992 Plane 5 */
  191. #define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */
  192. #define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */
  193. #define LC_INDIAN_2_COLUMN 0xfb/* Indian charset for 2-column width glyphs
  194. * (not supported) */
  195. #define LC_TIBETAN 0xfc /* Tibetan (not supported) */
  196. /* #define FREE 0xfd free (unused) */
  197. /* #define FREE 0xfe free (unused) */
  198. /* #define FREE 0xff free (unused) */
  199. /*----------------------------------------------------
  200. * end of MULE stuff
  201. *----------------------------------------------------
  202. */
  203. /*
  204. * PostgreSQL encoding identifiers
  205. *
  206. * WARNING: the order of this enum must be same as order of entries
  207. * in the pg_enc2name_tbl[] array (in mb/encnames.c), and
  208. * in the pg_wchar_table[] array (in mb/wchar.c)!
  209. *
  210. * If you add some encoding don't forget to check
  211. * PG_ENCODING_BE_LAST macro.
  212. *
  213. * PG_SQL_ASCII is default encoding and must be = 0.
  214. *
  215. * XXX We must avoid renumbering any backend encoding until libpq's major
  216. * version number is increased beyond 5; it turns out that the backend
  217. * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and
  218. * psql are concerned.
  219. */
  220. typedef enum pg_enc
  221. {
  222. PG_SQL_ASCII = 0, /* SQL/ASCII */
  223. PG_EUC_JP, /* EUC for Japanese */
  224. PG_EUC_CN, /* EUC for Chinese */
  225. PG_EUC_KR, /* EUC for Korean */
  226. PG_EUC_TW, /* EUC for Taiwan */
  227. PG_EUC_JIS_2004, /* EUC-JIS-2004 */
  228. PG_UTF8, /* Unicode UTF8 */
  229. PG_MULE_INTERNAL, /* Mule internal code */
  230. PG_LATIN1, /* ISO-8859-1 Latin 1 */
  231. PG_LATIN2, /* ISO-8859-2 Latin 2 */
  232. PG_LATIN3, /* ISO-8859-3 Latin 3 */
  233. PG_LATIN4, /* ISO-8859-4 Latin 4 */
  234. PG_LATIN5, /* ISO-8859-9 Latin 5 */
  235. PG_LATIN6, /* ISO-8859-10 Latin6 */
  236. PG_LATIN7, /* ISO-8859-13 Latin7 */
  237. PG_LATIN8, /* ISO-8859-14 Latin8 */
  238. PG_LATIN9, /* ISO-8859-15 Latin9 */
  239. PG_LATIN10, /* ISO-8859-16 Latin10 */
  240. PG_WIN1256, /* windows-1256 */
  241. PG_WIN1258, /* Windows-1258 */
  242. PG_WIN866, /* (MS-DOS CP866) */
  243. PG_WIN874, /* windows-874 */
  244. PG_KOI8R, /* KOI8-R */
  245. PG_WIN1251, /* windows-1251 */
  246. PG_WIN1252, /* windows-1252 */
  247. PG_ISO_8859_5, /* ISO-8859-5 */
  248. PG_ISO_8859_6, /* ISO-8859-6 */
  249. PG_ISO_8859_7, /* ISO-8859-7 */
  250. PG_ISO_8859_8, /* ISO-8859-8 */
  251. PG_WIN1250, /* windows-1250 */
  252. PG_WIN1253, /* windows-1253 */
  253. PG_WIN1254, /* windows-1254 */
  254. PG_WIN1255, /* windows-1255 */
  255. PG_WIN1257, /* windows-1257 */
  256. PG_KOI8U, /* KOI8-U */
  257. /* PG_ENCODING_BE_LAST points to the above entry */
  258. /* followings are for client encoding only */
  259. PG_SJIS, /* Shift JIS (Windows-932) */
  260. PG_BIG5, /* Big5 (Windows-950) */
  261. PG_GBK, /* GBK (Windows-936) */
  262. PG_UHC, /* UHC (Windows-949) */
  263. PG_GB18030, /* GB18030 */
  264. PG_JOHAB, /* EUC for Korean JOHAB */
  265. PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
  266. _PG_LAST_ENCODING_ /* mark only */
  267. } pg_enc;
  268. #define PG_ENCODING_BE_LAST PG_KOI8U
  269. /*
  270. * Please use these tests before access to pg_encconv_tbl[]
  271. * or to other places...
  272. */
  273. #define PG_VALID_BE_ENCODING(_enc) \
  274. ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
  275. #define PG_ENCODING_IS_CLIENT_ONLY(_enc) \
  276. ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)
  277. #define PG_VALID_ENCODING(_enc) \
  278. ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
  279. /* On FE are possible all encodings */
  280. #define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc)
  281. /*
  282. * Table for mapping an encoding number to official encoding name and
  283. * possibly other subsidiary data. Be careful to check encoding number
  284. * before accessing a table entry!
  285. *
  286. * if (PG_VALID_ENCODING(encoding))
  287. * pg_enc2name_tbl[ encoding ];
  288. */
  289. typedef struct pg_enc2name
  290. {
  291. const char *name;
  292. pg_enc encoding;
  293. #ifdef WIN32
  294. unsigned codepage; /* codepage for WIN32 */
  295. #endif
  296. } pg_enc2name;
  297. extern const pg_enc2name pg_enc2name_tbl[];
  298. /*
  299. * Encoding names for gettext
  300. */
  301. typedef struct pg_enc2gettext
  302. {
  303. pg_enc encoding;
  304. const char *name;
  305. } pg_enc2gettext;
  306. extern const pg_enc2gettext pg_enc2gettext_tbl[];
  307. /*
  308. * pg_wchar stuff
  309. */
  310. typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
  311. pg_wchar *to,
  312. int len);
  313. typedef int (*wchar2mb_with_len_converter) (const pg_wchar *from,
  314. unsigned char *to,
  315. int len);
  316. typedef int (*mblen_converter) (const unsigned char *mbstr);
  317. typedef int (*mbdisplaylen_converter) (const unsigned char *mbstr);
  318. typedef bool (*mbcharacter_incrementer) (unsigned char *mbstr, int len);
  319. typedef int (*mbverifier) (const unsigned char *mbstr, int len);
  320. typedef struct
  321. {
  322. mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multibyte
  323. * string to a wchar */
  324. wchar2mb_with_len_converter wchar2mb_with_len; /* convert a wchar
  325. * string to a multibyte */
  326. mblen_converter mblen; /* get byte length of a char */
  327. mbdisplaylen_converter dsplen; /* get display width of a char */
  328. mbverifier mbverify; /* verify multibyte sequence */
  329. int maxmblen; /* max bytes for a char in this encoding */
  330. } pg_wchar_tbl;
  331. extern const pg_wchar_tbl pg_wchar_table[];
  332. /*
  333. * Data structures for conversions between UTF-8 and other encodings
  334. * (UtfToLocal() and LocalToUtf()). In these data structures, characters of
  335. * either encoding are represented by uint32 words; hence we can only support
  336. * characters up to 4 bytes long. For example, the byte sequence 0xC2 0x89
  337. * would be represented by 0x0000C289, and 0xE8 0xA2 0xB4 by 0x00E8A2B4.
  338. *
  339. * Maps are arrays of these structs, which must be in order by the lookup key
  340. * (so that bsearch() can be used).
  341. *
  342. * UTF-8 to local code conversion map
  343. */
  344. typedef struct
  345. {
  346. uint32 utf; /* UTF-8 */
  347. uint32 code; /* local code */
  348. } pg_utf_to_local;
  349. /*
  350. * local code to UTF-8 conversion map
  351. */
  352. typedef struct
  353. {
  354. uint32 code; /* local code */
  355. uint32 utf; /* UTF-8 */
  356. } pg_local_to_utf;
  357. /*
  358. * UTF-8 to local code conversion map (for combined characters)
  359. */
  360. typedef struct
  361. {
  362. uint32 utf1; /* UTF-8 code 1 */
  363. uint32 utf2; /* UTF-8 code 2 */
  364. uint32 code; /* local code */
  365. } pg_utf_to_local_combined;
  366. /*
  367. * local code to UTF-8 conversion map (for combined characters)
  368. */
  369. typedef struct
  370. {
  371. uint32 code; /* local code */
  372. uint32 utf1; /* UTF-8 code 1 */
  373. uint32 utf2; /* UTF-8 code 2 */
  374. } pg_local_to_utf_combined;
  375. /*
  376. * callback function for algorithmic encoding conversions (in either direction)
  377. *
  378. * if function returns zero, it does not know how to convert the code
  379. */
  380. typedef uint32 (*utf_local_conversion_func) (uint32 code);
  381. /*
  382. * Support macro for encoding conversion functions to validate their
  383. * arguments. (This could be made more compact if we included fmgr.h
  384. * here, but we don't want to do that because this header file is also
  385. * used by frontends.)
  386. */
  387. #define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
  388. check_encoding_conversion_args(PG_GETARG_INT32(0), \
  389. PG_GETARG_INT32(1), \
  390. PG_GETARG_INT32(4), \
  391. (srcencoding), \
  392. (destencoding))
  393. /*
  394. * These functions are considered part of libpq's exported API and
  395. * are also declared in libpq-fe.h.
  396. */
  397. extern int pg_char_to_encoding(const char *name);
  398. extern const char *pg_encoding_to_char(int encoding);
  399. extern int pg_valid_server_encoding_id(int encoding);
  400. /*
  401. * Remaining functions are not considered part of libpq's API, though many
  402. * of them do exist inside libpq.
  403. */
  404. extern int pg_mb2wchar(const char *from, pg_wchar *to);
  405. extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
  406. extern int pg_encoding_mb2wchar_with_len(int encoding,
  407. const char *from, pg_wchar *to, int len);
  408. extern int pg_wchar2mb(const pg_wchar *from, char *to);
  409. extern int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len);
  410. extern int pg_encoding_wchar2mb_with_len(int encoding,
  411. const pg_wchar *from, char *to, int len);
  412. extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
  413. extern int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n);
  414. extern int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n);
  415. extern size_t pg_wchar_strlen(const pg_wchar *wstr);
  416. extern int pg_mblen(const char *mbstr);
  417. extern int pg_dsplen(const char *mbstr);
  418. extern int pg_encoding_mblen(int encoding, const char *mbstr);
  419. extern int pg_encoding_dsplen(int encoding, const char *mbstr);
  420. extern int pg_encoding_verifymb(int encoding, const char *mbstr, int len);
  421. extern int pg_mule_mblen(const unsigned char *mbstr);
  422. extern int pg_mic_mblen(const unsigned char *mbstr);
  423. extern int pg_mbstrlen(const char *mbstr);
  424. extern int pg_mbstrlen_with_len(const char *mbstr, int len);
  425. extern int pg_mbcliplen(const char *mbstr, int len, int limit);
  426. extern int pg_encoding_mbcliplen(int encoding, const char *mbstr,
  427. int len, int limit);
  428. extern int pg_mbcharcliplen(const char *mbstr, int len, int imit);
  429. extern int pg_encoding_max_length(int encoding);
  430. extern int pg_database_encoding_max_length(void);
  431. extern mbcharacter_incrementer pg_database_encoding_character_incrementer(void);
  432. extern int PrepareClientEncoding(int encoding);
  433. extern int SetClientEncoding(int encoding);
  434. extern void InitializeClientEncoding(void);
  435. extern int pg_get_client_encoding(void);
  436. extern const char *pg_get_client_encoding_name(void);
  437. extern void SetDatabaseEncoding(int encoding);
  438. extern int GetDatabaseEncoding(void);
  439. extern const char *GetDatabaseEncodingName(void);
  440. extern void SetMessageEncoding(int encoding);
  441. extern int GetMessageEncoding(void);
  442. #ifdef ENABLE_NLS
  443. extern int pg_bind_textdomain_codeset(const char *domainname);
  444. #endif
  445. extern int pg_valid_client_encoding(const char *name);
  446. extern int pg_valid_server_encoding(const char *name);
  447. extern unsigned char *unicode_to_utf8(pg_wchar c, unsigned char *utf8string);
  448. extern pg_wchar utf8_to_unicode(const unsigned char *c);
  449. extern int pg_utf_mblen(const unsigned char *);
  450. extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
  451. int src_encoding,
  452. int dest_encoding);
  453. extern char *pg_client_to_server(const char *s, int len);
  454. extern char *pg_server_to_client(const char *s, int len);
  455. extern char *pg_any_to_server(const char *s, int len, int encoding);
  456. extern char *pg_server_to_any(const char *s, int len, int encoding);
  457. extern unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc);
  458. extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc);
  459. extern void UtfToLocal(const unsigned char *utf, int len,
  460. unsigned char *iso,
  461. const pg_utf_to_local *map, int mapsize,
  462. const pg_utf_to_local_combined *cmap, int cmapsize,
  463. utf_local_conversion_func conv_func,
  464. int encoding);
  465. extern void LocalToUtf(const unsigned char *iso, int len,
  466. unsigned char *utf,
  467. const pg_local_to_utf *map, int mapsize,
  468. const pg_local_to_utf_combined *cmap, int cmapsize,
  469. utf_local_conversion_func conv_func,
  470. int encoding);
  471. extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
  472. extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
  473. bool noError);
  474. extern int pg_verify_mbstr_len(int encoding, const char *mbstr, int len,
  475. bool noError);
  476. extern void check_encoding_conversion_args(int src_encoding,
  477. int dest_encoding,
  478. int len,
  479. int expected_src_encoding,
  480. int expected_dest_encoding);
  481. extern void report_invalid_encoding(int encoding, const char *mbstr, int len) pg_attribute_noreturn();
  482. extern void report_untranslatable_char(int src_encoding, int dest_encoding,
  483. const char *mbstr, int len) pg_attribute_noreturn();
  484. extern void local2local(const unsigned char *l, unsigned char *p, int len,
  485. int src_encoding, int dest_encoding, const unsigned char *tab);
  486. extern void pg_ascii2mic(const unsigned char *l, unsigned char *p, int len);
  487. extern void pg_mic2ascii(const unsigned char *mic, unsigned char *p, int len);
  488. extern void latin2mic(const unsigned char *l, unsigned char *p, int len,
  489. int lc, int encoding);
  490. extern void mic2latin(const unsigned char *mic, unsigned char *p, int len,
  491. int lc, int encoding);
  492. extern void latin2mic_with_table(const unsigned char *l, unsigned char *p,
  493. int len, int lc, int encoding,
  494. const unsigned char *tab);
  495. extern void mic2latin_with_table(const unsigned char *mic, unsigned char *p,
  496. int len, int lc, int encoding,
  497. const unsigned char *tab);
  498. extern bool pg_utf8_islegal(const unsigned char *source, int length);
  499. #ifdef WIN32
  500. extern WCHAR *pgwin32_message_to_UTF16(const char *str, int len, int *utf16len);
  501. #endif
  502. #endif /* PG_WCHAR_H */