Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_wchar.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_wchar.h
00004  *    multibyte-character support
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * src/include/mb/pg_wchar.h
00010  *
00011  *  NOTES
00012  *      This is used both by the backend and by libpq, but should not be
00013  *      included by libpq client programs.  In particular, a libpq client
00014  *      should not assume that the encoding IDs used by the version of libpq
00015  *      it's linked to match up with the IDs declared here.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #ifndef PG_WCHAR_H
00020 #define PG_WCHAR_H
00021 
00022 /*
00023  * The pg_wchar type
00024  */
00025 typedef unsigned int pg_wchar;
00026 
00027 /*
00028  * Maximum byte length of multibyte characters in any backend encoding
00029  */
00030 #define MAX_MULTIBYTE_CHAR_LEN  4
00031 
00032 /*
00033  * various definitions for EUC
00034  */
00035 #define SS2 0x8e                /* single shift 2 (JIS0201) */
00036 #define SS3 0x8f                /* single shift 3 (JIS0212) */
00037 
00038 /*
00039  * SJIS validation macros
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  * MULE Internal Encoding (MIC)
00046  *
00047  * This encoding follows the design used within XEmacs; it is meant to
00048  * subsume many externally-defined character sets.  Each character includes
00049  * identification of the character set it belongs to, so the encoding is
00050  * general but somewhat bulky.
00051  *
00052  * Currently PostgreSQL supports 5 types of MULE character sets:
00053  *
00054  * 1) 1-byte ASCII characters.  Each byte is below 0x80.
00055  *
00056  * 2) "Official" single byte charsets such as ISO-8859-1 (Latin1).
00057  *    Each MULE character consists of 2 bytes: LC1 + C1, where LC1 is
00058  *    an identifier for the charset (in the range 0x81 to 0x8d) and C1
00059  *    is the character code (in the range 0xa0 to 0xff).
00060  *
00061  * 3) "Private" single byte charsets such as SISHENG.  Each MULE
00062  *    character consists of 3 bytes: LCPRV1 + LC12 + C1, where LCPRV1
00063  *    is a private-charset flag, LC12 is an identifier for the charset,
00064  *    and C1 is the character code (in the range 0xa0 to 0xff).
00065  *    LCPRV1 is either 0x9a (if LC12 is in the range 0xa0 to 0xdf)
00066  *    or 0x9b (if LC12 is in the range 0xe0 to 0xef).
00067  *
00068  * 4) "Official" multibyte charsets such as JIS X0208.  Each MULE
00069  *    character consists of 3 bytes: LC2 + C1 + C2, where LC2 is
00070  *    an identifier for the charset (in the range 0x90 to 0x99) and C1
00071  *    and C2 form the character code (each in the range 0xa0 to 0xff).
00072  *
00073  * 5) "Private" multibyte charsets such as CNS 11643-1992 Plane 3.
00074  *    Each MULE character consists of 4 bytes: LCPRV2 + LC22 + C1 + C2,
00075  *    where LCPRV2 is a private-charset flag, LC22 is an identifier for
00076  *    the charset, and C1 and C2 form the character code (each in the range
00077  *    0xa0 to 0xff).  LCPRV2 is either 0x9c (if LC22 is in the range 0xf0
00078  *    to 0xf4) or 0x9d (if LC22 is in the range 0xf5 to 0xfe).
00079  *
00080  * "Official" encodings are those that have been assigned code numbers by
00081  * the XEmacs project; "private" encodings have Postgres-specific charset
00082  * identifiers.
00083  *
00084  * See the "XEmacs Internals Manual", available at http://www.xemacs.org,
00085  * for more details.  Note that for historical reasons, Postgres'
00086  * private-charset flag values do not match what XEmacs says they should be,
00087  * so this isn't really exactly MULE (not that private charsets would be
00088  * interoperable anyway).
00089  *
00090  * Note that XEmacs's implementation is different from what emacs does.
00091  * We follow emacs's implementaion, rathter than XEmacs's.
00092  *----------------------------------------------------
00093  */
00094 
00095 /*
00096  * Charset identifiers (also called "leading bytes" in the MULE documentation)
00097  */
00098 
00099 /*
00100  * Charset IDs for official single byte encodings (0x81-0x8e)
00101  */
00102 #define LC_ISO8859_1        0x81    /* ISO8859 Latin 1 */
00103 #define LC_ISO8859_2        0x82    /* ISO8859 Latin 2 */
00104 #define LC_ISO8859_3        0x83    /* ISO8859 Latin 3 */
00105 #define LC_ISO8859_4        0x84    /* ISO8859 Latin 4 */
00106 #define LC_TIS620           0x85    /* Thai (not supported yet) */
00107 #define LC_ISO8859_7        0x86    /* Greek (not supported yet) */
00108 #define LC_ISO8859_6        0x87    /* Arabic (not supported yet) */
00109 #define LC_ISO8859_8        0x88    /* Hebrew (not supported yet) */
00110 #define LC_JISX0201K        0x89    /* Japanese 1 byte kana */
00111 #define LC_JISX0201R        0x8a    /* Japanese 1 byte Roman */
00112 /* Note that 0x8b seems to be unused as of Emacs 20.7.
00113  * However, there might be a chance that 0x8b could be used
00114  * in later versions of Emacs.
00115  */
00116 #define LC_KOI8_R           0x8b    /* Cyrillic KOI8-R */
00117 #define LC_ISO8859_5        0x8c    /* ISO8859 Cyrillic */
00118 #define LC_ISO8859_9        0x8d    /* ISO8859 Latin 5 (not supported yet) */
00119 #define LC_ISO8859_15       0x8e    /* ISO8859 Latin 15 (not supported yet) */
00120 /* #define CONTROL_1        0x8f    control characters (unused) */
00121 
00122 /* Is a leading byte for "official" single byte encodings? */
00123 #define IS_LC1(c)   ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
00124 
00125 /*
00126  * Charset IDs for official multibyte encodings (0x90-0x99)
00127  * 0x9a-0x9d are free. 0x9e and 0x9f are reserved.
00128  */
00129 #define LC_JISX0208_1978    0x90    /* Japanese Kanji, old JIS (not supported) */
00130 #define LC_GB2312_80        0x91    /* Chinese */
00131 #define LC_JISX0208         0x92    /* Japanese Kanji (JIS X 0208) */
00132 #define LC_KS5601           0x93    /* Korean */
00133 #define LC_JISX0212         0x94    /* Japanese Kanji (JIS X 0212) */
00134 #define LC_CNS11643_1       0x95    /* CNS 11643-1992 Plane 1 */
00135 #define LC_CNS11643_2       0x96    /* CNS 11643-1992 Plane 2 */
00136 #define LC_JISX0213_1       0x97    /* Japanese Kanji (JIS X 0213 Plane 1) (not supported) */
00137 #define LC_BIG5_1           0x98    /* Plane 1 Chinese traditional (not supported) */
00138 #define LC_BIG5_2           0x99    /* Plane 1 Chinese traditional (not supported) */
00139 
00140 /* Is a leading byte for "official" multibyte encodings? */
00141 #define IS_LC2(c)   ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
00142 
00143 /*
00144  * Postgres-specific prefix bytes for "private" single byte encodings
00145  * (According to the MULE docs, we should be using 0x9e for this)
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  * Postgres-specific prefix bytes for "private" multibyte encodings
00157  * (According to the MULE docs, we should be using 0x9f for this)
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  * Charset IDs for private single byte encodings (0xa0-0xef)
00169  */
00170 #define LC_SISHENG          0xa0    /* Chinese SiSheng characters for
00171                                      * PinYin/ZhuYin (not supported) */
00172 #define LC_IPA              0xa1    /* IPA (International Phonetic Association)
00173                                      * (not supported) */
00174 #define LC_VISCII_LOWER     0xa2    /* Vietnamese VISCII1.1 lower-case (not
00175                                      * supported) */
00176 #define LC_VISCII_UPPER     0xa3    /* Vietnamese VISCII1.1 upper-case (not
00177                                      * supported) */
00178 #define LC_ARABIC_DIGIT     0xa4    /* Arabic digit (not supported) */
00179 #define LC_ARABIC_1_COLUMN  0xa5    /* Arabic 1-column (not supported) */
00180 #define LC_ASCII_RIGHT_TO_LEFT  0xa6    /* ASCII (left half of ISO8859-1) with
00181                                          * right-to-left direction (not
00182                                          * supported) */
00183 #define LC_LAO              0xa7    /* Lao characters (ISO10646 0E80..0EDF)
00184                                      * (not supported) */
00185 #define LC_ARABIC_2_COLUMN  0xa8    /* Arabic 1-column (not supported) */
00186 
00187 /*
00188  * Charset IDs for private multibyte encodings (0xf0-0xff)
00189  */
00190 #define LC_INDIAN_1_COLUMN  0xf0    /* Indian charset for 1-column width glyphs
00191                                      * (not supported) */
00192 #define LC_TIBETAN_1_COLUMN 0xf1    /* Tibetan 1-column width glyphs
00193                                      * (not supported) */
00194 #define LC_UNICODE_SUBSET_2 0xf2    /* Unicode characters of the range U+2500..U+33FF.
00195                                      * (not supported) */  
00196 #define LC_UNICODE_SUBSET_3 0xf3    /* Unicode characters of the range U+E000..U+FFFF.
00197                                      * (not supported) */  
00198 #define LC_UNICODE_SUBSET   0xf4    /* Unicode characters of the range U+0100..U+24FF.
00199                                      * (not supported) */  
00200 #define LC_ETHIOPIC         0xf5    /* Ethiopic characters (not supported) */
00201 #define LC_CNS11643_3       0xf6    /* CNS 11643-1992 Plane 3 */
00202 #define LC_CNS11643_4       0xf7    /* CNS 11643-1992 Plane 4 */
00203 #define LC_CNS11643_5       0xf8    /* CNS 11643-1992 Plane 5 */
00204 #define LC_CNS11643_6       0xf9    /* CNS 11643-1992 Plane 6 */
00205 #define LC_CNS11643_7       0xfa    /* CNS 11643-1992 Plane 7 */
00206 #define LC_INDIAN_2_COLUMN  0xfb    /* Indian charset for 2-column width glyphs
00207                                      * (not supported) */
00208 #define LC_TIBETAN          0xfc    /* Tibetan (not supported) */
00209 /* #define FREE             0xfd    free (unused) */
00210 /* #define FREE             0xfe    free (unused) */
00211 /* #define FREE             0xff    free (unused) */
00212 
00213 /*----------------------------------------------------
00214  * end of MULE stuff
00215  *----------------------------------------------------
00216  */
00217 
00218 /*
00219  * PostgreSQL encoding identifiers
00220  *
00221  * WARNING: the order of this enum must be same as order of entries
00222  *          in the pg_enc2name_tbl[] array (in mb/encnames.c), and
00223  *          in the pg_wchar_table[] array (in mb/wchar.c)!
00224  *
00225  *          If you add some encoding don't forget to check
00226  *          PG_ENCODING_BE_LAST macro.
00227  *
00228  * PG_SQL_ASCII is default encoding and must be = 0.
00229  *
00230  * XXX  We must avoid renumbering any backend encoding until libpq's major
00231  * version number is increased beyond 5; it turns out that the backend
00232  * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and
00233  * psql are concerned.
00234  */
00235 typedef enum pg_enc
00236 {
00237     PG_SQL_ASCII = 0,           /* SQL/ASCII */
00238     PG_EUC_JP,                  /* EUC for Japanese */
00239     PG_EUC_CN,                  /* EUC for Chinese */
00240     PG_EUC_KR,                  /* EUC for Korean */
00241     PG_EUC_TW,                  /* EUC for Taiwan */
00242     PG_EUC_JIS_2004,            /* EUC-JIS-2004 */
00243     PG_UTF8,                    /* Unicode UTF8 */
00244     PG_MULE_INTERNAL,           /* Mule internal code */
00245     PG_LATIN1,                  /* ISO-8859-1 Latin 1 */
00246     PG_LATIN2,                  /* ISO-8859-2 Latin 2 */
00247     PG_LATIN3,                  /* ISO-8859-3 Latin 3 */
00248     PG_LATIN4,                  /* ISO-8859-4 Latin 4 */
00249     PG_LATIN5,                  /* ISO-8859-9 Latin 5 */
00250     PG_LATIN6,                  /* ISO-8859-10 Latin6 */
00251     PG_LATIN7,                  /* ISO-8859-13 Latin7 */
00252     PG_LATIN8,                  /* ISO-8859-14 Latin8 */
00253     PG_LATIN9,                  /* ISO-8859-15 Latin9 */
00254     PG_LATIN10,                 /* ISO-8859-16 Latin10 */
00255     PG_WIN1256,                 /* windows-1256 */
00256     PG_WIN1258,                 /* Windows-1258 */
00257     PG_WIN866,                  /* (MS-DOS CP866) */
00258     PG_WIN874,                  /* windows-874 */
00259     PG_KOI8R,                   /* KOI8-R */
00260     PG_WIN1251,                 /* windows-1251 */
00261     PG_WIN1252,                 /* windows-1252 */
00262     PG_ISO_8859_5,              /* ISO-8859-5 */
00263     PG_ISO_8859_6,              /* ISO-8859-6 */
00264     PG_ISO_8859_7,              /* ISO-8859-7 */
00265     PG_ISO_8859_8,              /* ISO-8859-8 */
00266     PG_WIN1250,                 /* windows-1250 */
00267     PG_WIN1253,                 /* windows-1253 */
00268     PG_WIN1254,                 /* windows-1254 */
00269     PG_WIN1255,                 /* windows-1255 */
00270     PG_WIN1257,                 /* windows-1257 */
00271     PG_KOI8U,                   /* KOI8-U */
00272     /* PG_ENCODING_BE_LAST points to the above entry */
00273 
00274     /* followings are for client encoding only */
00275     PG_SJIS,                    /* Shift JIS (Winindows-932) */
00276     PG_BIG5,                    /* Big5 (Windows-950) */
00277     PG_GBK,                     /* GBK (Windows-936) */
00278     PG_UHC,                     /* UHC (Windows-949) */
00279     PG_GB18030,                 /* GB18030 */
00280     PG_JOHAB,                   /* EUC for Korean JOHAB */
00281     PG_SHIFT_JIS_2004,          /* Shift-JIS-2004 */
00282     _PG_LAST_ENCODING_          /* mark only */
00283 
00284 } pg_enc;
00285 
00286 #define PG_ENCODING_BE_LAST PG_KOI8U
00287 
00288 /*
00289  * Please use these tests before access to pg_encconv_tbl[]
00290  * or to other places...
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 /* On FE are possible all encodings */
00302 #define PG_VALID_FE_ENCODING(_enc)  PG_VALID_ENCODING(_enc)
00303 
00304 /*
00305  * Encoding names with all aliases
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  * Careful:
00318  *
00319  * if (PG_VALID_ENCODING(encoding))
00320  *      pg_enc2name_tbl[ encoding ];
00321  */
00322 typedef struct pg_enc2name
00323 {
00324     char       *name;
00325     pg_enc      encoding;
00326 #ifdef WIN32
00327     unsigned    codepage;       /* codepage for WIN32 */
00328 #endif
00329 } pg_enc2name;
00330 
00331 extern pg_enc2name pg_enc2name_tbl[];
00332 
00333 /*
00334  * Encoding names for gettext
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  * pg_wchar stuff
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;  /* convert a multibyte
00366                                                      * string to a wchar */
00367     wchar2mb_with_len_converter wchar2mb_with_len;  /* convert a wchar
00368                                                      * string to a multibyte */
00369     mblen_converter mblen;      /* get byte length of a char */
00370     mbdisplaylen_converter dsplen;      /* get display width of a char */
00371     mbverifier  mbverify;       /* verify multibyte sequence */
00372     int         maxmblen;       /* max bytes for a char in this encoding */
00373 } pg_wchar_tbl;
00374 
00375 extern pg_wchar_tbl pg_wchar_table[];
00376 
00377 /*
00378  * UTF-8 to local code conversion map
00379  * Note that we limit the max length of UTF-8 to 4 bytes,
00380  * which is UCS-4 00010000-001FFFFF range.
00381  */
00382 typedef struct
00383 {
00384     uint32      utf;            /* UTF-8 */
00385     uint32      code;           /* local code */
00386 } pg_utf_to_local;
00387 
00388 /*
00389  * local code to UTF-8 conversion map
00390  */
00391 typedef struct
00392 {
00393     uint32      code;           /* local code */
00394     uint32      utf;            /* UTF-8 */
00395 } pg_local_to_utf;
00396 
00397 /*
00398  * UTF-8 to local code conversion map(combined characters)
00399  */
00400 typedef struct
00401 {
00402     uint32      utf1;           /* UTF-8 code 1 */
00403     uint32      utf2;           /* UTF-8 code 2 */
00404     uint32      code;           /* local code */
00405 } pg_utf_to_local_combined;
00406 
00407 /*
00408  * local code to UTF-8 conversion map(combined characters)
00409  */
00410 typedef struct
00411 {
00412     uint32      code;           /* local code */
00413     uint32      utf1;           /* UTF-8 code 1 */
00414     uint32      utf2;           /* UTF-8 code 2 */
00415 } pg_local_to_utf_combined;
00416 
00417 /*
00418  * Support macro for encoding conversion functions to validate their
00419  * arguments.  (This could be made more compact if we included fmgr.h
00420  * here, but we don't want to do that because this header file is also
00421  * used by frontends.)
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  * These functions are considered part of libpq's exported API and
00433  * are also declared in libpq-fe.h.
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  * Remaining functions are not considered part of libpq's API, though many
00441  * of them do exist inside libpq.
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   /* PG_WCHAR_H */