Header And Logo

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

Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

pg_wchar.h File Reference

Go to the source code of this file.

Data Structures

struct  pg_encname
struct  pg_enc2name
struct  pg_enc2gettext
struct  pg_wchar_tbl
struct  pg_utf_to_local
struct  pg_local_to_utf
struct  pg_utf_to_local_combined
struct  pg_local_to_utf_combined

Defines

#define MAX_MULTIBYTE_CHAR_LEN   4
#define SS2   0x8e
#define SS3   0x8f
#define ISSJISHEAD(c)   (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc))
#define ISSJISTAIL(c)   (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
#define LC_ISO8859_1   0x81
#define LC_ISO8859_2   0x82
#define LC_ISO8859_3   0x83
#define LC_ISO8859_4   0x84
#define LC_TIS620   0x85
#define LC_ISO8859_7   0x86
#define LC_ISO8859_6   0x87
#define LC_ISO8859_8   0x88
#define LC_JISX0201K   0x89
#define LC_JISX0201R   0x8a
#define LC_KOI8_R   0x8b
#define LC_ISO8859_5   0x8c
#define LC_ISO8859_9   0x8d
#define LC_ISO8859_15   0x8e
#define IS_LC1(c)   ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
#define LC_JISX0208_1978   0x90
#define LC_GB2312_80   0x91
#define LC_JISX0208   0x92
#define LC_KS5601   0x93
#define LC_JISX0212   0x94
#define LC_CNS11643_1   0x95
#define LC_CNS11643_2   0x96
#define LC_JISX0213_1   0x97
#define LC_BIG5_1   0x98
#define LC_BIG5_2   0x99
#define IS_LC2(c)   ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
#define LCPRV1_A   0x9a
#define LCPRV1_B   0x9b
#define IS_LCPRV1(c)   ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)
#define IS_LCPRV1_A_RANGE(c)   ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf)
#define IS_LCPRV1_B_RANGE(c)   ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef)
#define LCPRV2_A   0x9c
#define LCPRV2_B   0x9d
#define IS_LCPRV2(c)   ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B)
#define IS_LCPRV2_A_RANGE(c)   ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4)
#define IS_LCPRV2_B_RANGE(c)   ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe)
#define LC_SISHENG   0xa0
#define LC_IPA   0xa1
#define LC_VISCII_LOWER   0xa2
#define LC_VISCII_UPPER   0xa3
#define LC_ARABIC_DIGIT   0xa4
#define LC_ARABIC_1_COLUMN   0xa5
#define LC_ASCII_RIGHT_TO_LEFT   0xa6
#define LC_LAO   0xa7
#define LC_ARABIC_2_COLUMN   0xa8
#define LC_INDIAN_1_COLUMN   0xf0
#define LC_TIBETAN_1_COLUMN   0xf1
#define LC_UNICODE_SUBSET_2   0xf2
#define LC_UNICODE_SUBSET_3   0xf3
#define LC_UNICODE_SUBSET   0xf4
#define LC_ETHIOPIC   0xf5
#define LC_CNS11643_3   0xf6
#define LC_CNS11643_4   0xf7
#define LC_CNS11643_5   0xf8
#define LC_CNS11643_6   0xf9
#define LC_CNS11643_7   0xfa
#define LC_INDIAN_2_COLUMN   0xfb
#define LC_TIBETAN   0xfc
#define PG_ENCODING_BE_LAST   PG_KOI8U
#define PG_VALID_BE_ENCODING(_enc)   ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
#define PG_ENCODING_IS_CLIENT_ONLY(_enc)   ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)
#define PG_VALID_ENCODING(_enc)   ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
#define PG_VALID_FE_ENCODING(_enc)   PG_VALID_ENCODING(_enc)
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)

Typedefs

typedef unsigned int pg_wchar
typedef enum pg_enc pg_enc
typedef struct pg_encname pg_encname
typedef struct pg_enc2name pg_enc2name
typedef struct pg_enc2gettext pg_enc2gettext
typedef int(* mb2wchar_with_len_converter )(const unsigned char *from, pg_wchar *to, int len)
typedef int(* wchar2mb_with_len_converter )(const pg_wchar *from, unsigned char *to, int len)
typedef int(* mblen_converter )(const unsigned char *mbstr)
typedef int(* mbdisplaylen_converter )(const unsigned char *mbstr)
typedef bool(* mbcharacter_incrementer )(unsigned char *mbstr, int len)
typedef int(* mbverifier )(const unsigned char *mbstr, int len)

Enumerations

enum  pg_enc {
  PG_SQL_ASCII = 0, PG_EUC_JP, PG_EUC_CN, PG_EUC_KR,
  PG_EUC_TW, PG_EUC_JIS_2004, PG_UTF8, PG_MULE_INTERNAL,
  PG_LATIN1, PG_LATIN2, PG_LATIN3, PG_LATIN4,
  PG_LATIN5, PG_LATIN6, PG_LATIN7, PG_LATIN8,
  PG_LATIN9, PG_LATIN10, PG_WIN1256, PG_WIN1258,
  PG_WIN866, PG_WIN874, PG_KOI8R, PG_WIN1251,
  PG_WIN1252, PG_ISO_8859_5, PG_ISO_8859_6, PG_ISO_8859_7,
  PG_ISO_8859_8, PG_WIN1250, PG_WIN1253, PG_WIN1254,
  PG_WIN1255, PG_WIN1257, PG_KOI8U, PG_SJIS,
  PG_BIG5, PG_GBK, PG_UHC, PG_GB18030,
  PG_JOHAB, PG_SHIFT_JIS_2004, _PG_LAST_ENCODING_
}

Functions

int pg_char_to_encoding (const char *name)
const char * pg_encoding_to_char (int encoding)
int pg_valid_server_encoding_id (int encoding)
pg_encnamepg_char_to_encname_struct (const char *name)
int pg_mb2wchar (const char *from, pg_wchar *to)
int pg_mb2wchar_with_len (const char *from, pg_wchar *to, int len)
int pg_encoding_mb2wchar_with_len (int encoding, const char *from, pg_wchar *to, int len)
int pg_wchar2mb (const pg_wchar *from, char *to)
int pg_wchar2mb_with_len (const pg_wchar *from, char *to, int len)
int pg_encoding_wchar2mb_with_len (int encoding, const pg_wchar *from, char *to, int len)
int pg_char_and_wchar_strcmp (const char *s1, const pg_wchar *s2)
int pg_wchar_strncmp (const pg_wchar *s1, const pg_wchar *s2, size_t n)
int pg_char_and_wchar_strncmp (const char *s1, const pg_wchar *s2, size_t n)
size_t pg_wchar_strlen (const pg_wchar *wstr)
int pg_mblen (const char *mbstr)
int pg_dsplen (const char *mbstr)
int pg_encoding_mblen (int encoding, const char *mbstr)
int pg_encoding_dsplen (int encoding, const char *mbstr)
int pg_encoding_verifymb (int encoding, const char *mbstr, int len)
int pg_mule_mblen (const unsigned char *mbstr)
int pg_mic_mblen (const unsigned char *mbstr)
int pg_mbstrlen (const char *mbstr)
int pg_mbstrlen_with_len (const char *mbstr, int len)
int pg_mbcliplen (const char *mbstr, int len, int limit)
int pg_encoding_mbcliplen (int encoding, const char *mbstr, int len, int limit)
int pg_mbcharcliplen (const char *mbstr, int len, int imit)
int pg_encoding_max_length (int encoding)
int pg_database_encoding_max_length (void)
mbcharacter_incrementer pg_database_encoding_character_incrementer (void)
int PrepareClientEncoding (int encoding)
int SetClientEncoding (int encoding)
void InitializeClientEncoding (void)
int pg_get_client_encoding (void)
const char * pg_get_client_encoding_name (void)
void SetDatabaseEncoding (int encoding)
int GetDatabaseEncoding (void)
const char * GetDatabaseEncodingName (void)
int GetPlatformEncoding (void)
void pg_bind_textdomain_codeset (const char *domainname)
int pg_valid_client_encoding (const char *name)
int pg_valid_server_encoding (const char *name)
unsigned char * unicode_to_utf8 (pg_wchar c, unsigned char *utf8string)
pg_wchar utf8_to_unicode (const unsigned char *c)
int pg_utf_mblen (const unsigned char *)
unsigned char * pg_do_encoding_conversion (unsigned char *src, int len, int src_encoding, int dest_encoding)
char * pg_client_to_server (const char *s, int len)
char * pg_server_to_client (const char *s, int len)
char * pg_any_to_server (const char *s, int len, int encoding)
char * pg_server_to_any (const char *s, int len, int encoding)
unsigned short BIG5toCNS (unsigned short big5, unsigned char *lc)
unsigned short CNStoBIG5 (unsigned short cns, unsigned char lc)
void LocalToUtf (const unsigned char *iso, unsigned char *utf, const pg_local_to_utf *map, const pg_local_to_utf_combined *cmap, int size1, int size2, int encoding, int len)
void UtfToLocal (const unsigned char *utf, unsigned char *iso, const pg_utf_to_local *map, const pg_utf_to_local_combined *cmap, int size1, int size2, int encoding, int len)
bool pg_verifymbstr (const char *mbstr, int len, bool noError)
bool pg_verify_mbstr (int encoding, const char *mbstr, int len, bool noError)
int pg_verify_mbstr_len (int encoding, const char *mbstr, int len, bool noError)
void check_encoding_conversion_args (int src_encoding, int dest_encoding, int len, int expected_src_encoding, int expected_dest_encoding)
void report_invalid_encoding (int encoding, const char *mbstr, int len) __attribute__((noreturn))
void report_untranslatable_char (int src_encoding, int dest_encoding, const char *mbstr, int len) __attribute__((noreturn))
void pg_ascii2mic (const unsigned char *l, unsigned char *p, int len)
void pg_mic2ascii (const unsigned char *mic, unsigned char *p, int len)
void latin2mic (const unsigned char *l, unsigned char *p, int len, int lc, int encoding)
void mic2latin (const unsigned char *mic, unsigned char *p, int len, int lc, int encoding)
void latin2mic_with_table (const unsigned char *l, unsigned char *p, int len, int lc, int encoding, const unsigned char *tab)
void mic2latin_with_table (const unsigned char *mic, unsigned char *p, int len, int lc, int encoding, const unsigned char *tab)
bool pg_utf8_islegal (const unsigned char *source, int length)

Variables

pg_encname pg_encname_tbl []
unsigned int pg_encname_tbl_sz
pg_enc2name pg_enc2name_tbl []
pg_enc2gettext pg_enc2gettext_tbl []
pg_wchar_tbl pg_wchar_table []

Define Documentation

#define CHECK_ENCODING_CONVERSION_ARGS (   srcencoding,
  destencoding 
)
Value:
check_encoding_conversion_args(PG_GETARG_INT32(0), \
                                   PG_GETARG_INT32(1), \
                                   PG_GETARG_INT32(4), \
                                   (srcencoding), \
                                   (destencoding))

Definition at line 423 of file pg_wchar.h.

Referenced by ascii_to_mic(), ascii_to_utf8(), big5_to_euc_tw(), big5_to_mic(), big5_to_utf8(), euc_cn_to_mic(), euc_cn_to_utf8(), euc_jis_2004_to_shift_jis_2004(), euc_jis_2004_to_utf8(), euc_jp_to_mic(), euc_jp_to_sjis(), euc_jp_to_utf8(), euc_kr_to_mic(), euc_kr_to_utf8(), euc_tw_to_big5(), euc_tw_to_mic(), euc_tw_to_utf8(), gb18030_to_utf8(), gbk_to_utf8(), iso8859_1_to_utf8(), iso8859_to_utf8(), iso_to_koi8r(), iso_to_mic(), iso_to_win1251(), iso_to_win866(), johab_to_utf8(), koi8r_to_iso(), koi8r_to_mic(), koi8r_to_utf8(), koi8r_to_win1251(), koi8r_to_win866(), koi8u_to_utf8(), latin1_to_mic(), latin2_to_mic(), latin2_to_win1250(), latin3_to_mic(), latin4_to_mic(), mic_to_ascii(), mic_to_big5(), mic_to_euc_cn(), mic_to_euc_jp(), mic_to_euc_kr(), mic_to_euc_tw(), mic_to_iso(), mic_to_koi8r(), mic_to_latin1(), mic_to_latin2(), mic_to_latin3(), mic_to_latin4(), mic_to_sjis(), mic_to_win1250(), mic_to_win1251(), mic_to_win866(), shift_jis_2004_to_euc_jis_2004(), shift_jis_2004_to_utf8(), sjis_to_euc_jp(), sjis_to_mic(), sjis_to_utf8(), uhc_to_utf8(), utf8_to_ascii(), utf8_to_big5(), utf8_to_euc_cn(), utf8_to_euc_jis_2004(), utf8_to_euc_jp(), utf8_to_euc_kr(), utf8_to_euc_tw(), utf8_to_gb18030(), utf8_to_gbk(), utf8_to_iso8859(), utf8_to_iso8859_1(), utf8_to_johab(), utf8_to_koi8r(), utf8_to_koi8u(), utf8_to_shift_jis_2004(), utf8_to_sjis(), utf8_to_uhc(), utf8_to_win(), win1250_to_latin2(), win1250_to_mic(), win1251_to_iso(), win1251_to_koi8r(), win1251_to_mic(), win1251_to_win866(), win866_to_iso(), win866_to_koi8r(), win866_to_mic(), win866_to_win1251(), and win_to_utf8().

#define IS_LC1 (   c  )     ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
#define IS_LC2 (   c  )     ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)
#define IS_LCPRV1 (   c  )     ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)

Definition at line 149 of file pg_wchar.h.

Referenced by pg_mule2wchar_with_len(), pg_mule_dsplen(), and pg_mule_mblen().

#define IS_LCPRV1_A_RANGE (   c  )     ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf)

Definition at line 150 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

#define IS_LCPRV1_B_RANGE (   c  )     ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef)

Definition at line 152 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

#define IS_LCPRV2 (   c  )     ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B)

Definition at line 161 of file pg_wchar.h.

Referenced by pg_mule2wchar_with_len(), pg_mule_dsplen(), and pg_mule_mblen().

#define IS_LCPRV2_A_RANGE (   c  )     ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4)

Definition at line 162 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

#define IS_LCPRV2_B_RANGE (   c  )     ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe)

Definition at line 164 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

#define ISSJISHEAD (   c  )     (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc))

Definition at line 41 of file pg_wchar.h.

Referenced by pg_sjis_verifier(), and sjis2mic().

#define ISSJISTAIL (   c  )     (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))

Definition at line 42 of file pg_wchar.h.

Referenced by pg_sjis_verifier(), and sjis2mic().

#define LC_ARABIC_1_COLUMN   0xa5

Definition at line 179 of file pg_wchar.h.

#define LC_ARABIC_2_COLUMN   0xa8

Definition at line 185 of file pg_wchar.h.

#define LC_ARABIC_DIGIT   0xa4

Definition at line 178 of file pg_wchar.h.

#define LC_ASCII_RIGHT_TO_LEFT   0xa6

Definition at line 180 of file pg_wchar.h.

#define LC_BIG5_1   0x98

Definition at line 137 of file pg_wchar.h.

#define LC_BIG5_2   0x99

Definition at line 138 of file pg_wchar.h.

#define LC_CNS11643_1   0x95

Definition at line 134 of file pg_wchar.h.

Referenced by BIG5toCNS(), CNStoBIG5(), mic2big5(), and mic2euc_tw().

#define LC_CNS11643_2   0x96

Definition at line 135 of file pg_wchar.h.

Referenced by CNStoBIG5(), mic2big5(), and mic2euc_tw().

#define LC_CNS11643_3   0xf6

Definition at line 201 of file pg_wchar.h.

Referenced by big52mic(), CNStoBIG5(), and mic2euc_tw().

#define LC_CNS11643_4   0xf7

Definition at line 202 of file pg_wchar.h.

Referenced by big52mic(), and CNStoBIG5().

#define LC_CNS11643_5   0xf8

Definition at line 203 of file pg_wchar.h.

#define LC_CNS11643_6   0xf9

Definition at line 204 of file pg_wchar.h.

#define LC_CNS11643_7   0xfa

Definition at line 205 of file pg_wchar.h.

Referenced by mic2euc_tw().

#define LC_ETHIOPIC   0xf5

Definition at line 200 of file pg_wchar.h.

#define LC_GB2312_80   0x91

Definition at line 130 of file pg_wchar.h.

Referenced by mic2euc_cn().

#define LC_INDIAN_1_COLUMN   0xf0

Definition at line 190 of file pg_wchar.h.

#define LC_INDIAN_2_COLUMN   0xfb

Definition at line 206 of file pg_wchar.h.

#define LC_IPA   0xa1

Definition at line 172 of file pg_wchar.h.

#define LC_ISO8859_1   0x81

Definition at line 102 of file pg_wchar.h.

Referenced by latin12mic(), and mic2latin1().

#define LC_ISO8859_15   0x8e

Definition at line 119 of file pg_wchar.h.

#define LC_ISO8859_2   0x82

Definition at line 103 of file pg_wchar.h.

Referenced by latin22mic(), mic2latin2(), mic2win1250(), and win12502mic().

#define LC_ISO8859_3   0x83

Definition at line 104 of file pg_wchar.h.

Referenced by latin32mic(), and mic2latin3().

#define LC_ISO8859_4   0x84

Definition at line 105 of file pg_wchar.h.

Referenced by latin42mic(), and mic2latin4().

#define LC_ISO8859_5   0x8c

Definition at line 117 of file pg_wchar.h.

#define LC_ISO8859_6   0x87

Definition at line 108 of file pg_wchar.h.

#define LC_ISO8859_7   0x86

Definition at line 107 of file pg_wchar.h.

#define LC_ISO8859_8   0x88

Definition at line 109 of file pg_wchar.h.

#define LC_ISO8859_9   0x8d

Definition at line 118 of file pg_wchar.h.

#define LC_JISX0201K   0x89

Definition at line 110 of file pg_wchar.h.

Referenced by mic2euc_jp(), and mic2sjis().

#define LC_JISX0201R   0x8a

Definition at line 111 of file pg_wchar.h.

#define LC_JISX0208   0x92

Definition at line 131 of file pg_wchar.h.

Referenced by mic2euc_jp(), and mic2sjis().

#define LC_JISX0208_1978   0x90

Definition at line 129 of file pg_wchar.h.

#define LC_JISX0212   0x94

Definition at line 133 of file pg_wchar.h.

Referenced by mic2euc_jp(), and mic2sjis().

#define LC_JISX0213_1   0x97

Definition at line 136 of file pg_wchar.h.

#define LC_KOI8_R   0x8b
#define LC_KS5601   0x93

Definition at line 132 of file pg_wchar.h.

Referenced by mic2euc_kr().

#define LC_LAO   0xa7

Definition at line 183 of file pg_wchar.h.

#define LC_SISHENG   0xa0

Definition at line 170 of file pg_wchar.h.

#define LC_TIBETAN   0xfc

Definition at line 208 of file pg_wchar.h.

#define LC_TIBETAN_1_COLUMN   0xf1

Definition at line 192 of file pg_wchar.h.

#define LC_TIS620   0x85

Definition at line 106 of file pg_wchar.h.

#define LC_UNICODE_SUBSET   0xf4

Definition at line 198 of file pg_wchar.h.

#define LC_UNICODE_SUBSET_2   0xf2

Definition at line 194 of file pg_wchar.h.

#define LC_UNICODE_SUBSET_3   0xf3

Definition at line 196 of file pg_wchar.h.

#define LC_VISCII_LOWER   0xa2

Definition at line 174 of file pg_wchar.h.

#define LC_VISCII_UPPER   0xa3

Definition at line 176 of file pg_wchar.h.

#define LCPRV1_A   0x9a

Definition at line 147 of file pg_wchar.h.

#define LCPRV1_B   0x9b

Definition at line 148 of file pg_wchar.h.

#define LCPRV2_A   0x9c

Definition at line 159 of file pg_wchar.h.

#define LCPRV2_B   0x9d

Definition at line 160 of file pg_wchar.h.

Referenced by mic2big5(), and mic2euc_tw().

#define MAX_MULTIBYTE_CHAR_LEN   4

Definition at line 30 of file pg_wchar.h.

Referenced by convertPgWchar(), and fillTrgm().

#define PG_ENCODING_BE_LAST   PG_KOI8U

Definition at line 286 of file pg_wchar.h.

#define PG_ENCODING_IS_CLIENT_ONLY (   _enc  )     ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_)

Definition at line 295 of file pg_wchar.h.

Referenced by BeginCopy().

#define PG_VALID_BE_ENCODING (   _enc  )     ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST)
#define PG_VALID_ENCODING (   _enc  )     ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_)
#define PG_VALID_FE_ENCODING (   _enc  )     PG_VALID_ENCODING(_enc)

Definition at line 302 of file pg_wchar.h.

Referenced by pg_valid_client_encoding(), PrepareClientEncoding(), and SetClientEncoding().

#define SS2   0x8e
#define SS3   0x8f

Typedef Documentation

typedef int(* mb2wchar_with_len_converter)(const unsigned char *from, pg_wchar *to, int len)

Definition at line 347 of file pg_wchar.h.

typedef bool(* mbcharacter_incrementer)(unsigned char *mbstr, int len)

Definition at line 359 of file pg_wchar.h.

typedef int(* mbdisplaylen_converter)(const unsigned char *mbstr)

Definition at line 357 of file pg_wchar.h.

typedef int(* mblen_converter)(const unsigned char *mbstr)

Definition at line 355 of file pg_wchar.h.

typedef int(* mbverifier)(const unsigned char *mbstr, int len)

Definition at line 361 of file pg_wchar.h.

typedef enum pg_enc pg_enc
typedef struct pg_enc2name pg_enc2name
typedef struct pg_encname pg_encname
typedef unsigned int pg_wchar

Definition at line 25 of file pg_wchar.h.

typedef int(* wchar2mb_with_len_converter)(const pg_wchar *from, unsigned char *to, int len)

Definition at line 351 of file pg_wchar.h.


Enumeration Type Documentation

enum pg_enc
Enumerator:
PG_SQL_ASCII 
PG_EUC_JP 
PG_EUC_CN 
PG_EUC_KR 
PG_EUC_TW 
PG_EUC_JIS_2004 
PG_UTF8 
PG_MULE_INTERNAL 
PG_LATIN1 
PG_LATIN2 
PG_LATIN3 
PG_LATIN4 
PG_LATIN5 
PG_LATIN6 
PG_LATIN7 
PG_LATIN8 
PG_LATIN9 
PG_LATIN10 
PG_WIN1256 
PG_WIN1258 
PG_WIN866 
PG_WIN874 
PG_KOI8R 
PG_WIN1251 
PG_WIN1252 
PG_ISO_8859_5 
PG_ISO_8859_6 
PG_ISO_8859_7 
PG_ISO_8859_8 
PG_WIN1250 
PG_WIN1253 
PG_WIN1254 
PG_WIN1255 
PG_WIN1257 
PG_KOI8U 
PG_SJIS 
PG_BIG5 
PG_GBK 
PG_UHC 
PG_GB18030 
PG_JOHAB 
PG_SHIFT_JIS_2004 
_PG_LAST_ENCODING_ 

Definition at line 235 of file pg_wchar.h.

{
    PG_SQL_ASCII = 0,           /* SQL/ASCII */
    PG_EUC_JP,                  /* EUC for Japanese */
    PG_EUC_CN,                  /* EUC for Chinese */
    PG_EUC_KR,                  /* EUC for Korean */
    PG_EUC_TW,                  /* EUC for Taiwan */
    PG_EUC_JIS_2004,            /* EUC-JIS-2004 */
    PG_UTF8,                    /* Unicode UTF8 */
    PG_MULE_INTERNAL,           /* Mule internal code */
    PG_LATIN1,                  /* ISO-8859-1 Latin 1 */
    PG_LATIN2,                  /* ISO-8859-2 Latin 2 */
    PG_LATIN3,                  /* ISO-8859-3 Latin 3 */
    PG_LATIN4,                  /* ISO-8859-4 Latin 4 */
    PG_LATIN5,                  /* ISO-8859-9 Latin 5 */
    PG_LATIN6,                  /* ISO-8859-10 Latin6 */
    PG_LATIN7,                  /* ISO-8859-13 Latin7 */
    PG_LATIN8,                  /* ISO-8859-14 Latin8 */
    PG_LATIN9,                  /* ISO-8859-15 Latin9 */
    PG_LATIN10,                 /* ISO-8859-16 Latin10 */
    PG_WIN1256,                 /* windows-1256 */
    PG_WIN1258,                 /* Windows-1258 */
    PG_WIN866,                  /* (MS-DOS CP866) */
    PG_WIN874,                  /* windows-874 */
    PG_KOI8R,                   /* KOI8-R */
    PG_WIN1251,                 /* windows-1251 */
    PG_WIN1252,                 /* windows-1252 */
    PG_ISO_8859_5,              /* ISO-8859-5 */
    PG_ISO_8859_6,              /* ISO-8859-6 */
    PG_ISO_8859_7,              /* ISO-8859-7 */
    PG_ISO_8859_8,              /* ISO-8859-8 */
    PG_WIN1250,                 /* windows-1250 */
    PG_WIN1253,                 /* windows-1253 */
    PG_WIN1254,                 /* windows-1254 */
    PG_WIN1255,                 /* windows-1255 */
    PG_WIN1257,                 /* windows-1257 */
    PG_KOI8U,                   /* KOI8-U */
    /* PG_ENCODING_BE_LAST points to the above entry */

    /* followings are for client encoding only */
    PG_SJIS,                    /* Shift JIS (Winindows-932) */
    PG_BIG5,                    /* Big5 (Windows-950) */
    PG_GBK,                     /* GBK (Windows-936) */
    PG_UHC,                     /* UHC (Windows-949) */
    PG_GB18030,                 /* GB18030 */
    PG_JOHAB,                   /* EUC for Korean JOHAB */
    PG_SHIFT_JIS_2004,          /* Shift-JIS-2004 */
    _PG_LAST_ENCODING_          /* mark only */

} pg_enc;


Function Documentation

unsigned short BIG5toCNS ( unsigned short  big5,
unsigned char *  lc 
)

Definition at line 292 of file big5.c.

References b1c4, b2c3, BinarySearchRange(), i, and LC_CNS11643_1.

Referenced by big52mic().

{
    unsigned short cns = 0;
    int         i;

    if (big5 < 0xc940U)
    {
        /* level 1 */

        for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++)
        {
            if (b1c4[i][0] == big5)
            {
                *lc = LC_CNS11643_4;
                return (b1c4[i][1] | 0x8080U);
            }
        }

        if (0 < (cns = BinarySearchRange(big5Level1ToCnsPlane1, 23, big5)))
            *lc = LC_CNS11643_1;
    }
    else if (big5 == 0xc94aU)
    {
        /* level 2 */
        *lc = LC_CNS11643_1;
        cns = 0x4442;
    }
    else
    {
        /* level 2 */
        for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++)
        {
            if (b2c3[i][0] == big5)
            {
                *lc = LC_CNS11643_3;
                return (b2c3[i][1] | 0x8080U);
            }
        }

        if (0 < (cns = BinarySearchRange(big5Level2ToCnsPlane2, 46, big5)))
            *lc = LC_CNS11643_2;
    }

    if (0 == cns)
    {                           /* no mapping Big5 to CNS 11643-1992 */
        *lc = 0;
        return (unsigned short) '?';
    }

    return cns | 0x8080;
}

void check_encoding_conversion_args ( int  src_encoding,
int  dest_encoding,
int  len,
int  expected_src_encoding,
int  expected_dest_encoding 
)

Definition at line 1969 of file wchar.c.

References elog, ERROR, name, pg_enc2name_tbl, and PG_VALID_ENCODING.

{
    if (!PG_VALID_ENCODING(src_encoding))
        elog(ERROR, "invalid source encoding ID: %d", src_encoding);
    if (src_encoding != expected_src_encoding && expected_src_encoding >= 0)
        elog(ERROR, "expected source encoding \"%s\", but got \"%s\"",
             pg_enc2name_tbl[expected_src_encoding].name,
             pg_enc2name_tbl[src_encoding].name);
    if (!PG_VALID_ENCODING(dest_encoding))
        elog(ERROR, "invalid destination encoding ID: %d", dest_encoding);
    if (dest_encoding != expected_dest_encoding && expected_dest_encoding >= 0)
        elog(ERROR, "expected destination encoding \"%s\", but got \"%s\"",
             pg_enc2name_tbl[expected_dest_encoding].name,
             pg_enc2name_tbl[dest_encoding].name);
    if (len < 0)
        elog(ERROR, "encoding conversion length must not be negative");
}

unsigned short CNStoBIG5 ( unsigned short  cns,
unsigned char  lc 
)

Definition at line 345 of file big5.c.

References b1c4, b2c3, BinarySearchRange(), i, LC_CNS11643_1, LC_CNS11643_2, LC_CNS11643_3, and LC_CNS11643_4.

Referenced by mic2big5().

{
    int         i;
    unsigned int big5 = 0;

    cns &= 0x7f7f;

    switch (lc)
    {
        case LC_CNS11643_1:
            big5 = BinarySearchRange(cnsPlane1ToBig5Level1, 24, cns);
            break;
        case LC_CNS11643_2:
            big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns);
            break;
        case LC_CNS11643_3:
            for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++)
            {
                if (b2c3[i][1] == cns)
                    return (b2c3[i][0]);
            }
            break;
        case LC_CNS11643_4:
            for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++)
            {
                if (b1c4[i][1] == cns)
                    return (b1c4[i][0]);
            }
        default:
            break;
    }
    return big5;
}

int GetDatabaseEncoding ( void   ) 
const char* GetDatabaseEncodingName ( void   ) 
int GetPlatformEncoding ( void   ) 

Definition at line 953 of file mbutils.c.

References pg_enc2name::encoding, encoding, NULL, pg_enc2name_tbl, and pg_get_encoding_from_locale().

Referenced by write_console().

{
    if (PlatformEncoding == NULL)
    {
        /* try to determine encoding of server's environment locale */
        int         encoding = pg_get_encoding_from_locale("", true);

        if (encoding < 0)
            encoding = PG_SQL_ASCII;
        PlatformEncoding = &pg_enc2name_tbl[encoding];
    }
    return PlatformEncoding->encoding;
}

void InitializeClientEncoding ( void   ) 

Definition at line 267 of file mbutils.c.

References Assert, backend_startup_complete, ereport, errcode(), errmsg(), FATAL, GetDatabaseEncodingName(), name, pending_client_encoding, pg_enc2name_tbl, PrepareClientEncoding(), and SetClientEncoding().

Referenced by InitPostgres().

{
    Assert(!backend_startup_complete);
    backend_startup_complete = true;

    if (PrepareClientEncoding(pending_client_encoding) < 0 ||
        SetClientEncoding(pending_client_encoding) < 0)
    {
        /*
         * Oops, the requested conversion is not available. We couldn't fail
         * before, but we can now.
         */
        ereport(FATAL,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("conversion between %s and %s is not supported",
                        pg_enc2name_tbl[pending_client_encoding].name,
                        GetDatabaseEncodingName())));
    }
}

void latin2mic ( const unsigned char *  l,
unsigned char *  p,
int  len,
int  lc,
int  encoding 
)

Definition at line 26 of file conv.c.

References IS_HIGHBIT_SET, and report_invalid_encoding().

Referenced by koi8r2mic(), latin12mic(), latin22mic(), latin32mic(), and latin42mic().

{
    int         c1;

    while (len > 0)
    {
        c1 = *l;
        if (c1 == 0)
            report_invalid_encoding(encoding, (const char *) l, len);
        if (IS_HIGHBIT_SET(c1))
            *p++ = lc;
        *p++ = c1;
        l++;
        len--;
    }
    *p = '\0';
}

void latin2mic_with_table ( const unsigned char *  l,
unsigned char *  p,
int  len,
int  lc,
int  encoding,
const unsigned char *  tab 
)

Definition at line 148 of file conv.c.

References IS_HIGHBIT_SET, PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by iso2mic(), win12502mic(), win12512mic(), and win8662mic().

{
    unsigned char c1,
                c2;

    while (len > 0)
    {
        c1 = *l;
        if (c1 == 0)
            report_invalid_encoding(encoding, (const char *) l, len);
        if (!IS_HIGHBIT_SET(c1))
            *p++ = c1;
        else
        {
            c2 = tab[c1 - HIGHBIT];
            if (c2)
            {
                *p++ = lc;
                *p++ = c2;
            }
            else
                report_untranslatable_char(encoding, PG_MULE_INTERNAL,
                                           (const char *) l, len);
        }
        l++;
        len--;
    }
    *p = '\0';
}

void LocalToUtf ( const unsigned char *  iso,
unsigned char *  utf,
const pg_local_to_utf map,
const pg_local_to_utf_combined cmap,
int  size1,
int  size2,
int  encoding,
int  len 
)

Definition at line 497 of file conv.c.

References compare2(), compare4(), ereport, errcode(), errmsg(), ERROR, IS_HIGHBIT_SET, NULL, pg_encoding_verifymb(), PG_UTF8, PG_VALID_ENCODING, report_invalid_encoding(), report_untranslatable_char(), pg_local_to_utf::utf, pg_local_to_utf_combined::utf1, and pg_local_to_utf_combined::utf2.

Referenced by big5_to_utf8(), euc_cn_to_utf8(), euc_jis_2004_to_utf8(), euc_jp_to_utf8(), euc_kr_to_utf8(), euc_tw_to_utf8(), gb18030_to_utf8(), gbk_to_utf8(), iso8859_to_utf8(), johab_to_utf8(), koi8r_to_utf8(), koi8u_to_utf8(), shift_jis_2004_to_utf8(), sjis_to_utf8(), uhc_to_utf8(), and win_to_utf8().

{
    unsigned int iiso;
    int         l;
    pg_local_to_utf *p;
    pg_local_to_utf_combined *cp;

    if (!PG_VALID_ENCODING(encoding))
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("invalid encoding number: %d", encoding)));

    for (; len > 0; len -= l)
    {
        /* "break" cases all represent errors */
        if (*iso == '\0')
            break;

        if (!IS_HIGHBIT_SET(*iso))
        {
            /* ASCII case is easy */
            *utf++ = *iso++;
            l = 1;
            continue;
        }

        l = pg_encoding_verifymb(encoding, (const char *) iso, len);
        if (l < 0)
            break;

        if (l == 1)
            iiso = *iso++;
        else if (l == 2)
        {
            iiso = *iso++ << 8;
            iiso |= *iso++;
        }
        else if (l == 3)
        {
            iiso = *iso++ << 16;
            iiso |= *iso++ << 8;
            iiso |= *iso++;
        }
        else if (l == 4)
        {
            iiso = *iso++ << 24;
            iiso |= *iso++ << 16;
            iiso |= *iso++ << 8;
            iiso |= *iso++;
        }

        p = bsearch(&iiso, map, size1,
                    sizeof(pg_local_to_utf), compare2);

        if (p == NULL)
        {
            /*
             * not found in the ordinary map. if there's a combined character
             * map, try with it
             */
            if (cmap)
            {
                cp = bsearch(&iiso, cmap, size2,
                             sizeof(pg_local_to_utf_combined), compare4);

                if (cp)
                {
                    if (cp->utf1 & 0xff000000)
                        *utf++ = cp->utf1 >> 24;
                    if (cp->utf1 & 0x00ff0000)
                        *utf++ = (cp->utf1 & 0x00ff0000) >> 16;
                    if (cp->utf1 & 0x0000ff00)
                        *utf++ = (cp->utf1 & 0x0000ff00) >> 8;
                    if (cp->utf1 & 0x000000ff)
                        *utf++ = cp->utf1 & 0x000000ff;

                    if (cp->utf2 & 0xff000000)
                        *utf++ = cp->utf2 >> 24;
                    if (cp->utf2 & 0x00ff0000)
                        *utf++ = (cp->utf2 & 0x00ff0000) >> 16;
                    if (cp->utf2 & 0x0000ff00)
                        *utf++ = (cp->utf2 & 0x0000ff00) >> 8;
                    if (cp->utf2 & 0x000000ff)
                        *utf++ = cp->utf2 & 0x000000ff;

                    continue;
                }
            }

            report_untranslatable_char(encoding, PG_UTF8,
                                       (const char *) (iso - l), len);

        }
        else
        {
            if (p->utf & 0xff000000)
                *utf++ = p->utf >> 24;
            if (p->utf & 0x00ff0000)
                *utf++ = (p->utf & 0x00ff0000) >> 16;
            if (p->utf & 0x0000ff00)
                *utf++ = (p->utf & 0x0000ff00) >> 8;
            if (p->utf & 0x000000ff)
                *utf++ = p->utf & 0x000000ff;
        }
    }

    if (len > 0)
        report_invalid_encoding(encoding, (const char *) iso, len);

    *utf = '\0';
}

void mic2latin ( const unsigned char *  mic,
unsigned char *  p,
int  len,
int  lc,
int  encoding 
)

Definition at line 54 of file conv.c.

References IS_HIGHBIT_SET, pg_mic_mblen(), PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by mic2koi8r(), mic2latin1(), mic2latin2(), mic2latin3(), and mic2latin4().

{
    int         c1;

    while (len > 0)
    {
        c1 = *mic;
        if (c1 == 0)
            report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic, len);
        if (!IS_HIGHBIT_SET(c1))
        {
            /* easy for ASCII */
            *p++ = c1;
            mic++;
            len--;
        }
        else
        {
            int         l = pg_mic_mblen(mic);

            if (len < l)
                report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic,
                                        len);
            if (l != 2 || c1 != lc || !IS_HIGHBIT_SET(mic[1]))
                report_untranslatable_char(PG_MULE_INTERNAL, encoding,
                                           (const char *) mic, len);
            *p++ = mic[1];
            mic += 2;
            len -= 2;
        }
    }
    *p = '\0';
}

void mic2latin_with_table ( const unsigned char *  mic,
unsigned char *  p,
int  len,
int  lc,
int  encoding,
const unsigned char *  tab 
)

Definition at line 196 of file conv.c.

References HIGHBIT, IS_HIGHBIT_SET, pg_mic_mblen(), PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by mic2iso(), mic2win1250(), mic2win1251(), and mic2win866().

{
    unsigned char c1,
                c2;

    while (len > 0)
    {
        c1 = *mic;
        if (c1 == 0)
            report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic, len);
        if (!IS_HIGHBIT_SET(c1))
        {
            /* easy for ASCII */
            *p++ = c1;
            mic++;
            len--;
        }
        else
        {
            int         l = pg_mic_mblen(mic);

            if (len < l)
                report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic,
                                        len);
            if (l != 2 || c1 != lc || !IS_HIGHBIT_SET(mic[1]) ||
                (c2 = tab[mic[1] - HIGHBIT]) == 0)
            {
                report_untranslatable_char(PG_MULE_INTERNAL, encoding,
                                           (const char *) mic, len);
                break;          /* keep compiler quiet */
            }
            *p++ = c2;
            mic += 2;
            len -= 2;
        }
    }
    *p = '\0';
}

char* pg_any_to_server ( const char *  s,
int  len,
int  encoding 
)

Definition at line 549 of file mbutils.c.

References Assert, pg_enc2name::encoding, ereport, errcode(), errmsg(), ERROR, i, IS_HIGHBIT_SET, name, perform_default_encoding_conversion(), pg_do_encoding_conversion(), pg_enc2name_tbl, PG_SQL_ASCII, PG_VALID_BE_ENCODING, and pg_verify_mbstr().

Referenced by CopyReadLine(), json_lex_string(), and pg_client_to_server().

{
    Assert(DatabaseEncoding);
    Assert(ClientEncoding);

    if (len <= 0)
        return (char *) s;

    if (encoding == DatabaseEncoding->encoding ||
        encoding == PG_SQL_ASCII)
    {
        /*
         * No conversion is needed, but we must still validate the data.
         */
        (void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false);
        return (char *) s;
    }

    if (DatabaseEncoding->encoding == PG_SQL_ASCII)
    {
        /*
         * No conversion is possible, but we must still validate the data,
         * because the client-side code might have done string escaping using
         * the selected client_encoding.  If the client encoding is ASCII-safe
         * then we just do a straight validation under that encoding.  For an
         * ASCII-unsafe encoding we have a problem: we dare not pass such data
         * to the parser but we have no way to convert it.  We compromise by
         * rejecting the data if it contains any non-ASCII characters.
         */
        if (PG_VALID_BE_ENCODING(encoding))
            (void) pg_verify_mbstr(encoding, s, len, false);
        else
        {
            int         i;

            for (i = 0; i < len; i++)
            {
                if (s[i] == '\0' || IS_HIGHBIT_SET(s[i]))
                    ereport(ERROR,
                            (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
                     errmsg("invalid byte value for encoding \"%s\": 0x%02x",
                            pg_enc2name_tbl[PG_SQL_ASCII].name,
                            (unsigned char) s[i])));
            }
        }
        return (char *) s;
    }

    if (ClientEncoding->encoding == encoding)
        return perform_default_encoding_conversion(s, len, true);
    else
        return (char *) pg_do_encoding_conversion(
             (unsigned char *) s, len, encoding, DatabaseEncoding->encoding);
}

void pg_ascii2mic ( const unsigned char *  l,
unsigned char *  p,
int  len 
)

Definition at line 98 of file conv.c.

References IS_HIGHBIT_SET, PG_SQL_ASCII, and report_invalid_encoding().

Referenced by ascii_to_mic(), and ascii_to_utf8().

{
    int         c1;

    while (len > 0)
    {
        c1 = *l;
        if (c1 == 0 || IS_HIGHBIT_SET(c1))
            report_invalid_encoding(PG_SQL_ASCII, (const char *) l, len);
        *p++ = c1;
        l++;
        len--;
    }
    *p = '\0';
}

void pg_bind_textdomain_codeset ( const char *  domainname  ) 

Definition at line 888 of file mbutils.c.

References elog, encoding, GetDatabaseEncoding(), i, LOG, name, pg_enc2gettext::name, NULL, pg_enc2gettext_tbl, and pg_strcasecmp().

Referenced by CheckMyDatabase(), and pg_bindtextdomain().

{
#if defined(ENABLE_NLS)
    int         encoding = GetDatabaseEncoding();
    int         i;

    /*
     * gettext() uses the codeset specified by LC_CTYPE by default, so if that
     * matches the database encoding we don't need to do anything. In CREATE
     * DATABASE, we enforce or trust that the locale's codeset matches
     * database encoding, except for the C locale. In C locale, we bind
     * gettext() explicitly to the right codeset.
     *
     * On Windows, though, gettext() tends to get confused so we always bind
     * it.
     */
#ifndef WIN32
    const char *ctype = setlocale(LC_CTYPE, NULL);

    if (pg_strcasecmp(ctype, "C") != 0 && pg_strcasecmp(ctype, "POSIX") != 0)
        return;
#endif

    for (i = 0; pg_enc2gettext_tbl[i].name != NULL; i++)
    {
        if (pg_enc2gettext_tbl[i].encoding == encoding)
        {
            if (bind_textdomain_codeset(domainname,
                                        pg_enc2gettext_tbl[i].name) == NULL)
                elog(LOG, "bind_textdomain_codeset failed");
            break;
        }
    }
#endif
}

int pg_char_and_wchar_strcmp ( const char *  s1,
const pg_wchar s2 
)

Definition at line 41 of file wstrcmp.c.

{
    while ((pg_wchar) *s1 == *s2++)
        if (*s1++ == 0)
            return 0;
    return *(const unsigned char *) s1 - *(const pg_wchar *) (s2 - 1);
}

int pg_char_and_wchar_strncmp ( const char *  s1,
const pg_wchar s2,
size_t  n 
)

Definition at line 55 of file wstrncmp.c.

Referenced by cclass(), and element().

{
    if (n == 0)
        return 0;
    do
    {
        if ((pg_wchar) ((unsigned char) *s1) != *s2++)
            return ((pg_wchar) ((unsigned char) *s1) - *(s2 - 1));
        if (*s1++ == 0)
            break;
    } while (--n != 0);
    return 0;
}

pg_encname* pg_char_to_encname_struct ( const char *  name  ) 

Definition at line 463 of file encnames.c.

References clean_encoding_name(), ereport, errcode(), errmsg(), ERROR, NAMEDATALEN, NULL, and pg_encname_tbl_sz.

Referenced by pg_char_to_encoding().

{
    unsigned int nel = pg_encname_tbl_sz;
    pg_encname *base = pg_encname_tbl,
               *last = base + nel - 1,
               *position;
    int         result;
    char        buff[NAMEDATALEN],
               *key;

    if (name == NULL || *name == '\0')
        return NULL;

    if (strlen(name) >= NAMEDATALEN)
    {
#ifdef FRONTEND
        fprintf(stderr, "encoding name too long\n");
        return NULL;
#else
        ereport(ERROR,
                (errcode(ERRCODE_NAME_TOO_LONG),
                 errmsg("encoding name too long")));
#endif
    }
    key = clean_encoding_name(name, buff);

    while (last >= base)
    {
        position = base + ((last - base) >> 1);
        result = key[0] - position->name[0];

        if (result == 0)
        {
            result = strcmp(key, position->name);
            if (result == 0)
                return position;
        }
        if (result < 0)
            last = position - 1;
        else
            base = position + 1;
    }
    return NULL;
}

int pg_char_to_encoding ( const char *  name  ) 

Definition at line 512 of file encnames.c.

{
    pg_encname *p;

    if (!name)
        return -1;

    p = pg_char_to_encname_struct(name);
    return p ? p->encoding : -1;
}

char* pg_client_to_server ( const char *  s,
int  len 
)
mbcharacter_incrementer pg_database_encoding_character_incrementer ( void   ) 

Definition at line 1845 of file wchar.c.

References GetDatabaseEncoding(), PG_EUC_JP, and PG_UTF8.

Referenced by make_greater_string().

{
    /*
     * Eventually it might be best to add a field to pg_wchar_table[], but for
     * now we just use a switch.
     */
    switch (GetDatabaseEncoding())
    {
        case PG_UTF8:
            return pg_utf8_increment;

        case PG_EUC_JP:
            return pg_eucjp_increment;

        default:
            return pg_generic_charinc;
    }
}

int pg_database_encoding_max_length ( void   ) 
unsigned char* pg_do_encoding_conversion ( unsigned char *  src,
int  len,
int  src_encoding,
int  dest_encoding 
)

Definition at line 328 of file mbutils.c.

References CStringGetDatum, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, FindDefaultConversionProc(), Int32GetDatum, IsTransactionState(), LOG, MAX_CONVERSION_GROWTH, MaxAllocSize, ObjectIdGetDatum, OidFunctionCall5, OidIsValid, palloc(), pg_encoding_to_char(), PG_SQL_ASCII, PROCOID, and SearchSysCacheExists1.

Referenced by ASN1_STRING_to_text(), convert_charset(), db_encoding_strdup(), dsnowball_lexize(), hv_fetch_string(), hv_store_string(), pg_any_to_server(), pg_convert(), pg_server_to_any(), pg_stat_statements(), PLyUnicode_Bytes(), read_extension_script_file(), t_readline(), unicode_to_sqlchar(), utf_e2u(), utf_u2e(), X509_NAME_to_text(), and xml_recv().

{
    unsigned char *result;
    Oid         proc;

    if (!IsTransactionState())
        return src;

    if (src_encoding == dest_encoding)
        return src;

    if (src_encoding == PG_SQL_ASCII || dest_encoding == PG_SQL_ASCII)
        return src;

    if (len <= 0)
        return src;

    proc = FindDefaultConversionProc(src_encoding, dest_encoding);
    if (!OidIsValid(proc))
    {
        ereport(LOG,
                (errcode(ERRCODE_UNDEFINED_FUNCTION),
                 errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
                        pg_encoding_to_char(src_encoding),
                        pg_encoding_to_char(dest_encoding))));
        return src;
    }

    /*
     * XXX we should avoid throwing errors in OidFunctionCall. Otherwise we
     * are going into infinite loop!  So we have to make sure that the
     * function exists before calling OidFunctionCall.
     */
    if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(proc)))
    {
        elog(LOG, "cache lookup failed for function %u", proc);
        return src;
    }

    /*
     * Allocate space for conversion result, being wary of integer overflow
     */
    if ((Size) len >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
        ereport(ERROR,
                (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
                 errmsg("out of memory"),
         errdetail("String of %d bytes is too long for encoding conversion.",
                   len)));

    result = palloc(len * MAX_CONVERSION_GROWTH + 1);

    OidFunctionCall5(proc,
                     Int32GetDatum(src_encoding),
                     Int32GetDatum(dest_encoding),
                     CStringGetDatum(src),
                     CStringGetDatum(result),
                     Int32GetDatum(len));
    return result;
}

int pg_dsplen ( const char *  mbstr  ) 

Definition at line 744 of file mbutils.c.

References pg_wchar_tbl::dsplen, pg_enc2name::encoding, and pg_wchar_table.

Referenced by p_isspecial().

{
    return ((*pg_wchar_table[DatabaseEncoding->encoding].dsplen) ((const unsigned char *) mbstr));
}

int pg_encoding_dsplen ( int  encoding,
const char *  mbstr 
)

Definition at line 1793 of file wchar.c.

References Assert, PG_SQL_ASCII, and PG_VALID_ENCODING.

Referenced by PQdsplen(), and reportErrorPosition().

{
    Assert(PG_VALID_ENCODING(encoding));

    return ((encoding >= 0 &&
             encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
       ((*pg_wchar_table[encoding].dsplen) ((const unsigned char *) mbstr)) :
    ((*pg_wchar_table[PG_SQL_ASCII].dsplen) ((const unsigned char *) mbstr)));
}

int pg_encoding_max_length ( int  encoding  ) 
int pg_encoding_mb2wchar_with_len ( int  encoding,
const char *  from,
pg_wchar to,
int  len 
)

Definition at line 707 of file mbutils.c.

References pg_wchar_table.

{
    return (*pg_wchar_table[encoding].mb2wchar_with_len) ((const unsigned char *) from, to, len);
}

int pg_encoding_mbcliplen ( int  encoding,
const char *  mbstr,
int  len,
int  limit 
)

Definition at line 807 of file mbutils.c.

References cliplen(), pg_wchar_tbl::mblen, pg_encoding_max_length(), and pg_wchar_table.

Referenced by generate_normalized_query(), pg_mbcliplen(), pgss_shmem_startup(), and pgss_store().

{
    mblen_converter mblen_fn;
    int         clen = 0;
    int         l;

    /* optimization for single byte encoding */
    if (pg_encoding_max_length(encoding) == 1)
        return cliplen(mbstr, len, limit);

    mblen_fn = pg_wchar_table[encoding].mblen;

    while (len > 0 && *mbstr)
    {
        l = (*mblen_fn) ((const unsigned char *) mbstr);
        if ((clen + l) > limit)
            break;
        clen += l;
        if (clen == limit)
            break;
        len -= l;
        mbstr += l;
    }
    return clen;
}

int pg_encoding_mblen ( int  encoding,
const char *  mbstr 
)
const char* pg_encoding_to_char ( int  encoding  ) 

Definition at line 534 of file encnames.c.

{
    if (PG_VALID_ENCODING(encoding))
    {
        pg_enc2name *p = &pg_enc2name_tbl[encoding];

        Assert(encoding == p->encoding);
        return p->name;
    }
    return "";
}

int pg_encoding_verifymb ( int  encoding,
const char *  mbstr,
int  len 
)

Definition at line 1809 of file wchar.c.

References Assert, PG_SQL_ASCII, and PG_VALID_ENCODING.

Referenced by big52mic(), euc_jis_20042shift_jis_2004(), euc_jp2mic(), euc_jp2sjis(), euc_kr2mic(), euc_tw2mic(), LocalToUtf(), mic2big5(), mic2euc_jp(), mic2euc_kr(), mic2euc_tw(), mic2sjis(), shift_jis_20042euc_jis_2004(), and sjis2euc_jp().

{
    Assert(PG_VALID_ENCODING(encoding));

    return ((encoding >= 0 &&
             encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
            ((*pg_wchar_table[encoding].mbverify) ((const unsigned char *) mbstr, len)) :
            ((*pg_wchar_table[PG_SQL_ASCII].mbverify) ((const unsigned char *) mbstr, len)));
}

int pg_encoding_wchar2mb_with_len ( int  encoding,
const pg_wchar from,
char *  to,
int  len 
)

Definition at line 729 of file mbutils.c.

References pg_wchar_table.

{
    return (*pg_wchar_table[encoding].wchar2mb_with_len) (from, (unsigned char *)to, len);
}

int pg_get_client_encoding ( void   ) 

Definition at line 291 of file mbutils.c.

References Assert, and pg_enc2name::encoding.

Referenced by BeginCopy(), and xml_send().

const char* pg_get_client_encoding_name ( void   ) 

Definition at line 301 of file mbutils.c.

References Assert, and pg_enc2name::name.

int pg_mb2wchar ( const char *  from,
pg_wchar to 
)

Definition at line 693 of file mbutils.c.

References pg_enc2name::encoding, pg_wchar_tbl::mb2wchar_with_len, and pg_wchar_table.

{
    return (*pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len) ((const unsigned char *) from, to, strlen(from));
}

int pg_mb2wchar_with_len ( const char *  from,
pg_wchar to,
int  len 
)
int pg_mbcharcliplen ( const char *  mbstr,
int  len,
int  imit 
)

Definition at line 839 of file mbutils.c.

References cliplen(), pg_database_encoding_max_length(), and pg_mblen().

Referenced by bpchar(), bpchar_input(), text_left(), text_right(), varchar(), and varchar_input().

{
    int         clen = 0;
    int         nch = 0;
    int         l;

    /* optimization for single byte encoding */
    if (pg_database_encoding_max_length() == 1)
        return cliplen(mbstr, len, limit);

    while (len > 0 && *mbstr)
    {
        l = pg_mblen(mbstr);
        nch++;
        if (nch > limit)
            break;
        clen += l;
        len -= l;
        mbstr += l;
    }
    return clen;
}

int pg_mbcliplen ( const char *  mbstr,
int  len,
int  limit 
)
int pg_mblen ( const char *  mbstr  ) 
int pg_mbstrlen ( const char *  mbstr  ) 

Definition at line 751 of file mbutils.c.

References pg_database_encoding_max_length(), and pg_mblen().

Referenced by text_format_append_string().

{
    int         len = 0;

    /* optimization for single byte encoding */
    if (pg_database_encoding_max_length() == 1)
        return strlen(mbstr);

    while (*mbstr)
    {
        mbstr += pg_mblen(mbstr);
        len++;
    }
    return len;
}

int pg_mbstrlen_with_len ( const char *  mbstr,
int  len 
)

Definition at line 771 of file mbutils.c.

References pg_database_encoding_max_length(), and pg_mblen().

Referenced by bpchar(), bpchar_input(), bpcharlen(), levenshtein_internal(), lpad(), match_prosrc_to_query(), parser_errposition(), plpgsql_scanner_errposition(), rpad(), text_left(), text_length(), text_right(), and text_substring().

{
    int         len = 0;

    /* optimization for single byte encoding */
    if (pg_database_encoding_max_length() == 1)
        return limit;

    while (limit > 0 && *mbstr)
    {
        int         l = pg_mblen(mbstr);

        limit -= l;
        mbstr += l;
        len++;
    }
    return len;
}

void pg_mic2ascii ( const unsigned char *  mic,
unsigned char *  p,
int  len 
)

Definition at line 118 of file conv.c.

References IS_HIGHBIT_SET, PG_MULE_INTERNAL, PG_SQL_ASCII, and report_untranslatable_char().

Referenced by mic_to_ascii(), and utf8_to_ascii().

{
    int         c1;

    while (len > 0)
    {
        c1 = *mic;
        if (c1 == 0 || IS_HIGHBIT_SET(c1))
            report_untranslatable_char(PG_MULE_INTERNAL, PG_SQL_ASCII,
                                       (const char *) mic, len);
        *p++ = c1;
        mic++;
        len--;
    }
    *p = '\0';
}

int pg_mic_mblen ( const unsigned char *  mbstr  ) 

Definition at line 1770 of file wchar.c.

References pg_mule_mblen().

Referenced by mic2latin(), and mic2latin_with_table().

{
    return pg_mule_mblen(mbstr);
}

int pg_mule_mblen ( const unsigned char *  mbstr  ) 

Definition at line 866 of file wchar.c.

References IS_LC1, IS_LC2, IS_LCPRV1, and IS_LCPRV2.

Referenced by pg_mic_mblen(), and pg_mule_verifier().

{
    int         len;

    if (IS_LC1(*s))
        len = 2;
    else if (IS_LCPRV1(*s))
        len = 3;
    else if (IS_LC2(*s))
        len = 3;
    else if (IS_LCPRV2(*s))
        len = 4;
    else
        len = 1;                /* assume ASCII */
    return len;
}

char* pg_server_to_any ( const char *  s,
int  len,
int  encoding 
)

Definition at line 619 of file mbutils.c.

References Assert, pg_enc2name::encoding, perform_default_encoding_conversion(), pg_do_encoding_conversion(), and PG_SQL_ASCII.

Referenced by CopyAttributeOutCSV(), CopyAttributeOutText(), CopyTo(), and pg_server_to_client().

{
    Assert(DatabaseEncoding);
    Assert(ClientEncoding);

    if (len <= 0)
        return (char *) s;

    if (encoding == DatabaseEncoding->encoding ||
        encoding == PG_SQL_ASCII ||
        DatabaseEncoding->encoding == PG_SQL_ASCII)
        return (char *) s;      /* assume data is valid */

    if (ClientEncoding->encoding == encoding)
        return perform_default_encoding_conversion(s, len, false);
    else
        return (char *) pg_do_encoding_conversion(
             (unsigned char *) s, len, DatabaseEncoding->encoding, encoding);
}

char* pg_server_to_client ( const char *  s,
int  len 
)
bool pg_utf8_islegal ( const unsigned char *  source,
int  length 
)

Definition at line 1452 of file wchar.c.

Referenced by pg_utf8_verifier(), utf8_to_iso8859_1(), and UtfToLocal().

{
    unsigned char a;

    switch (length)
    {
        default:
            /* reject lengths 5 and 6 for now */
            return false;
        case 4:
            a = source[3];
            if (a < 0x80 || a > 0xBF)
                return false;
            /* FALL THRU */
        case 3:
            a = source[2];
            if (a < 0x80 || a > 0xBF)
                return false;
            /* FALL THRU */
        case 2:
            a = source[1];
            switch (*source)
            {
                case 0xE0:
                    if (a < 0xA0 || a > 0xBF)
                        return false;
                    break;
                case 0xED:
                    if (a < 0x80 || a > 0x9F)
                        return false;
                    break;
                case 0xF0:
                    if (a < 0x90 || a > 0xBF)
                        return false;
                    break;
                case 0xF4:
                    if (a < 0x80 || a > 0x8F)
                        return false;
                    break;
                default:
                    if (a < 0x80 || a > 0xBF)
                        return false;
                    break;
            }
            /* FALL THRU */
        case 1:
            a = *source;
            if (a >= 0x80 && a < 0xC2)
                return false;
            if (a > 0xF4)
                return false;
            break;
    }
    return true;
}

int pg_utf_mblen ( const unsigned char *   ) 

Definition at line 541 of file wchar.c.

Referenced by json_lex_string(), pg_utf8_verifier(), pg_wchar2utf_with_len(), utf8_to_iso8859_1(), and UtfToLocal().

{
    int         len;

    if ((*s & 0x80) == 0)
        len = 1;
    else if ((*s & 0xe0) == 0xc0)
        len = 2;
    else if ((*s & 0xf0) == 0xe0)
        len = 3;
    else if ((*s & 0xf8) == 0xf0)
        len = 4;
#ifdef NOT_USED
    else if ((*s & 0xfc) == 0xf8)
        len = 5;
    else if ((*s & 0xfe) == 0xfc)
        len = 6;
#endif
    else
        len = 1;
    return len;
}

int pg_valid_client_encoding ( const char *  name  ) 

Definition at line 401 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding().

{
    int         enc;

    if ((enc = pg_char_to_encoding(name)) < 0)
        return -1;

    if (!PG_VALID_FE_ENCODING(enc))
        return -1;

    return enc;
}

int pg_valid_server_encoding ( const char *  name  ) 

Definition at line 415 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_BE_ENCODING.

Referenced by createdb(), get_encoding_id(), and parse_extension_control_file().

{
    int         enc;

    if ((enc = pg_char_to_encoding(name)) < 0)
        return -1;

    if (!PG_VALID_BE_ENCODING(enc))
        return -1;

    return enc;
}

int pg_valid_server_encoding_id ( int  encoding  ) 

Definition at line 429 of file encnames.c.

bool pg_verify_mbstr ( int  encoding,
const char *  mbstr,
int  len,
bool  noError 
)

Definition at line 1880 of file wchar.c.

References pg_verify_mbstr_len().

Referenced by pg_any_to_server(), and t_readline().

{
    return pg_verify_mbstr_len(encoding, mbstr, len, noError) >= 0;
}

int pg_verify_mbstr_len ( int  encoding,
const char *  mbstr,
int  len,
bool  noError 
)

Definition at line 1897 of file wchar.c.

References Assert, IS_HIGHBIT_SET, pg_wchar_tbl::mbverify, NULL, pg_encoding_max_length(), PG_VALID_ENCODING, and report_invalid_encoding().

Referenced by length_in_encoding(), pg_convert(), pg_verify_mbstr(), pg_verifymbstr(), read_extension_script_file(), and utf_u2e().

{
    mbverifier  mbverify;
    int         mb_len;

    Assert(PG_VALID_ENCODING(encoding));

    /*
     * In single-byte encodings, we need only reject nulls (\0).
     */
    if (pg_encoding_max_length(encoding) <= 1)
    {
        const char *nullpos = memchr(mbstr, 0, len);

        if (nullpos == NULL)
            return len;
        if (noError)
            return -1;
        report_invalid_encoding(encoding, nullpos, 1);
    }

    /* fetch function pointer just once */
    mbverify = pg_wchar_table[encoding].mbverify;

    mb_len = 0;

    while (len > 0)
    {
        int         l;

        /* fast path for ASCII-subset characters */
        if (!IS_HIGHBIT_SET(*mbstr))
        {
            if (*mbstr != '\0')
            {
                mb_len++;
                mbstr++;
                len--;
                continue;
            }
            if (noError)
                return -1;
            report_invalid_encoding(encoding, mbstr, len);
        }

        l = (*mbverify) ((const unsigned char *) mbstr, len);

        if (l < 0)
        {
            if (noError)
                return -1;
            report_invalid_encoding(encoding, mbstr, len);
        }

        mbstr += l;
        len -= l;
        mb_len++;
    }
    return mb_len;
}

bool pg_verifymbstr ( const char *  mbstr,
int  len,
bool  noError 
)
int pg_wchar2mb ( const pg_wchar from,
char *  to 
)

Definition at line 715 of file mbutils.c.

References pg_enc2name::encoding, pg_wchar_strlen(), pg_wchar_table, and pg_wchar_tbl::wchar2mb_with_len.

{
    return (*pg_wchar_table[DatabaseEncoding->encoding].wchar2mb_with_len) (from, (unsigned char *)to, pg_wchar_strlen(from));
}

int pg_wchar2mb_with_len ( const pg_wchar from,
char *  to,
int  len 
)

Definition at line 722 of file mbutils.c.

References pg_enc2name::encoding, pg_wchar_table, and pg_wchar_tbl::wchar2mb_with_len.

Referenced by convertPgWchar(), and regexp_fixed_prefix().

{
    return (*pg_wchar_table[DatabaseEncoding->encoding].wchar2mb_with_len) (from, (unsigned char *)to, len);
}

size_t pg_wchar_strlen ( const pg_wchar wstr  ) 

Definition at line 70 of file wstrncmp.c.

Referenced by pg_wchar2mb().

{
    const pg_wchar *s;

    for (s = str; *s; ++s)
        ;
    return (s - str);
}

int pg_wchar_strncmp ( const pg_wchar s1,
const pg_wchar s2,
size_t  n 
)

Definition at line 40 of file wstrncmp.c.

{
    if (n == 0)
        return 0;
    do
    {
        if (*s1 != *s2++)
            return (*s1 - *(s2 - 1));
        if (*s1++ == 0)
            break;
    } while (--n != 0);
    return 0;
}

int PrepareClientEncoding ( int  encoding  ) 

Definition at line 88 of file mbutils.c.

References backend_startup_complete, ConvProcInfo::c_encoding, FindDefaultConversionProc(), fmgr_info_cxt(), GetDatabaseEncoding(), IsTransactionState(), lcons(), lfirst, MemoryContextAlloc(), MemoryContextSwitchTo(), OidIsValid, PG_SQL_ASCII, PG_VALID_FE_ENCODING, ConvProcInfo::s_encoding, ConvProcInfo::to_client_info, ConvProcInfo::to_server_info, and TopMemoryContext.

Referenced by check_client_encoding(), and InitializeClientEncoding().

{
    int         current_server_encoding;
    ListCell   *lc;

    if (!PG_VALID_FE_ENCODING(encoding))
        return -1;

    /* Can't do anything during startup, per notes above */
    if (!backend_startup_complete)
        return 0;

    current_server_encoding = GetDatabaseEncoding();

    /*
     * Check for cases that require no conversion function.
     */
    if (current_server_encoding == encoding ||
        current_server_encoding == PG_SQL_ASCII ||
        encoding == PG_SQL_ASCII)
        return 0;

    if (IsTransactionState())
    {
        /*
         * If we're in a live transaction, it's safe to access the catalogs,
         * so look up the functions.  We repeat the lookup even if the info is
         * already cached, so that we can react to changes in the contents of
         * pg_conversion.
         */
        Oid         to_server_proc,
                    to_client_proc;
        ConvProcInfo *convinfo;
        MemoryContext oldcontext;

        to_server_proc = FindDefaultConversionProc(encoding,
                                                   current_server_encoding);
        if (!OidIsValid(to_server_proc))
            return -1;
        to_client_proc = FindDefaultConversionProc(current_server_encoding,
                                                   encoding);
        if (!OidIsValid(to_client_proc))
            return -1;

        /*
         * Load the fmgr info into TopMemoryContext (could still fail here)
         */
        convinfo = (ConvProcInfo *) MemoryContextAlloc(TopMemoryContext,
                                                       sizeof(ConvProcInfo));
        convinfo->s_encoding = current_server_encoding;
        convinfo->c_encoding = encoding;
        fmgr_info_cxt(to_server_proc, &convinfo->to_server_info,
                      TopMemoryContext);
        fmgr_info_cxt(to_client_proc, &convinfo->to_client_info,
                      TopMemoryContext);

        /* Attach new info to head of list */
        oldcontext = MemoryContextSwitchTo(TopMemoryContext);
        ConvProcList = lcons(convinfo, ConvProcList);
        MemoryContextSwitchTo(oldcontext);

        /*
         * We cannot yet remove any older entry for the same encoding pair,
         * since it could still be in use.  SetClientEncoding will clean up.
         */

        return 0;               /* success */
    }
    else
    {
        /*
         * If we're not in a live transaction, the only thing we can do is
         * restore a previous setting using the cache.  This covers all
         * transaction-rollback cases.  The only case it might not work for is
         * trying to change client_encoding on the fly by editing
         * postgresql.conf and SIGHUP'ing.  Which would probably be a stupid
         * thing to do anyway.
         */
        foreach(lc, ConvProcList)
        {
            ConvProcInfo *oldinfo = (ConvProcInfo *) lfirst(lc);

            if (oldinfo->s_encoding == current_server_encoding &&
                oldinfo->c_encoding == encoding)
                return 0;
        }

        return -1;              /* it's not cached, so fail */
    }
}

void report_invalid_encoding ( int  encoding,
const char *  mbstr,
int  len 
)

Definition at line 1998 of file wchar.c.

References buf, ereport, errcode(), errmsg(), ERROR, Min, name, pg_enc2name_tbl, and pg_encoding_mblen().

Referenced by big52mic(), euc_cn2mic(), euc_jis_20042shift_jis_2004(), euc_jp2mic(), euc_jp2sjis(), euc_kr2mic(), euc_tw2mic(), iso8859_1_to_utf8(), latin2mic(), latin2mic_with_table(), LocalToUtf(), mic2big5(), mic2euc_cn(), mic2euc_jp(), mic2euc_kr(), mic2euc_tw(), mic2latin(), mic2latin_with_table(), mic2sjis(), pg_ascii2mic(), pg_verify_mbstr_len(), shift_jis_20042euc_jis_2004(), sjis2euc_jp(), sjis2mic(), utf8_to_iso8859_1(), and UtfToLocal().

{
    int         l = pg_encoding_mblen(encoding, mbstr);
    char        buf[8 * 5 + 1];
    char       *p = buf;
    int         j,
                jlimit;

    jlimit = Min(l, len);
    jlimit = Min(jlimit, 8);    /* prevent buffer overrun */

    for (j = 0; j < jlimit; j++)
    {
        p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
        if (j < jlimit - 1)
            p += sprintf(p, " ");
    }

    ereport(ERROR,
            (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
             errmsg("invalid byte sequence for encoding \"%s\": %s",
                    pg_enc2name_tbl[encoding].name,
                    buf)));
}

void report_untranslatable_char ( int  src_encoding,
int  dest_encoding,
const char *  mbstr,
int  len 
)

Definition at line 2030 of file wchar.c.

References buf, ereport, errcode(), errmsg(), ERROR, Min, name, pg_enc2name_tbl, and pg_encoding_mblen().

Referenced by big52mic(), latin2mic_with_table(), LocalToUtf(), mic2big5(), mic2euc_cn(), mic2euc_jp(), mic2euc_kr(), mic2euc_tw(), mic2latin(), mic2latin_with_table(), mic2sjis(), pg_mic2ascii(), utf8_to_iso8859_1(), and UtfToLocal().

{
    int         l = pg_encoding_mblen(src_encoding, mbstr);
    char        buf[8 * 5 + 1];
    char       *p = buf;
    int         j,
                jlimit;

    jlimit = Min(l, len);
    jlimit = Min(jlimit, 8);    /* prevent buffer overrun */

    for (j = 0; j < jlimit; j++)
    {
        p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
        if (j < jlimit - 1)
            p += sprintf(p, " ");
    }

    ereport(ERROR,
            (errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
             errmsg("character with byte sequence %s in encoding \"%s\" has no equivalent in encoding \"%s\"",
                    buf,
                    pg_enc2name_tbl[src_encoding].name,
                    pg_enc2name_tbl[dest_encoding].name)));
}

int SetClientEncoding ( int  encoding  ) 

Definition at line 186 of file mbutils.c.

References backend_startup_complete, ConvProcInfo::c_encoding, GetDatabaseEncoding(), lfirst, list_delete_cell(), list_head(), lnext, pending_client_encoding, pfree(), pg_enc2name_tbl, PG_SQL_ASCII, PG_VALID_FE_ENCODING, ConvProcInfo::s_encoding, ConvProcInfo::to_client_info, and ConvProcInfo::to_server_info.

Referenced by assign_client_encoding(), and InitializeClientEncoding().

{
    int         current_server_encoding;
    bool        found;
    ListCell   *lc;
    ListCell   *prev;
    ListCell   *next;

    if (!PG_VALID_FE_ENCODING(encoding))
        return -1;

    /* Can't do anything during startup, per notes above */
    if (!backend_startup_complete)
    {
        pending_client_encoding = encoding;
        return 0;
    }

    current_server_encoding = GetDatabaseEncoding();

    /*
     * Check for cases that require no conversion function.
     */
    if (current_server_encoding == encoding ||
        current_server_encoding == PG_SQL_ASCII ||
        encoding == PG_SQL_ASCII)
    {
        ClientEncoding = &pg_enc2name_tbl[encoding];
        ToServerConvProc = NULL;
        ToClientConvProc = NULL;
        return 0;
    }

    /*
     * Search the cache for the entry previously prepared by
     * PrepareClientEncoding; if there isn't one, we lose.  While at it,
     * release any duplicate entries so that repeated Prepare/Set cycles don't
     * leak memory.
     */
    found = false;
    prev = NULL;
    for (lc = list_head(ConvProcList); lc; lc = next)
    {
        ConvProcInfo *convinfo = (ConvProcInfo *) lfirst(lc);

        next = lnext(lc);

        if (convinfo->s_encoding == current_server_encoding &&
            convinfo->c_encoding == encoding)
        {
            if (!found)
            {
                /* Found newest entry, so set up */
                ClientEncoding = &pg_enc2name_tbl[encoding];
                ToServerConvProc = &convinfo->to_server_info;
                ToClientConvProc = &convinfo->to_client_info;
                found = true;
            }
            else
            {
                /* Duplicate entry, release it */
                ConvProcList = list_delete_cell(ConvProcList, lc, prev);
                pfree(convinfo);
                continue;       /* prev mustn't advance */
            }
        }

        prev = lc;
    }

    if (found)
        return 0;               /* success */
    else
        return -1;              /* it's not cached, so fail */
}

void SetDatabaseEncoding ( int  encoding  ) 
unsigned char* unicode_to_utf8 ( pg_wchar  c,
unsigned char *  utf8string 
)

Definition at line 475 of file wchar.c.

Referenced by json_lex_string(), pg_wchar2utf_with_len(), and unicode_to_sqlchar().

{
    if (c <= 0x7F)
    {
        utf8string[0] = c;
    }
    else if (c <= 0x7FF)
    {
        utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
        utf8string[1] = 0x80 | (c & 0x3F);
    }
    else if (c <= 0xFFFF)
    {
        utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
        utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
        utf8string[2] = 0x80 | (c & 0x3F);
    }
    else
    {
        utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
        utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
        utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
        utf8string[3] = 0x80 | (c & 0x3F);
    }

    return utf8string;
}

pg_wchar utf8_to_unicode ( const unsigned char *  c  ) 

Definition at line 714 of file wchar.c.

Referenced by pg_utf_dsplen(), and pg_wcsformat().

{
    if ((*c & 0x80) == 0)
        return (pg_wchar) c[0];
    else if ((*c & 0xe0) == 0xc0)
        return (pg_wchar) (((c[0] & 0x1f) << 6) |
                           (c[1] & 0x3f));
    else if ((*c & 0xf0) == 0xe0)
        return (pg_wchar) (((c[0] & 0x0f) << 12) |
                           ((c[1] & 0x3f) << 6) |
                           (c[2] & 0x3f));
    else if ((*c & 0xf8) == 0xf0)
        return (pg_wchar) (((c[0] & 0x07) << 18) |
                           ((c[1] & 0x3f) << 12) |
                           ((c[2] & 0x3f) << 6) |
                           (c[3] & 0x3f));
    else
        /* that is an invalid code on purpose */
        return 0xffffffff;
}

void UtfToLocal ( const unsigned char *  utf,
unsigned char *  iso,
const pg_utf_to_local map,
const pg_utf_to_local_combined cmap,
int  size1,
int  size2,
int  encoding,
int  len 
)

Definition at line 336 of file conv.c.

References pg_utf_to_local_combined::code, pg_utf_to_local::code, compare1(), compare3(), NULL, PG_UTF8, pg_utf8_islegal(), pg_utf_mblen(), report_invalid_encoding(), report_untranslatable_char(), and set_iso_code().

Referenced by utf8_to_big5(), utf8_to_euc_cn(), utf8_to_euc_jis_2004(), utf8_to_euc_jp(), utf8_to_euc_kr(), utf8_to_euc_tw(), utf8_to_gb18030(), utf8_to_gbk(), utf8_to_iso8859(), utf8_to_johab(), utf8_to_koi8r(), utf8_to_koi8u(), utf8_to_shift_jis_2004(), utf8_to_sjis(), utf8_to_uhc(), and utf8_to_win().

{
    uint32      iutf;
    uint32      cutf[2];
    uint32      code;
    pg_utf_to_local *p;
    pg_utf_to_local_combined *cp;
    int         l;

    for (; len > 0; len -= l)
    {
        /* "break" cases all represent errors */
        if (*utf == '\0')
            break;

        l = pg_utf_mblen(utf);

        if (len < l)
            break;

        if (!pg_utf8_islegal(utf, l))
            break;

        if (l == 1)
        {
            /* ASCII case is easy */
            *iso++ = *utf++;
            continue;
        }
        else if (l == 2)
        {
            iutf = *utf++ << 8;
            iutf |= *utf++;
        }
        else if (l == 3)
        {
            iutf = *utf++ << 16;
            iutf |= *utf++ << 8;
            iutf |= *utf++;
        }
        else if (l == 4)
        {
            iutf = *utf++ << 24;
            iutf |= *utf++ << 16;
            iutf |= *utf++ << 8;
            iutf |= *utf++;
        }

        /*
         * first, try with combined map if possible
         */
        if (cmap && len > l)
        {
            const unsigned char *utf_save = utf;
            int         len_save = len;
            int         l_save = l;

            len -= l;

            l = pg_utf_mblen(utf);
            if (len < l)
                break;

            if (!pg_utf8_islegal(utf, l))
                break;

            cutf[0] = iutf;

            if (l == 1)
            {
                if (len_save > 1)
                {
                    p = bsearch(&cutf[0], map, size1,
                                sizeof(pg_utf_to_local), compare1);
                    if (p == NULL)
                        report_untranslatable_char(PG_UTF8, encoding,
                               (const char *) (utf_save - l_save), len_save);
                    iso = set_iso_code(iso, p->code);
                }

                /* ASCII case is easy */
                *iso++ = *utf++;
                continue;
            }
            else if (l == 2)
            {
                iutf = *utf++ << 8;
                iutf |= *utf++;
            }
            else if (l == 3)
            {
                iutf = *utf++ << 16;
                iutf |= *utf++ << 8;
                iutf |= *utf++;
            }
            else if (l == 4)
            {
                iutf = *utf++ << 24;
                iutf |= *utf++ << 16;
                iutf |= *utf++ << 8;
                iutf |= *utf++;
            }

            cutf[1] = iutf;
            cp = bsearch(cutf, cmap, size2,
                         sizeof(pg_utf_to_local_combined), compare3);
            if (cp)
                code = cp->code;
            else
            {
                /* not found in combined map. try with ordinary map */
                p = bsearch(&cutf[0], map, size1,
                            sizeof(pg_utf_to_local), compare1);
                if (p == NULL)
                    report_untranslatable_char(PG_UTF8, encoding,
                               (const char *) (utf_save - l_save), len_save);
                iso = set_iso_code(iso, p->code);

                p = bsearch(&cutf[1], map, size1,
                            sizeof(pg_utf_to_local), compare1);
                if (p == NULL)
                    report_untranslatable_char(PG_UTF8, encoding,
                                               (const char *) (utf - l), len);
                code = p->code;
            }
        }
        else    /* no cmap or no remaining data */
        {
            p = bsearch(&iutf, map, size1,
                        sizeof(pg_utf_to_local), compare1);
            if (p == NULL)
                report_untranslatable_char(PG_UTF8, encoding,
                                           (const char *) (utf - l), len);
            code = p->code;
        }
        iso = set_iso_code(iso, code);
    }

    if (len > 0)
        report_invalid_encoding(PG_UTF8, (const char *) utf, len);

    *iso = '\0';
}


Variable Documentation

Definition at line 357 of file encnames.c.

Referenced by pg_bind_textdomain_codeset().

Definition at line 32 of file encnames.c.

unsigned int pg_encname_tbl_sz

Definition at line 294 of file encnames.c.

Referenced by pg_char_to_encname_struct().