00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PG_WCHAR_H
00020 #define PG_WCHAR_H
00021
00022
00023
00024
00025 typedef unsigned int pg_wchar;
00026
00027
00028
00029
00030 #define MAX_MULTIBYTE_CHAR_LEN 4
00031
00032
00033
00034
00035 #define SS2 0x8e
00036 #define SS3 0x8f
00037
00038
00039
00040
00041 #define ISSJISHEAD(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc))
00042 #define ISSJISTAIL(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #define LC_ISO8859_1 0x81
00103 #define LC_ISO8859_2 0x82
00104 #define LC_ISO8859_3 0x83
00105 #define LC_ISO8859_4 0x84
00106 #define LC_TIS620 0x85
00107 #define LC_ISO8859_7 0x86
00108 #define LC_ISO8859_6 0x87
00109 #define LC_ISO8859_8 0x88
00110 #define LC_JISX0201K 0x89
00111 #define LC_JISX0201R 0x8a
00112
00113
00114
00115
00116 #define LC_KOI8_R 0x8b
00117 #define LC_ISO8859_5 0x8c
00118 #define LC_ISO8859_9 0x8d
00119 #define LC_ISO8859_15 0x8e
00120
00121
00122
00123 #define IS_LC1(c) ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
00124
00125
00126
00127
00128
00129 #define LC_JISX0208_1978 0x90
00130 #define LC_GB2312_80 0x91
00131 #define LC_JISX0208 0x92
00132 #define LC_KS5601 0x93
00133 #define LC_JISX0212 0x94
00134 #define LC_CNS11643_1 0x95
00135 #define LC_CNS11643_2 0x96
00136 #define LC_JISX0213_1 0x97
00137 #define LC_BIG5_1 0x98
00138 #define LC_BIG5_2 0x99
00139
00140
00141 #define IS_LC2(c) ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
00142
00143
00144
00145
00146
00147 #define LCPRV1_A 0x9a
00148 #define LCPRV1_B 0x9b
00149 #define IS_LCPRV1(c) ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)
00150 #define IS_LCPRV1_A_RANGE(c) \
00151 ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf)
00152 #define IS_LCPRV1_B_RANGE(c) \
00153 ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef)
00154
00155
00156
00157
00158
00159 #define LCPRV2_A 0x9c
00160 #define LCPRV2_B 0x9d
00161 #define IS_LCPRV2(c) ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B)
00162 #define IS_LCPRV2_A_RANGE(c) \
00163 ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4)
00164 #define IS_LCPRV2_B_RANGE(c) \
00165 ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe)
00166
00167
00168
00169
00170 #define LC_SISHENG 0xa0
00171
00172 #define LC_IPA 0xa1
00173
00174 #define LC_VISCII_LOWER 0xa2
00175
00176 #define LC_VISCII_UPPER 0xa3
00177
00178 #define LC_ARABIC_DIGIT 0xa4
00179 #define LC_ARABIC_1_COLUMN 0xa5
00180 #define LC_ASCII_RIGHT_TO_LEFT 0xa6
00181
00182
00183 #define LC_LAO 0xa7
00184
00185 #define LC_ARABIC_2_COLUMN 0xa8
00186
00187
00188
00189
00190 #define LC_INDIAN_1_COLUMN 0xf0
00191
00192 #define LC_TIBETAN_1_COLUMN 0xf1
00193
00194 #define LC_UNICODE_SUBSET_2 0xf2
00195
00196 #define LC_UNICODE_SUBSET_3 0xf3
00197
00198 #define LC_UNICODE_SUBSET 0xf4
00199
00200 #define LC_ETHIOPIC 0xf5
00201 #define LC_CNS11643_3 0xf6
00202 #define LC_CNS11643_4 0xf7
00203 #define LC_CNS11643_5 0xf8
00204 #define LC_CNS11643_6 0xf9
00205 #define LC_CNS11643_7 0xfa
00206 #define LC_INDIAN_2_COLUMN 0xfb
00207
00208 #define LC_TIBETAN 0xfc
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 typedef enum pg_enc
00236 {
00237 PG_SQL_ASCII = 0,
00238 PG_EUC_JP,
00239 PG_EUC_CN,
00240 PG_EUC_KR,
00241 PG_EUC_TW,
00242 PG_EUC_JIS_2004,
00243 PG_UTF8,
00244 PG_MULE_INTERNAL,
00245 PG_LATIN1,
00246 PG_LATIN2,
00247 PG_LATIN3,
00248 PG_LATIN4,
00249 PG_LATIN5,
00250 PG_LATIN6,
00251 PG_LATIN7,
00252 PG_LATIN8,
00253 PG_LATIN9,
00254 PG_LATIN10,
00255 PG_WIN1256,
00256 PG_WIN1258,
00257 PG_WIN866,
00258 PG_WIN874,
00259 PG_KOI8R,
00260 PG_WIN1251,
00261 PG_WIN1252,
00262 PG_ISO_8859_5,
00263 PG_ISO_8859_6,
00264 PG_ISO_8859_7,
00265 PG_ISO_8859_8,
00266 PG_WIN1250,
00267 PG_WIN1253,
00268 PG_WIN1254,
00269 PG_WIN1255,
00270 PG_WIN1257,
00271 PG_KOI8U,
00272
00273
00274
00275 PG_SJIS,
00276 PG_BIG5,
00277 PG_GBK,
00278 PG_UHC,
00279 PG_GB18030,
00280 PG_JOHAB,
00281 PG_SHIFT_JIS_2004,
00282 _PG_LAST_ENCODING_
00283
00284 } pg_enc;
00285
00286 #define PG_ENCODING_BE_LAST PG_KOI8U
00287
00288
00289
00290
00291
00292 #define PG_VALID_BE_ENCODING(_enc) \
00293 ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
00294
00295 #define PG_ENCODING_IS_CLIENT_ONLY(_enc) \
00296 ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)
00297
00298 #define PG_VALID_ENCODING(_enc) \
00299 ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
00300
00301
00302 #define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc)
00303
00304
00305
00306
00307 typedef struct pg_encname
00308 {
00309 char *name;
00310 pg_enc encoding;
00311 } pg_encname;
00312
00313 extern pg_encname pg_encname_tbl[];
00314 extern unsigned int pg_encname_tbl_sz;
00315
00316
00317
00318
00319
00320
00321
00322 typedef struct pg_enc2name
00323 {
00324 char *name;
00325 pg_enc encoding;
00326 #ifdef WIN32
00327 unsigned codepage;
00328 #endif
00329 } pg_enc2name;
00330
00331 extern pg_enc2name pg_enc2name_tbl[];
00332
00333
00334
00335
00336 typedef struct pg_enc2gettext
00337 {
00338 pg_enc encoding;
00339 const char *name;
00340 } pg_enc2gettext;
00341
00342 extern pg_enc2gettext pg_enc2gettext_tbl[];
00343
00344
00345
00346
00347 typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
00348 pg_wchar *to,
00349 int len);
00350
00351 typedef int (*wchar2mb_with_len_converter) (const pg_wchar *from,
00352 unsigned char *to,
00353 int len);
00354
00355 typedef int (*mblen_converter) (const unsigned char *mbstr);
00356
00357 typedef int (*mbdisplaylen_converter) (const unsigned char *mbstr);
00358
00359 typedef bool (*mbcharacter_incrementer) (unsigned char *mbstr, int len);
00360
00361 typedef int (*mbverifier) (const unsigned char *mbstr, int len);
00362
00363 typedef struct
00364 {
00365 mb2wchar_with_len_converter mb2wchar_with_len;
00366
00367 wchar2mb_with_len_converter wchar2mb_with_len;
00368
00369 mblen_converter mblen;
00370 mbdisplaylen_converter dsplen;
00371 mbverifier mbverify;
00372 int maxmblen;
00373 } pg_wchar_tbl;
00374
00375 extern pg_wchar_tbl pg_wchar_table[];
00376
00377
00378
00379
00380
00381
00382 typedef struct
00383 {
00384 uint32 utf;
00385 uint32 code;
00386 } pg_utf_to_local;
00387
00388
00389
00390
00391 typedef struct
00392 {
00393 uint32 code;
00394 uint32 utf;
00395 } pg_local_to_utf;
00396
00397
00398
00399
00400 typedef struct
00401 {
00402 uint32 utf1;
00403 uint32 utf2;
00404 uint32 code;
00405 } pg_utf_to_local_combined;
00406
00407
00408
00409
00410 typedef struct
00411 {
00412 uint32 code;
00413 uint32 utf1;
00414 uint32 utf2;
00415 } pg_local_to_utf_combined;
00416
00417
00418
00419
00420
00421
00422
00423 #define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
00424 check_encoding_conversion_args(PG_GETARG_INT32(0), \
00425 PG_GETARG_INT32(1), \
00426 PG_GETARG_INT32(4), \
00427 (srcencoding), \
00428 (destencoding))
00429
00430
00431
00432
00433
00434
00435 extern int pg_char_to_encoding(const char *name);
00436 extern const char *pg_encoding_to_char(int encoding);
00437 extern int pg_valid_server_encoding_id(int encoding);
00438
00439
00440
00441
00442
00443 extern pg_encname *pg_char_to_encname_struct(const char *name);
00444
00445 extern int pg_mb2wchar(const char *from, pg_wchar *to);
00446 extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
00447 extern int pg_encoding_mb2wchar_with_len(int encoding,
00448 const char *from, pg_wchar *to, int len);
00449 extern int pg_wchar2mb(const pg_wchar *from, char *to);
00450 extern int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len);
00451 extern int pg_encoding_wchar2mb_with_len(int encoding,
00452 const pg_wchar *from, char *to, int len);
00453 extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
00454 extern int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n);
00455 extern int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n);
00456 extern size_t pg_wchar_strlen(const pg_wchar *wstr);
00457 extern int pg_mblen(const char *mbstr);
00458 extern int pg_dsplen(const char *mbstr);
00459 extern int pg_encoding_mblen(int encoding, const char *mbstr);
00460 extern int pg_encoding_dsplen(int encoding, const char *mbstr);
00461 extern int pg_encoding_verifymb(int encoding, const char *mbstr, int len);
00462 extern int pg_mule_mblen(const unsigned char *mbstr);
00463 extern int pg_mic_mblen(const unsigned char *mbstr);
00464 extern int pg_mbstrlen(const char *mbstr);
00465 extern int pg_mbstrlen_with_len(const char *mbstr, int len);
00466 extern int pg_mbcliplen(const char *mbstr, int len, int limit);
00467 extern int pg_encoding_mbcliplen(int encoding, const char *mbstr,
00468 int len, int limit);
00469 extern int pg_mbcharcliplen(const char *mbstr, int len, int imit);
00470 extern int pg_encoding_max_length(int encoding);
00471 extern int pg_database_encoding_max_length(void);
00472 extern mbcharacter_incrementer pg_database_encoding_character_incrementer(void);
00473
00474 extern int PrepareClientEncoding(int encoding);
00475 extern int SetClientEncoding(int encoding);
00476 extern void InitializeClientEncoding(void);
00477 extern int pg_get_client_encoding(void);
00478 extern const char *pg_get_client_encoding_name(void);
00479
00480 extern void SetDatabaseEncoding(int encoding);
00481 extern int GetDatabaseEncoding(void);
00482 extern const char *GetDatabaseEncodingName(void);
00483 extern int GetPlatformEncoding(void);
00484 extern void pg_bind_textdomain_codeset(const char *domainname);
00485
00486 extern int pg_valid_client_encoding(const char *name);
00487 extern int pg_valid_server_encoding(const char *name);
00488
00489 extern unsigned char *unicode_to_utf8(pg_wchar c, unsigned char *utf8string);
00490 extern pg_wchar utf8_to_unicode(const unsigned char *c);
00491 extern int pg_utf_mblen(const unsigned char *);
00492 extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
00493 int src_encoding,
00494 int dest_encoding);
00495
00496 extern char *pg_client_to_server(const char *s, int len);
00497 extern char *pg_server_to_client(const char *s, int len);
00498 extern char *pg_any_to_server(const char *s, int len, int encoding);
00499 extern char *pg_server_to_any(const char *s, int len, int encoding);
00500
00501 extern unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc);
00502 extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc);
00503
00504 extern void LocalToUtf(const unsigned char *iso, unsigned char *utf,
00505 const pg_local_to_utf *map, const pg_local_to_utf_combined *cmap,
00506 int size1, int size2, int encoding, int len);
00507
00508 extern void UtfToLocal(const unsigned char *utf, unsigned char *iso,
00509 const pg_utf_to_local *map, const pg_utf_to_local_combined *cmap,
00510 int size1, int size2, int encoding, int len);
00511
00512 extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
00513 extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
00514 bool noError);
00515 extern int pg_verify_mbstr_len(int encoding, const char *mbstr, int len,
00516 bool noError);
00517
00518 extern void check_encoding_conversion_args(int src_encoding,
00519 int dest_encoding,
00520 int len,
00521 int expected_src_encoding,
00522 int expected_dest_encoding);
00523
00524 extern void report_invalid_encoding(int encoding, const char *mbstr, int len) __attribute__((noreturn));
00525 extern void report_untranslatable_char(int src_encoding, int dest_encoding,
00526 const char *mbstr, int len) __attribute__((noreturn));
00527
00528 extern void pg_ascii2mic(const unsigned char *l, unsigned char *p, int len);
00529 extern void pg_mic2ascii(const unsigned char *mic, unsigned char *p, int len);
00530 extern void latin2mic(const unsigned char *l, unsigned char *p, int len,
00531 int lc, int encoding);
00532 extern void mic2latin(const unsigned char *mic, unsigned char *p, int len,
00533 int lc, int encoding);
00534 extern void latin2mic_with_table(const unsigned char *l, unsigned char *p,
00535 int len, int lc, int encoding,
00536 const unsigned char *tab);
00537 extern void mic2latin_with_table(const unsigned char *mic, unsigned char *p,
00538 int len, int lc, int encoding,
00539 const unsigned char *tab);
00540
00541 extern bool pg_utf8_islegal(const unsigned char *source, int length);
00542
00543 #ifdef WIN32
00544 extern WCHAR *pgwin32_toUTF16(const char *str, int len, int *utf16len);
00545 #endif
00546
00547 #endif