PostgreSQL Source Code  git master
pg_wchar.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_enc2name
 
struct  pg_enc2gettext
 
struct  pg_wchar_tbl
 
struct  pg_mb_radix_tree
 
struct  pg_utf_to_local_combined
 
struct  pg_local_to_utf_combined
 

Macros

#define MAX_MULTIBYTE_CHAR_LEN   4
 
#define SS2   0x8e /* single shift 2 (JIS0201) */
 
#define SS3   0x8f /* single shift 3 (JIS0212) */
 
#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 /* ISO8859 Latin 1 */
 
#define LC_ISO8859_2   0x82 /* ISO8859 Latin 2 */
 
#define LC_ISO8859_3   0x83 /* ISO8859 Latin 3 */
 
#define LC_ISO8859_4   0x84 /* ISO8859 Latin 4 */
 
#define LC_TIS620   0x85 /* Thai (not supported yet) */
 
#define LC_ISO8859_7   0x86 /* Greek (not supported yet) */
 
#define LC_ISO8859_6   0x87 /* Arabic (not supported yet) */
 
#define LC_ISO8859_8   0x88 /* Hebrew (not supported yet) */
 
#define LC_JISX0201K   0x89 /* Japanese 1 byte kana */
 
#define LC_JISX0201R   0x8a /* Japanese 1 byte Roman */
 
#define LC_KOI8_R   0x8b /* Cyrillic KOI8-R */
 
#define LC_ISO8859_5   0x8c /* ISO8859 Cyrillic */
 
#define LC_ISO8859_9   0x8d /* ISO8859 Latin 5 (not supported yet) */
 
#define LC_ISO8859_15   0x8e /* ISO8859 Latin 15 (not supported yet) */
 
#define IS_LC1(c)   ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)
 
#define LC_JISX0208_1978   0x90 /* Japanese Kanji, old JIS (not supported) */
 
#define LC_GB2312_80   0x91 /* Chinese */
 
#define LC_JISX0208   0x92 /* Japanese Kanji (JIS X 0208) */
 
#define LC_KS5601   0x93 /* Korean */
 
#define LC_JISX0212   0x94 /* Japanese Kanji (JIS X 0212) */
 
#define LC_CNS11643_1   0x95 /* CNS 11643-1992 Plane 1 */
 
#define LC_CNS11643_2   0x96 /* CNS 11643-1992 Plane 2 */
 
#define LC_JISX0213_1
 
#define LC_BIG5_1
 
#define LC_BIG5_2
 
#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
 
#define LC_IPA
 
#define LC_VISCII_LOWER
 
#define LC_VISCII_UPPER
 
#define LC_ARABIC_DIGIT   0xa4 /* Arabic digit (not supported) */
 
#define LC_ARABIC_1_COLUMN   0xa5 /* Arabic 1-column (not supported) */
 
#define LC_ASCII_RIGHT_TO_LEFT
 
#define LC_LAO
 
#define LC_ARABIC_2_COLUMN   0xa8 /* Arabic 1-column (not supported) */
 
#define LC_INDIAN_1_COLUMN
 
#define LC_TIBETAN_1_COLUMN
 
#define LC_UNICODE_SUBSET_2
 
#define LC_UNICODE_SUBSET_3
 
#define LC_UNICODE_SUBSET
 
#define LC_ETHIOPIC   0xf5 /* Ethiopic characters (not supported) */
 
#define LC_CNS11643_3   0xf6 /* CNS 11643-1992 Plane 3 */
 
#define LC_CNS11643_4   0xf7 /* CNS 11643-1992 Plane 4 */
 
#define LC_CNS11643_5   0xf8 /* CNS 11643-1992 Plane 5 */
 
#define LC_CNS11643_6   0xf9 /* CNS 11643-1992 Plane 6 */
 
#define LC_CNS11643_7   0xfa /* CNS 11643-1992 Plane 7 */
 
#define LC_INDIAN_2_COLUMN
 
#define LC_TIBETAN   0xfc /* Tibetan (not supported) */
 
#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 MAX_CONVERSION_GROWTH   4
 
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
 

Typedefs

typedef unsigned int pg_wchar
 
typedef enum pg_enc pg_enc
 
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)
 
typedef uint32(* utf_local_conversion_func) (uint32 code)
 

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

bool is_encoding_supported_by_icu (int encoding)
 
const char * get_encoding_name_for_icu (int encoding)
 
int pg_char_to_encoding (const char *name)
 
const char * pg_encoding_to_char (int encoding)
 
int pg_valid_server_encoding_id (int encoding)
 
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 limit)
 
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)
 
void SetMessageEncoding (int encoding)
 
int GetMessageEncoding (void)
 
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 UtfToLocal (const unsigned char *utf, int len, unsigned char *iso, const pg_mb_radix_tree *map, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
 
void LocalToUtf (const unsigned char *iso, int len, unsigned char *utf, const pg_mb_radix_tree *map, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
 
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) pg_attribute_noreturn()
 
void report_untranslatable_char (int src_encoding, int dest_encoding, const char *mbstr, int len) pg_attribute_noreturn()
 
void local2local (const unsigned char *l, unsigned char *p, int len, int src_encoding, int dest_encoding, const unsigned char *tab)
 
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

const pg_enc2name pg_enc2name_tbl []
 
const pg_enc2gettext pg_enc2gettext_tbl []
 
const pg_wchar_tbl pg_wchar_table []
 

Macro Definition Documentation

◆ CHECK_ENCODING_CONVERSION_ARGS

#define CHECK_ENCODING_CONVERSION_ARGS (   srcencoding,
  destencoding 
)
Value:
(srcencoding), \
(destencoding))
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
void check_encoding_conversion_args(int src_encoding, int dest_encoding, int len, int expected_src_encoding, int expected_dest_encoding)
Definition: wchar.c:2014

Definition at line 503 of file pg_wchar.h.

Referenced by 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_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_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().

◆ IS_LC1

#define IS_LC1 (   c)    ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d)

◆ IS_LC2

#define IS_LC2 (   c)    ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99)

◆ IS_LCPRV1

#define IS_LCPRV1 (   c)    ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B)

Definition at line 152 of file pg_wchar.h.

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

◆ IS_LCPRV1_A_RANGE

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

Definition at line 153 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ IS_LCPRV1_B_RANGE

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

Definition at line 155 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ IS_LCPRV2

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

Definition at line 164 of file pg_wchar.h.

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

◆ IS_LCPRV2_A_RANGE

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

Definition at line 165 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ IS_LCPRV2_B_RANGE

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

Definition at line 167 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ ISSJISHEAD

#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().

◆ ISSJISTAIL

#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().

◆ LC_ARABIC_1_COLUMN

#define LC_ARABIC_1_COLUMN   0xa5 /* Arabic 1-column (not supported) */

Definition at line 182 of file pg_wchar.h.

◆ LC_ARABIC_2_COLUMN

#define LC_ARABIC_2_COLUMN   0xa8 /* Arabic 1-column (not supported) */

Definition at line 188 of file pg_wchar.h.

◆ LC_ARABIC_DIGIT

#define LC_ARABIC_DIGIT   0xa4 /* Arabic digit (not supported) */

Definition at line 181 of file pg_wchar.h.

◆ LC_ASCII_RIGHT_TO_LEFT

#define LC_ASCII_RIGHT_TO_LEFT
Value:
0xa6 /* ASCII (left half of ISO8859-1) with
* right-to-left direction (not
* supported) */

Definition at line 183 of file pg_wchar.h.

◆ LC_BIG5_1

#define LC_BIG5_1
Value:
0x98 /* Plane 1 Chinese traditional (not
* supported) */

Definition at line 138 of file pg_wchar.h.

◆ LC_BIG5_2

#define LC_BIG5_2
Value:
0x99 /* Plane 1 Chinese traditional (not
* supported) */

Definition at line 140 of file pg_wchar.h.

◆ LC_CNS11643_1

#define LC_CNS11643_1   0x95 /* CNS 11643-1992 Plane 1 */

Definition at line 134 of file pg_wchar.h.

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

◆ LC_CNS11643_2

#define LC_CNS11643_2   0x96 /* CNS 11643-1992 Plane 2 */

Definition at line 135 of file pg_wchar.h.

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

◆ LC_CNS11643_3

#define LC_CNS11643_3   0xf6 /* CNS 11643-1992 Plane 3 */

Definition at line 204 of file pg_wchar.h.

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

◆ LC_CNS11643_4

#define LC_CNS11643_4   0xf7 /* CNS 11643-1992 Plane 4 */

Definition at line 205 of file pg_wchar.h.

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

◆ LC_CNS11643_5

#define LC_CNS11643_5   0xf8 /* CNS 11643-1992 Plane 5 */

Definition at line 206 of file pg_wchar.h.

◆ LC_CNS11643_6

#define LC_CNS11643_6   0xf9 /* CNS 11643-1992 Plane 6 */

Definition at line 207 of file pg_wchar.h.

◆ LC_CNS11643_7

#define LC_CNS11643_7   0xfa /* CNS 11643-1992 Plane 7 */

Definition at line 208 of file pg_wchar.h.

Referenced by mic2euc_tw().

◆ LC_ETHIOPIC

#define LC_ETHIOPIC   0xf5 /* Ethiopic characters (not supported) */

Definition at line 203 of file pg_wchar.h.

◆ LC_GB2312_80

#define LC_GB2312_80   0x91 /* Chinese */

Definition at line 130 of file pg_wchar.h.

Referenced by euc_cn2mic(), and mic2euc_cn().

◆ LC_INDIAN_1_COLUMN

#define LC_INDIAN_1_COLUMN
Value:
0xf0 /* Indian charset for 1-column width
* glyphs (not supported) */

Definition at line 193 of file pg_wchar.h.

◆ LC_INDIAN_2_COLUMN

#define LC_INDIAN_2_COLUMN
Value:
0xfb /* Indian charset for 2-column width
* glyphs (not supported) */

Definition at line 209 of file pg_wchar.h.

◆ LC_IPA

#define LC_IPA
Value:
0xa1 /* IPA (International Phonetic
* Association) (not supported) */

Definition at line 175 of file pg_wchar.h.

◆ LC_ISO8859_1

#define LC_ISO8859_1   0x81 /* ISO8859 Latin 1 */

Definition at line 102 of file pg_wchar.h.

Referenced by latin1_to_mic(), and mic_to_latin1().

◆ LC_ISO8859_15

#define LC_ISO8859_15   0x8e /* ISO8859 Latin 15 (not supported yet) */

Definition at line 119 of file pg_wchar.h.

◆ LC_ISO8859_2

#define LC_ISO8859_2   0x82 /* ISO8859 Latin 2 */

Definition at line 103 of file pg_wchar.h.

Referenced by latin2_to_mic(), mic_to_latin2(), mic_to_win1250(), and win1250_to_mic().

◆ LC_ISO8859_3

#define LC_ISO8859_3   0x83 /* ISO8859 Latin 3 */

Definition at line 104 of file pg_wchar.h.

Referenced by latin3_to_mic(), and mic_to_latin3().

◆ LC_ISO8859_4

#define LC_ISO8859_4   0x84 /* ISO8859 Latin 4 */

Definition at line 105 of file pg_wchar.h.

Referenced by latin4_to_mic(), and mic_to_latin4().

◆ LC_ISO8859_5

#define LC_ISO8859_5   0x8c /* ISO8859 Cyrillic */

Definition at line 117 of file pg_wchar.h.

◆ LC_ISO8859_6

#define LC_ISO8859_6   0x87 /* Arabic (not supported yet) */

Definition at line 108 of file pg_wchar.h.

◆ LC_ISO8859_7

#define LC_ISO8859_7   0x86 /* Greek (not supported yet) */

Definition at line 107 of file pg_wchar.h.

◆ LC_ISO8859_8

#define LC_ISO8859_8   0x88 /* Hebrew (not supported yet) */

Definition at line 109 of file pg_wchar.h.

◆ LC_ISO8859_9

#define LC_ISO8859_9   0x8d /* ISO8859 Latin 5 (not supported yet) */

Definition at line 118 of file pg_wchar.h.

◆ LC_JISX0201K

#define LC_JISX0201K   0x89 /* Japanese 1 byte kana */

Definition at line 110 of file pg_wchar.h.

Referenced by euc_jp2mic(), mic2euc_jp(), mic2sjis(), and sjis2mic().

◆ LC_JISX0201R

#define LC_JISX0201R   0x8a /* Japanese 1 byte Roman */

Definition at line 111 of file pg_wchar.h.

◆ LC_JISX0208

#define LC_JISX0208   0x92 /* Japanese Kanji (JIS X 0208) */

Definition at line 131 of file pg_wchar.h.

Referenced by euc_jp2mic(), mic2euc_jp(), mic2sjis(), and sjis2mic().

◆ LC_JISX0208_1978

#define LC_JISX0208_1978   0x90 /* Japanese Kanji, old JIS (not supported) */

Definition at line 129 of file pg_wchar.h.

◆ LC_JISX0212

#define LC_JISX0212   0x94 /* Japanese Kanji (JIS X 0212) */

Definition at line 133 of file pg_wchar.h.

Referenced by euc_jp2mic(), mic2euc_jp(), mic2sjis(), and sjis2mic().

◆ LC_JISX0213_1

#define LC_JISX0213_1
Value:
0x97 /* Japanese Kanji (JIS X 0213 Plane 1)
* (not supported) */

Definition at line 136 of file pg_wchar.h.

◆ LC_KOI8_R

#define LC_KOI8_R   0x8b /* Cyrillic KOI8-R */

◆ LC_KS5601

#define LC_KS5601   0x93 /* Korean */

Definition at line 132 of file pg_wchar.h.

Referenced by euc_kr2mic(), and mic2euc_kr().

◆ LC_LAO

#define LC_LAO
Value:
0xa7 /* Lao characters (ISO10646 0E80..0EDF)
* (not supported) */

Definition at line 186 of file pg_wchar.h.

◆ LC_SISHENG

#define LC_SISHENG
Value:
0xa0 /* Chinese SiSheng characters for
* PinYin/ZhuYin (not supported) */

Definition at line 173 of file pg_wchar.h.

◆ LC_TIBETAN

#define LC_TIBETAN   0xfc /* Tibetan (not supported) */

Definition at line 211 of file pg_wchar.h.

◆ LC_TIBETAN_1_COLUMN

#define LC_TIBETAN_1_COLUMN
Value:
0xf1 /* Tibetan 1-column width glyphs (not
* supported) */

Definition at line 195 of file pg_wchar.h.

◆ LC_TIS620

#define LC_TIS620   0x85 /* Thai (not supported yet) */

Definition at line 106 of file pg_wchar.h.

◆ LC_UNICODE_SUBSET

#define LC_UNICODE_SUBSET
Value:
0xf4 /* Unicode characters of the range
* U+0100..U+24FF. (not supported) */

Definition at line 201 of file pg_wchar.h.

◆ LC_UNICODE_SUBSET_2

#define LC_UNICODE_SUBSET_2
Value:
0xf2 /* Unicode characters of the range
* U+2500..U+33FF. (not supported) */

Definition at line 197 of file pg_wchar.h.

◆ LC_UNICODE_SUBSET_3

#define LC_UNICODE_SUBSET_3
Value:
0xf3 /* Unicode characters of the range
* U+E000..U+FFFF. (not supported) */

Definition at line 199 of file pg_wchar.h.

◆ LC_VISCII_LOWER

#define LC_VISCII_LOWER
Value:
0xa2 /* Vietnamese VISCII1.1 lower-case (not
* supported) */

Definition at line 177 of file pg_wchar.h.

◆ LC_VISCII_UPPER

#define LC_VISCII_UPPER
Value:
0xa3 /* Vietnamese VISCII1.1 upper-case (not
* supported) */

Definition at line 179 of file pg_wchar.h.

◆ LCPRV1_A

#define LCPRV1_A   0x9a

Definition at line 150 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ LCPRV1_B

#define LCPRV1_B   0x9b

Definition at line 151 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ LCPRV2_A

#define LCPRV2_A   0x9c

Definition at line 162 of file pg_wchar.h.

Referenced by pg_wchar2mule_with_len().

◆ LCPRV2_B

#define LCPRV2_B   0x9d

Definition at line 163 of file pg_wchar.h.

Referenced by big52mic(), euc_tw2mic(), mic2big5(), mic2euc_tw(), and pg_wchar2mule_with_len().

◆ MAX_CONVERSION_GROWTH

#define MAX_CONVERSION_GROWTH   4

◆ MAX_MULTIBYTE_CHAR_LEN

#define MAX_MULTIBYTE_CHAR_LEN   4

Definition at line 30 of file pg_wchar.h.

Referenced by convertPgWchar(), fillTrgm(), packArcInfoCmp(), and xml_is_document().

◆ PG_ENCODING_BE_LAST

#define PG_ENCODING_BE_LAST   PG_KOI8U

Definition at line 289 of file pg_wchar.h.

Referenced by get_encoding_name_for_icu().

◆ PG_ENCODING_IS_CLIENT_ONLY

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

Definition at line 298 of file pg_wchar.h.

Referenced by BeginCopy().

◆ PG_VALID_BE_ENCODING

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

◆ PG_VALID_ENCODING

◆ PG_VALID_FE_ENCODING

#define PG_VALID_FE_ENCODING (   _enc)    PG_VALID_ENCODING(_enc)

Definition at line 305 of file pg_wchar.h.

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

◆ SS2

◆ SS3

Typedef Documentation

◆ mb2wchar_with_len_converter

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

Definition at line 357 of file pg_wchar.h.

◆ mbcharacter_incrementer

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

Definition at line 369 of file pg_wchar.h.

◆ mbdisplaylen_converter

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

Definition at line 367 of file pg_wchar.h.

◆ mblen_converter

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

Definition at line 365 of file pg_wchar.h.

◆ mbverifier

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

Definition at line 371 of file pg_wchar.h.

◆ pg_enc

typedef enum pg_enc pg_enc

◆ pg_enc2gettext

◆ pg_enc2name

typedef struct pg_enc2name pg_enc2name

◆ pg_wchar

typedef unsigned int pg_wchar

Definition at line 25 of file pg_wchar.h.

◆ utf_local_conversion_func

typedef uint32(* utf_local_conversion_func) (uint32 code)

Definition at line 495 of file pg_wchar.h.

◆ wchar2mb_with_len_converter

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

Definition at line 361 of file pg_wchar.h.

Enumeration Type Documentation

◆ pg_enc

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 238 of file pg_wchar.h.

239 {
240  PG_SQL_ASCII = 0, /* SQL/ASCII */
241  PG_EUC_JP, /* EUC for Japanese */
242  PG_EUC_CN, /* EUC for Chinese */
243  PG_EUC_KR, /* EUC for Korean */
244  PG_EUC_TW, /* EUC for Taiwan */
245  PG_EUC_JIS_2004, /* EUC-JIS-2004 */
246  PG_UTF8, /* Unicode UTF8 */
247  PG_MULE_INTERNAL, /* Mule internal code */
248  PG_LATIN1, /* ISO-8859-1 Latin 1 */
249  PG_LATIN2, /* ISO-8859-2 Latin 2 */
250  PG_LATIN3, /* ISO-8859-3 Latin 3 */
251  PG_LATIN4, /* ISO-8859-4 Latin 4 */
252  PG_LATIN5, /* ISO-8859-9 Latin 5 */
253  PG_LATIN6, /* ISO-8859-10 Latin6 */
254  PG_LATIN7, /* ISO-8859-13 Latin7 */
255  PG_LATIN8, /* ISO-8859-14 Latin8 */
256  PG_LATIN9, /* ISO-8859-15 Latin9 */
257  PG_LATIN10, /* ISO-8859-16 Latin10 */
258  PG_WIN1256, /* windows-1256 */
259  PG_WIN1258, /* Windows-1258 */
260  PG_WIN866, /* (MS-DOS CP866) */
261  PG_WIN874, /* windows-874 */
262  PG_KOI8R, /* KOI8-R */
263  PG_WIN1251, /* windows-1251 */
264  PG_WIN1252, /* windows-1252 */
265  PG_ISO_8859_5, /* ISO-8859-5 */
266  PG_ISO_8859_6, /* ISO-8859-6 */
267  PG_ISO_8859_7, /* ISO-8859-7 */
268  PG_ISO_8859_8, /* ISO-8859-8 */
269  PG_WIN1250, /* windows-1250 */
270  PG_WIN1253, /* windows-1253 */
271  PG_WIN1254, /* windows-1254 */
272  PG_WIN1255, /* windows-1255 */
273  PG_WIN1257, /* windows-1257 */
274  PG_KOI8U, /* KOI8-U */
275  /* PG_ENCODING_BE_LAST points to the above entry */
276 
277  /* followings are for client encoding only */
278  PG_SJIS, /* Shift JIS (Windows-932) */
279  PG_BIG5, /* Big5 (Windows-950) */
280  PG_GBK, /* GBK (Windows-936) */
281  PG_UHC, /* UHC (Windows-949) */
282  PG_GB18030, /* GB18030 */
283  PG_JOHAB, /* EUC for Korean JOHAB */
284  PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
285  _PG_LAST_ENCODING_ /* mark only */
286 
287 } pg_enc;
pg_enc
Definition: pg_wchar.h:238

Function Documentation

◆ BIG5toCNS()

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

Definition at line 292 of file big5.c.

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

Referenced by big52mic().

293 {
294  unsigned short cns = 0;
295  int i;
296 
297  if (big5 < 0xc940U)
298  {
299  /* level 1 */
300 
301  for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++)
302  {
303  if (b1c4[i][0] == big5)
304  {
305  *lc = LC_CNS11643_4;
306  return (b1c4[i][1] | 0x8080U);
307  }
308  }
309 
310  if (0 < (cns = BinarySearchRange(big5Level1ToCnsPlane1, 23, big5)))
311  *lc = LC_CNS11643_1;
312  }
313  else if (big5 == 0xc94aU)
314  {
315  /* level 2 */
316  *lc = LC_CNS11643_1;
317  cns = 0x4442;
318  }
319  else
320  {
321  /* level 2 */
322  for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++)
323  {
324  if (b2c3[i][0] == big5)
325  {
326  *lc = LC_CNS11643_3;
327  return (b2c3[i][1] | 0x8080U);
328  }
329  }
330 
331  if (0 < (cns = BinarySearchRange(big5Level2ToCnsPlane2, 46, big5)))
332  *lc = LC_CNS11643_2;
333  }
334 
335  if (0 == cns)
336  { /* no mapping Big5 to CNS 11643-1992 */
337  *lc = 0;
338  return (unsigned short) '?';
339  }
340 
341  return cns | 0x8080;
342 }
#define LC_CNS11643_1
Definition: pg_wchar.h:134
static unsigned short BinarySearchRange(const codes_t *array, int high, unsigned short code)
Definition: big5.c:208
static const codes_t big5Level2ToCnsPlane2[48]
Definition: big5.c:84
#define LC_CNS11643_4
Definition: pg_wchar.h:205
static const codes_t big5Level1ToCnsPlane1[25]
Definition: big5.c:25
#define LC_CNS11643_2
Definition: pg_wchar.h:135
#define LC_CNS11643_3
Definition: pg_wchar.h:204
static const unsigned short b1c4[][2]
Definition: big5.c:189
int i
static const unsigned short b2c3[][2]
Definition: big5.c:197

◆ check_encoding_conversion_args()

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

Definition at line 2014 of file wchar.c.

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

2019 {
2020  if (!PG_VALID_ENCODING(src_encoding))
2021  elog(ERROR, "invalid source encoding ID: %d", src_encoding);
2022  if (src_encoding != expected_src_encoding && expected_src_encoding >= 0)
2023  elog(ERROR, "expected source encoding \"%s\", but got \"%s\"",
2024  pg_enc2name_tbl[expected_src_encoding].name,
2025  pg_enc2name_tbl[src_encoding].name);
2026  if (!PG_VALID_ENCODING(dest_encoding))
2027  elog(ERROR, "invalid destination encoding ID: %d", dest_encoding);
2028  if (dest_encoding != expected_dest_encoding && expected_dest_encoding >= 0)
2029  elog(ERROR, "expected destination encoding \"%s\", but got \"%s\"",
2030  pg_enc2name_tbl[expected_dest_encoding].name,
2031  pg_enc2name_tbl[dest_encoding].name);
2032  if (len < 0)
2033  elog(ERROR, "encoding conversion length must not be negative");
2034 }
#define ERROR
Definition: elog.h:43
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:226

◆ CNStoBIG5()

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().

346 {
347  int i;
348  unsigned int big5 = 0;
349 
350  cns &= 0x7f7f;
351 
352  switch (lc)
353  {
354  case LC_CNS11643_1:
355  big5 = BinarySearchRange(cnsPlane1ToBig5Level1, 24, cns);
356  break;
357  case LC_CNS11643_2:
358  big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns);
359  break;
360  case LC_CNS11643_3:
361  for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++)
362  {
363  if (b2c3[i][1] == cns)
364  return b2c3[i][0];
365  }
366  break;
367  case LC_CNS11643_4:
368  for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++)
369  {
370  if (b1c4[i][1] == cns)
371  return b1c4[i][0];
372  }
373  default:
374  break;
375  }
376  return big5;
377 }
#define LC_CNS11643_1
Definition: pg_wchar.h:134
static unsigned short BinarySearchRange(const codes_t *array, int high, unsigned short code)
Definition: big5.c:208
#define LC_CNS11643_4
Definition: pg_wchar.h:205
static const codes_t cnsPlane2ToBig5Level2[49]
Definition: big5.c:136
static const codes_t cnsPlane1ToBig5Level1[26]
Definition: big5.c:54
#define LC_CNS11643_2
Definition: pg_wchar.h:135
#define LC_CNS11643_3
Definition: pg_wchar.h:204
static const unsigned short b1c4[][2]
Definition: big5.c:189
int i
static const unsigned short b2c3[][2]
Definition: big5.c:197

◆ get_encoding_name_for_icu()

const char* get_encoding_name_for_icu ( int  encoding)

Definition at line 461 of file encnames.c.

References pg_encname::encoding, ereport, errcode(), errmsg(), ERROR, lengthof, pg_enc2icu_tbl, PG_ENCODING_BE_LAST, pg_encoding_to_char(), and StaticAssertStmt.

Referenced by get_collation_actual_version().

462 {
463  const char *icu_encoding_name;
464 
466  "pg_enc2icu_tbl incomplete");
467 
468  icu_encoding_name = pg_enc2icu_tbl[encoding];
469 
470  if (!icu_encoding_name)
471  ereport(ERROR,
472  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
473  errmsg("encoding \"%s\" not supported by ICU",
475 
476  return icu_encoding_name;
477 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define lengthof(array)
Definition: c.h:662
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:842
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_ENCODING_BE_LAST
Definition: pg_wchar.h:289
static const char *const pg_enc2icu_tbl[]
Definition: encnames.c:415
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
int32 encoding
Definition: pg_database.h:41
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ GetDatabaseEncoding()

◆ GetDatabaseEncodingName()

const char* GetDatabaseEncodingName ( void  )

◆ GetMessageEncoding()

int GetMessageEncoding ( void  )

◆ InitializeClientEncoding()

void InitializeClientEncoding ( void  )

Definition at line 274 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().

275 {
278 
281  {
282  /*
283  * Oops, the requested conversion is not available. We couldn't fail
284  * before, but we can now.
285  */
286  ereport(FATAL,
287  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
288  errmsg("conversion between %s and %s is not supported",
291  }
292 }
int PrepareClientEncoding(int encoding)
Definition: mbutils.c:103
static bool backend_startup_complete
Definition: mbutils.c:83
static int pending_client_encoding
Definition: mbutils.c:84
int errcode(int sqlerrcode)
Definition: elog.c:570
#define FATAL
Definition: elog.h:52
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
int SetClientEncoding(int encoding)
Definition: mbutils.c:201
#define ereport(elevel, rest)
Definition: elog.h:141
#define Assert(condition)
Definition: c.h:732
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1002
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ is_encoding_supported_by_icu()

bool is_encoding_supported_by_icu ( int  encoding)

Definition at line 455 of file encnames.c.

References pg_enc2icu_tbl.

Referenced by lookup_collation().

456 {
457  return (pg_enc2icu_tbl[encoding] != NULL);
458 }
static const char *const pg_enc2icu_tbl[]
Definition: encnames.c:415
int32 encoding
Definition: pg_database.h:41

◆ latin2mic()

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

Definition at line 71 of file conv.c.

References IS_HIGHBIT_SET, and report_invalid_encoding().

Referenced by koi8r_to_mic(), latin1_to_mic(), latin2_to_mic(), latin3_to_mic(), and latin4_to_mic().

73 {
74  int c1;
75 
76  while (len > 0)
77  {
78  c1 = *l;
79  if (c1 == 0)
80  report_invalid_encoding(encoding, (const char *) l, len);
81  if (IS_HIGHBIT_SET(c1))
82  *p++ = lc;
83  *p++ = c1;
84  l++;
85  len--;
86  }
87  *p = '\0';
88 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043

◆ latin2mic_with_table()

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 HIGHBIT, IS_HIGHBIT_SET, PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by iso_to_mic(), win1250_to_mic(), win1251_to_mic(), and win866_to_mic().

154 {
155  unsigned char c1,
156  c2;
157 
158  while (len > 0)
159  {
160  c1 = *l;
161  if (c1 == 0)
162  report_invalid_encoding(encoding, (const char *) l, len);
163  if (!IS_HIGHBIT_SET(c1))
164  *p++ = c1;
165  else
166  {
167  c2 = tab[c1 - HIGHBIT];
168  if (c2)
169  {
170  *p++ = lc;
171  *p++ = c2;
172  }
173  else
175  (const char *) l, len);
176  }
177  l++;
178  len--;
179  }
180  *p = '\0';
181 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
#define HIGHBIT
Definition: c.h:1074
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043

◆ local2local()

void local2local ( const unsigned char *  l,
unsigned char *  p,
int  len,
int  src_encoding,
int  dest_encoding,
const unsigned char *  tab 
)

Definition at line 30 of file conv.c.

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

Referenced by iso_to_koi8r(), iso_to_win1251(), iso_to_win866(), koi8r_to_iso(), koi8r_to_win1251(), koi8r_to_win866(), latin2_to_win1250(), win1250_to_latin2(), win1251_to_iso(), win1251_to_koi8r(), win1251_to_win866(), win866_to_iso(), win866_to_koi8r(), and win866_to_win1251().

36 {
37  unsigned char c1,
38  c2;
39 
40  while (len > 0)
41  {
42  c1 = *l;
43  if (c1 == 0)
44  report_invalid_encoding(src_encoding, (const char *) l, len);
45  if (!IS_HIGHBIT_SET(c1))
46  *p++ = c1;
47  else
48  {
49  c2 = tab[c1 - HIGHBIT];
50  if (c2)
51  *p++ = c2;
52  else
53  report_untranslatable_char(src_encoding, dest_encoding,
54  (const char *) l, len);
55  }
56  l++;
57  len--;
58  }
59  *p = '\0';
60 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
#define HIGHBIT
Definition: c.h:1074
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043

◆ LocalToUtf()

void LocalToUtf ( const unsigned char *  iso,
int  len,
unsigned char *  utf,
const pg_mb_radix_tree map,
const pg_local_to_utf_combined cmap,
int  cmapsize,
utf_local_conversion_func  conv_func,
int  encoding 
)

Definition at line 621 of file conv.c.

References compare4(), elog, ereport, errcode(), errmsg(), ERROR, IS_HIGHBIT_SET, pg_encoding_verifymb(), pg_mb_radix_conv(), PG_UTF8, PG_VALID_ENCODING, report_invalid_encoding(), report_untranslatable_char(), store_coded_char(), 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().

627 {
628  uint32 iiso;
629  int l;
630  const pg_local_to_utf_combined *cp;
631 
633  ereport(ERROR,
634  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
635  errmsg("invalid encoding number: %d", encoding)));
636 
637  for (; len > 0; len -= l)
638  {
639  unsigned char b1 = 0;
640  unsigned char b2 = 0;
641  unsigned char b3 = 0;
642  unsigned char b4 = 0;
643 
644  /* "break" cases all represent errors */
645  if (*iso == '\0')
646  break;
647 
648  if (!IS_HIGHBIT_SET(*iso))
649  {
650  /* ASCII case is easy, assume it's one-to-one conversion */
651  *utf++ = *iso++;
652  l = 1;
653  continue;
654  }
655 
656  l = pg_encoding_verifymb(encoding, (const char *) iso, len);
657  if (l < 0)
658  break;
659 
660  /* collect coded char of length l */
661  if (l == 1)
662  b4 = *iso++;
663  else if (l == 2)
664  {
665  b3 = *iso++;
666  b4 = *iso++;
667  }
668  else if (l == 3)
669  {
670  b2 = *iso++;
671  b3 = *iso++;
672  b4 = *iso++;
673  }
674  else if (l == 4)
675  {
676  b1 = *iso++;
677  b2 = *iso++;
678  b3 = *iso++;
679  b4 = *iso++;
680  }
681  else
682  {
683  elog(ERROR, "unsupported character length %d", l);
684  iiso = 0; /* keep compiler quiet */
685  }
686  iiso = (b1 << 24 | b2 << 16 | b3 << 8 | b4);
687 
688  if (map)
689  {
690  uint32 converted = pg_mb_radix_conv(map, l, b1, b2, b3, b4);
691 
692  if (converted)
693  {
694  utf = store_coded_char(utf, converted);
695  continue;
696  }
697 
698  /* If there's a combined character map, try that */
699  if (cmap)
700  {
701  cp = bsearch(&iiso, cmap, cmapsize,
703 
704  if (cp)
705  {
706  utf = store_coded_char(utf, cp->utf1);
707  utf = store_coded_char(utf, cp->utf2);
708  continue;
709  }
710  }
711  }
712 
713  /* if there's a conversion function, try that */
714  if (conv_func)
715  {
716  uint32 converted = (*conv_func) (iiso);
717 
718  if (converted)
719  {
720  utf = store_coded_char(utf, converted);
721  continue;
722  }
723  }
724 
725  /* failed to translate this character */
727  (const char *) (iso - l), len);
728  }
729 
730  /* if we broke out of loop early, must be invalid input */
731  if (len > 0)
732  report_invalid_encoding(encoding, (const char *) iso, len);
733 
734  *utf = '\0';
735 }
static int compare4(const void *p1, const void *p2)
Definition: conv.c:264
int errcode(int sqlerrcode)
Definition: elog.c:570
static unsigned char * store_coded_char(unsigned char *dest, uint32 code)
Definition: conv.c:278
int pg_encoding_verifymb(int encoding, const char *mbstr, int len)
Definition: wchar.c:1857
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
#define ERROR
Definition: elog.h:43
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
static uint32 pg_mb_radix_conv(const pg_mb_radix_tree *rt, int l, unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4)
Definition: conv.c:298
unsigned int uint32
Definition: c.h:358
#define ereport(elevel, rest)
Definition: elog.h:141
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226

◆ mic2latin()

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

Definition at line 99 of file conv.c.

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

Referenced by mic_to_koi8r(), mic_to_latin1(), mic_to_latin2(), mic_to_latin3(), and mic_to_latin4().

101 {
102  int c1;
103 
104  while (len > 0)
105  {
106  c1 = *mic;
107  if (c1 == 0)
108  report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic, len);
109  if (!IS_HIGHBIT_SET(c1))
110  {
111  /* easy for ASCII */
112  *p++ = c1;
113  mic++;
114  len--;
115  }
116  else
117  {
118  int l = pg_mic_mblen(mic);
119 
120  if (len < l)
121  report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic,
122  len);
123  if (l != 2 || c1 != lc || !IS_HIGHBIT_SET(mic[1]))
125  (const char *) mic, len);
126  *p++ = mic[1];
127  mic += 2;
128  len -= 2;
129  }
130  }
131  *p = '\0';
132 }
int pg_mic_mblen(const unsigned char *mbstr)
Definition: wchar.c:1824
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043

◆ mic2latin_with_table()

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 mic_to_iso(), mic_to_win1250(), mic_to_win1251(), and mic_to_win866().

202 {
203  unsigned char c1,
204  c2;
205 
206  while (len > 0)
207  {
208  c1 = *mic;
209  if (c1 == 0)
210  report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic, len);
211  if (!IS_HIGHBIT_SET(c1))
212  {
213  /* easy for ASCII */
214  *p++ = c1;
215  mic++;
216  len--;
217  }
218  else
219  {
220  int l = pg_mic_mblen(mic);
221 
222  if (len < l)
223  report_invalid_encoding(PG_MULE_INTERNAL, (const char *) mic,
224  len);
225  if (l != 2 || c1 != lc || !IS_HIGHBIT_SET(mic[1]) ||
226  (c2 = tab[mic[1] - HIGHBIT]) == 0)
227  {
229  (const char *) mic, len);
230  break; /* keep compiler quiet */
231  }
232  *p++ = c2;
233  mic += 2;
234  len -= 2;
235  }
236  }
237  *p = '\0';
238 }
int pg_mic_mblen(const unsigned char *mbstr)
Definition: wchar.c:1824
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
#define HIGHBIT
Definition: c.h:1074
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043

◆ pg_any_to_server()

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

Definition at line 553 of file mbutils.c.

References 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, pg_verify_mbstr(), and unconstify.

Referenced by ASN1_STRING_to_text(), cache_single_string(), CopyReadLine(), db_encoding_convert(), dsnowball_lexize(), pg_client_to_server(), pg_stat_statements_internal(), pgp_armor_headers(), PLyUnicode_Bytes(), read_extension_script_file(), t_readline(), unicode_to_sqlchar(), utf_u2e(), X509_NAME_to_cstring(), X509_NAME_to_text(), and xml_recv().

554 {
555  if (len <= 0)
556  return unconstify(char *, s); /* empty string is always valid */
557 
560  {
561  /*
562  * No conversion is needed, but we must still validate the data.
563  */
564  (void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false);
565  return unconstify(char *, s);
566  }
567 
569  {
570  /*
571  * No conversion is possible, but we must still validate the data,
572  * because the client-side code might have done string escaping using
573  * the selected client_encoding. If the client encoding is ASCII-safe
574  * then we just do a straight validation under that encoding. For an
575  * ASCII-unsafe encoding we have a problem: we dare not pass such data
576  * to the parser but we have no way to convert it. We compromise by
577  * rejecting the data if it contains any non-ASCII characters.
578  */
580  (void) pg_verify_mbstr(encoding, s, len, false);
581  else
582  {
583  int i;
584 
585  for (i = 0; i < len; i++)
586  {
587  if (s[i] == '\0' || IS_HIGHBIT_SET(s[i]))
588  ereport(ERROR,
589  (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
590  errmsg("invalid byte value for encoding \"%s\": 0x%02x",
592  (unsigned char) s[i])));
593  }
594  }
595  return unconstify(char *, s);
596  }
597 
598  /* Fast path if we can use cached conversion function */
600  return perform_default_encoding_conversion(s, len, true);
601 
602  /* General case ... will not work outside transactions */
603  return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
604  len,
605  encoding,
607 }
static char * perform_default_encoding_conversion(const char *src, int len, bool is_client_to_server)
Definition: mbutils.c:660
int errcode(int sqlerrcode)
Definition: elog.c:570
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
Definition: mbutils.c:318
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
#define ERROR
Definition: elog.h:43
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
Definition: wchar.c:1925
#define ereport(elevel, rest)
Definition: elog.h:141
#define unconstify(underlying_type, expr)
Definition: c.h:1163
pg_enc encoding
Definition: pg_wchar.h:329
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
int32 encoding
Definition: pg_database.h:41
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74
int i

◆ pg_char_and_wchar_strcmp()

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

Definition at line 41 of file wstrcmp.c.

42 {
43  while ((pg_wchar) *s1 == *s2++)
44  if (*s1++ == 0)
45  return 0;
46  return *(const unsigned char *) s1 - *(const pg_wchar *) (s2 - 1);
47 }
char * s1
unsigned int pg_wchar
Definition: mbprint.c:31
char * s2

◆ pg_char_and_wchar_strncmp()

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().

56 {
57  if (n == 0)
58  return 0;
59  do
60  {
61  if ((pg_wchar) ((unsigned char) *s1) != *s2++)
62  return ((pg_wchar) ((unsigned char) *s1) - *(s2 - 1));
63  if (*s1++ == 0)
64  break;
65  } while (--n != 0);
66  return 0;
67 }
char * s1
unsigned int pg_wchar
Definition: mbprint.c:31
char * s2

◆ pg_char_to_encoding()

int pg_char_to_encoding ( const char *  name)

Definition at line 551 of file encnames.c.

552 {
553  unsigned int nel = lengthof(pg_encname_tbl);
554  const pg_encname *base = pg_encname_tbl,
555  *last = base + nel - 1,
556  *position;
557  int result;
558  char buff[NAMEDATALEN],
559  *key;
560 
561  if (name == NULL || *name == '\0')
562  return -1;
563 
564  if (strlen(name) >= NAMEDATALEN)
565  {
566 #ifdef FRONTEND
567  fprintf(stderr, "encoding name too long\n");
568  return -1;
569 #else
570  ereport(ERROR,
571  (errcode(ERRCODE_NAME_TOO_LONG),
572  errmsg("encoding name too long")));
573 #endif
574  }
575  key = clean_encoding_name(name, buff);
576 
577  while (last >= base)
578  {
579  position = base + ((last - base) >> 1);
580  result = key[0] - position->name[0];
581 
582  if (result == 0)
583  {
584  result = strcmp(key, position->name);
585  if (result == 0)
586  return position->encoding;
587  }
588  if (result < 0)
589  last = position - 1;
590  else
591  base = position + 1;
592  }
593  return -1;
594 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define lengthof(array)
Definition: c.h:662
#define fprintf
Definition: port.h:196
#define NAMEDATALEN
#define ERROR
Definition: elog.h:43
static const pg_encname pg_encname_tbl[]
Definition: encnames.c:38
#define ereport(elevel, rest)
Definition: elog.h:141
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784
static char * clean_encoding_name(const char *key, char *newkey)
Definition: encnames.c:525

◆ pg_client_to_server()

char* pg_client_to_server ( const char *  s,
int  len 
)

Definition at line 537 of file mbutils.c.

References pg_enc2name::encoding, and pg_any_to_server().

Referenced by exec_bind_message(), parse_fcall_arguments(), pq_getmsgstring(), and pq_getmsgtext().

538 {
539  return pg_any_to_server(s, len, ClientEncoding->encoding);
540 }
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
pg_enc encoding
Definition: pg_wchar.h:329
char * pg_any_to_server(const char *s, int len, int encoding)
Definition: mbutils.c:553

◆ pg_database_encoding_character_incrementer()

mbcharacter_incrementer pg_database_encoding_character_incrementer ( void  )

Definition at line 1890 of file wchar.c.

References GetDatabaseEncoding(), PG_EUC_JP, pg_eucjp_increment(), pg_generic_charinc(), PG_UTF8, and pg_utf8_increment().

Referenced by make_greater_string().

1891 {
1892  /*
1893  * Eventually it might be best to add a field to pg_wchar_table[], but for
1894  * now we just use a switch.
1895  */
1896  switch (GetDatabaseEncoding())
1897  {
1898  case PG_UTF8:
1899  return pg_utf8_increment;
1900 
1901  case PG_EUC_JP:
1902  return pg_eucjp_increment;
1903 
1904  default:
1905  return pg_generic_charinc;
1906  }
1907 }
static bool pg_eucjp_increment(unsigned char *charptr, int length)
Definition: wchar.c:1687
static bool pg_generic_charinc(unsigned char *charptr, int len)
Definition: wchar.c:1575
static bool pg_utf8_increment(unsigned char *charptr, int length)
Definition: wchar.c:1609
int GetDatabaseEncoding(void)
Definition: mbutils.c:996

◆ pg_database_encoding_max_length()

◆ pg_do_encoding_conversion()

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

Definition at line 318 of file mbutils.c.

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

Referenced by convert_charset(), GetMessageEncoding(), pg_any_to_server(), pg_convert(), pg_server_to_any(), and xml_is_document().

320 {
321  unsigned char *result;
322  Oid proc;
323 
324  if (len <= 0)
325  return src; /* empty string is always valid */
326 
327  if (src_encoding == dest_encoding)
328  return src; /* no conversion required, assume valid */
329 
330  if (dest_encoding == PG_SQL_ASCII)
331  return src; /* any string is valid in SQL_ASCII */
332 
333  if (src_encoding == PG_SQL_ASCII)
334  {
335  /* No conversion is possible, but we must validate the result */
336  (void) pg_verify_mbstr(dest_encoding, (const char *) src, len, false);
337  return src;
338  }
339 
340  if (!IsTransactionState()) /* shouldn't happen */
341  elog(ERROR, "cannot perform encoding conversion outside a transaction");
342 
343  proc = FindDefaultConversionProc(src_encoding, dest_encoding);
344  if (!OidIsValid(proc))
345  ereport(ERROR,
346  (errcode(ERRCODE_UNDEFINED_FUNCTION),
347  errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
348  pg_encoding_to_char(src_encoding),
349  pg_encoding_to_char(dest_encoding))));
350 
351  /*
352  * Allocate space for conversion result, being wary of integer overflow
353  */
354  if ((Size) len >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
355  ereport(ERROR,
356  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
357  errmsg("out of memory"),
358  errdetail("String of %d bytes is too long for encoding conversion.",
359  len)));
360 
361  result = palloc(len * MAX_CONVERSION_GROWTH + 1);
362 
363  OidFunctionCall5(proc,
364  Int32GetDatum(src_encoding),
365  Int32GetDatum(dest_encoding),
366  CStringGetDatum(src),
367  CStringGetDatum(result),
368  Int32GetDatum(len));
369  return result;
370 }
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:860
#define CStringGetDatum(X)
Definition: postgres.h:578
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
Definition: wchar.c:1925
#define ereport(elevel, rest)
Definition: elog.h:141
#define MaxAllocSize
Definition: memutils.h:40
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
size_t Size
Definition: c.h:466
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:3673
bool IsTransactionState(void)
Definition: xact.c:356
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:316
#define Int32GetDatum(X)
Definition: postgres.h:479
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
#define OidFunctionCall5(functionId, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:663

◆ pg_dsplen()

int pg_dsplen ( const char *  mbstr)

Definition at line 759 of file mbutils.c.

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

Referenced by p_isspecial().

760 {
761  return pg_wchar_table[DatabaseEncoding->encoding].dsplen((const unsigned char *) mbstr);
762 }
mbdisplaylen_converter dsplen
Definition: pg_wchar.h:380
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74

◆ pg_encoding_dsplen()

int pg_encoding_dsplen ( int  encoding,
const char *  mbstr 
)

Definition at line 1844 of file wchar.c.

References PG_SQL_ASCII, and PG_VALID_ENCODING.

Referenced by PQdsplen(), and reportErrorPosition().

1845 {
1846  return (PG_VALID_ENCODING(encoding) ?
1847  pg_wchar_table[encoding].dsplen((const unsigned char *) mbstr) :
1848  pg_wchar_table[PG_SQL_ASCII].dsplen((const unsigned char *) mbstr));
1849 }
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777

◆ pg_encoding_max_length()

int pg_encoding_max_length ( int  encoding)

Definition at line 1868 of file wchar.c.

References Assert, encoding, pg_wchar_tbl::maxmblen, and PG_VALID_ENCODING.

Referenced by ascii(), chr(), pg_encoding_mbcliplen(), pg_verify_mbstr_len(), reportErrorPosition(), and type_maximum_size().

1869 {
1871 
1873 }
int maxmblen
Definition: pg_wchar.h:382
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
#define Assert(condition)
Definition: c.h:732
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777

◆ pg_encoding_mb2wchar_with_len()

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

Definition at line 722 of file mbutils.c.

References encoding, pg_wchar_tbl::mb2wchar_with_len, and pg_wchar_table.

Referenced by xml_is_document().

724 {
725  return pg_wchar_table[encoding].mb2wchar_with_len((const unsigned char *) from, to, len);
726 }
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
mb2wchar_with_len_converter mb2wchar_with_len
Definition: pg_wchar.h:375

◆ pg_encoding_mbcliplen()

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

Definition at line 822 of file mbutils.c.

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

Referenced by pg_mbcliplen().

824 {
825  mblen_converter mblen_fn;
826  int clen = 0;
827  int l;
828 
829  /* optimization for single byte encoding */
831  return cliplen(mbstr, len, limit);
832 
833  mblen_fn = pg_wchar_table[encoding].mblen;
834 
835  while (len > 0 && *mbstr)
836  {
837  l = (*mblen_fn) ((const unsigned char *) mbstr);
838  if ((clen + l) > limit)
839  break;
840  clen += l;
841  if (clen == limit)
842  break;
843  len -= l;
844  mbstr += l;
845  }
846  return clen;
847 }
int(* mblen_converter)(const unsigned char *mbstr)
Definition: pg_wchar.h:365
int pg_encoding_max_length(int encoding)
Definition: wchar.c:1868
static int cliplen(const char *str, int len, int limit)
Definition: mbutils.c:879
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
mblen_converter mblen
Definition: pg_wchar.h:379

◆ pg_encoding_mblen()

int pg_encoding_mblen ( int  encoding,
const char *  mbstr 
)

Definition at line 1833 of file wchar.c.

References PG_SQL_ASCII, and PG_VALID_ENCODING.

Referenced by CopyAttributeOutCSV(), CopyAttributeOutText(), CopyReadLineText(), PQescapeInternal(), PQescapeStringInternal(), PQmblen(), report_invalid_encoding(), report_untranslatable_char(), reportErrorPosition(), and xml_is_document().

1834 {
1835  return (PG_VALID_ENCODING(encoding) ?
1836  pg_wchar_table[encoding].mblen((const unsigned char *) mbstr) :
1837  pg_wchar_table[PG_SQL_ASCII].mblen((const unsigned char *) mbstr));
1838 }
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777

◆ pg_encoding_to_char()

const char* pg_encoding_to_char ( int  encoding)

Definition at line 607 of file encnames.c.

608 {
610  {
611  const pg_enc2name *p = &pg_enc2name_tbl[encoding];
612 
613  Assert(encoding == p->encoding);
614  return p->name;
615  }
616  return "";
617 }
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
const char * name
Definition: pg_wchar.h:328
pg_enc encoding
Definition: pg_wchar.h:329
#define Assert(condition)
Definition: c.h:732
int32 encoding
Definition: pg_database.h:41

◆ pg_encoding_verifymb()

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

Definition at line 1857 of file wchar.c.

References 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().

1858 {
1859  return (PG_VALID_ENCODING(encoding) ?
1860  pg_wchar_table[encoding].mbverify((const unsigned char *) mbstr, len) :
1861  pg_wchar_table[PG_SQL_ASCII].mbverify((const unsigned char *) mbstr, len));
1862 }
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777

◆ pg_encoding_wchar2mb_with_len()

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

Definition at line 744 of file mbutils.c.

References encoding, pg_wchar_table, and pg_wchar_tbl::wchar2mb_with_len.

746 {
747  return pg_wchar_table[encoding].wchar2mb_with_len(from, (unsigned char *) to, len);
748 }
wchar2mb_with_len_converter wchar2mb_with_len
Definition: pg_wchar.h:377
int32 encoding
Definition: pg_database.h:41
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777

◆ pg_get_client_encoding()

int pg_get_client_encoding ( void  )

Definition at line 298 of file mbutils.c.

References pg_enc2name::encoding.

Referenced by BeginCopy(), and xml_send().

299 {
300  return ClientEncoding->encoding;
301 }
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
pg_enc encoding
Definition: pg_wchar.h:329

◆ pg_get_client_encoding_name()

const char* pg_get_client_encoding_name ( void  )

Definition at line 307 of file mbutils.c.

References pg_enc2name::name.

308 {
309  return ClientEncoding->name;
310 }
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
const char * name
Definition: pg_wchar.h:328

◆ pg_mb2wchar()

int pg_mb2wchar ( const char *  from,
pg_wchar to 
)

Definition at line 708 of file mbutils.c.

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

709 {
710  return pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len((const unsigned char *) from, to, strlen(from));
711 }
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74
mb2wchar_with_len_converter mb2wchar_with_len
Definition: pg_wchar.h:375

◆ pg_mb2wchar_with_len()

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

Definition at line 715 of file mbutils.c.

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

Referenced by check_ident_usermap(), CheckAffix(), NIAddAffix(), parse_ident_line(), RE_compile(), RE_compile_and_cache(), RE_execute(), replace_text_regexp(), setup_regexp_matches(), and TParserInit().

716 {
717  return pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len((const unsigned char *) from, to, len);
718 }
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74
mb2wchar_with_len_converter mb2wchar_with_len
Definition: pg_wchar.h:375

◆ pg_mbcharcliplen()

int pg_mbcharcliplen ( const char *  mbstr,
int  len,
int  limit 
)

Definition at line 854 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().

855 {
856  int clen = 0;
857  int nch = 0;
858  int l;
859 
860  /* optimization for single byte encoding */
862  return cliplen(mbstr, len, limit);
863 
864  while (len > 0 && *mbstr)
865  {
866  l = pg_mblen(mbstr);
867  nch++;
868  if (nch > limit)
869  break;
870  clen += l;
871  len -= l;
872  mbstr += l;
873  }
874  return clen;
875 }
int pg_database_encoding_max_length(void)
Definition: wchar.c:1881
static int cliplen(const char *str, int len, int limit)
Definition: mbutils.c:879
int pg_mblen(const char *mbstr)
Definition: mbutils.c:752

◆ pg_mbcliplen()

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

◆ pg_mblen()

int pg_mblen ( const char *  mbstr)

Definition at line 752 of file mbutils.c.

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

Referenced by addCompoundAffixFlagValue(), appendStringInfoRegexpSubstr(), charlen_to_bytelen(), check_replace_text_has_escape_char(), DCH_from_char(), dotrim(), extract_mb_char(), find_word(), findchar(), findchar2(), findwrd(), gbt_var_node_cp_len(), get_modifiers(), get_nextfield(), get_wildcard_part(), getlexeme(), getNextFlagFromString(), gettoken_query(), gettoken_query_standard(), gettoken_query_websearch(), gettoken_tsvector(), infix(), initTrie(), json_lex_string(), lpad(), lquery_in(), ltree_in(), make_trigrams(), map_sql_identifier_to_xml_name(), map_xml_name_to_sql_identifier(), match_prosrc_to_literal(), mb_strchr(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), NUM_eat_non_data_chars(), NUM_processor(), parse_affentry(), parse_format(), parse_or_operator(), pg_mbcharcliplen(), pg_mbstrlen(), pg_mbstrlen_with_len(), readstoplist(), report_json_context(), rpad(), RS_compile(), RS_execute(), RS_isRegis(), similar_escape_internal(), t_isalpha(), t_isdigit(), t_isprint(), t_isspace(), text_position_get_match_pos(), text_position_next(), text_reverse(), text_substring(), text_to_array_internal(), thesaurusRead(), TParserGet(), translate(), ts_stat_sql(), tsvectorout(), unaccent_lexize(), varstr_levenshtein(), wchareq(), and xml_is_document().

753 {
754  return pg_wchar_table[DatabaseEncoding->encoding].mblen((const unsigned char *) mbstr);
755 }
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74
mblen_converter mblen
Definition: pg_wchar.h:379

◆ pg_mbstrlen()

int pg_mbstrlen ( const char *  mbstr)

Definition at line 766 of file mbutils.c.

References pg_database_encoding_max_length(), and pg_mblen().

Referenced by NUM_processor(), and text_format_append_string().

767 {
768  int len = 0;
769 
770  /* optimization for single byte encoding */
772  return strlen(mbstr);
773 
774  while (*mbstr)
775  {
776  mbstr += pg_mblen(mbstr);
777  len++;
778  }
779  return len;
780 }
int pg_database_encoding_max_length(void)
Definition: wchar.c:1881
int pg_mblen(const char *mbstr)
Definition: mbutils.c:752

◆ pg_mbstrlen_with_len()

int pg_mbstrlen_with_len ( const char *  mbstr,
int  len 
)

Definition at line 786 of file mbutils.c.

References pg_database_encoding_max_length(), and pg_mblen().

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

787 {
788  int len = 0;
789 
790  /* optimization for single byte encoding */
792  return limit;
793 
794  while (limit > 0 && *mbstr)
795  {
796  int l = pg_mblen(mbstr);
797 
798  limit -= l;
799  mbstr += l;
800  len++;
801  }
802  return len;
803 }
int pg_database_encoding_max_length(void)
Definition: wchar.c:1881
int pg_mblen(const char *mbstr)
Definition: mbutils.c:752

◆ pg_mic_mblen()

int pg_mic_mblen ( const unsigned char *  mbstr)

Definition at line 1824 of file wchar.c.

References pg_mule_mblen().

Referenced by mic2latin(), and mic2latin_with_table().

1825 {
1826  return pg_mule_mblen(mbstr);
1827 }
int pg_mule_mblen(const unsigned char *s)
Definition: wchar.c:903

◆ pg_mule_mblen()

int pg_mule_mblen ( const unsigned char *  mbstr)

Definition at line 903 of file wchar.c.

References IS_LC1, IS_LC2, IS_LCPRV1, and IS_LCPRV2.

Referenced by pg_mic_mblen(), and pg_mule_verifier().

904 {
905  int len;
906 
907  if (IS_LC1(*s))
908  len = 2;
909  else if (IS_LCPRV1(*s))
910  len = 3;
911  else if (IS_LC2(*s))
912  len = 3;
913  else if (IS_LCPRV2(*s))
914  len = 4;
915  else
916  len = 1; /* assume ASCII */
917  return len;
918 }
#define IS_LC2(c)
Definition: pg_wchar.h:144
#define IS_LCPRV2(c)
Definition: pg_wchar.h:164
#define IS_LCPRV1(c)
Definition: pg_wchar.h:152
#define IS_LC1(c)
Definition: pg_wchar.h:123

◆ pg_server_to_any()

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

Definition at line 626 of file mbutils.c.

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

Referenced by compareStrings(), CopyAttributeOutCSV(), CopyAttributeOutText(), CopyTo(), dsnowball_lexize(), hv_fetch_string(), hv_store_string(), pg_server_to_client(), PLyUnicode_AsString(), utf_e2u(), and xml_is_document().

627 {
628  if (len <= 0)
629  return unconstify(char *, s); /* empty string is always valid */
630 
633  return unconstify(char *, s); /* assume data is valid */
634 
636  {
637  /* No conversion is possible, but we must validate the result */
638  (void) pg_verify_mbstr(encoding, s, len, false);
639  return unconstify(char *, s);
640  }
641 
642  /* Fast path if we can use cached conversion function */
644  return perform_default_encoding_conversion(s, len, false);
645 
646  /* General case ... will not work outside transactions */
647  return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
648  len,
650  encoding);
651 }
static char * perform_default_encoding_conversion(const char *src, int len, bool is_client_to_server)
Definition: mbutils.c:660
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
Definition: mbutils.c:318
bool pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
Definition: wchar.c:1925
#define unconstify(underlying_type, expr)
Definition: c.h:1163
pg_enc encoding
Definition: pg_wchar.h:329
int32 encoding
Definition: pg_database.h:41
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74

◆ pg_server_to_client()

char* pg_server_to_client ( const char *  s,
int  len 
)

Definition at line 615 of file mbutils.c.

References pg_enc2name::encoding, and pg_server_to_any().

Referenced by pq_puttextmessage(), pq_sendcountedtext(), pq_sendstring(), pq_sendtext(), and pq_writestring().

616 {
617  return pg_server_to_any(s, len, ClientEncoding->encoding);
618 }
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
char * pg_server_to_any(const char *s, int len, int encoding)
Definition: mbutils.c:626
pg_enc encoding
Definition: pg_wchar.h:329

◆ pg_utf8_islegal()

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

Definition at line 1506 of file wchar.c.

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

1507 {
1508  unsigned char a;
1509 
1510  switch (length)
1511  {
1512  default:
1513  /* reject lengths 5 and 6 for now */
1514  return false;
1515  case 4:
1516  a = source[3];
1517  if (a < 0x80 || a > 0xBF)
1518  return false;
1519  /* FALL THRU */
1520  case 3:
1521  a = source[2];
1522  if (a < 0x80 || a > 0xBF)
1523  return false;
1524  /* FALL THRU */
1525  case 2:
1526  a = source[1];
1527  switch (*source)
1528  {
1529  case 0xE0:
1530  if (a < 0xA0 || a > 0xBF)
1531  return false;
1532  break;
1533  case 0xED:
1534  if (a < 0x80 || a > 0x9F)
1535  return false;
1536  break;
1537  case 0xF0:
1538  if (a < 0x90 || a > 0xBF)
1539  return false;
1540  break;
1541  case 0xF4:
1542  if (a < 0x80 || a > 0x8F)
1543  return false;
1544  break;
1545  default:
1546  if (a < 0x80 || a > 0xBF)
1547  return false;
1548  break;
1549  }
1550  /* FALL THRU */
1551  case 1:
1552  a = *source;
1553  if (a >= 0x80 && a < 0xC2)
1554  return false;
1555  if (a > 0xF4)
1556  return false;
1557  break;
1558  }
1559  return true;
1560 }

◆ pg_utf_mblen()

int pg_utf_mblen ( const unsigned char *  )

Definition at line 548 of file wchar.c.

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

549 {
550  int len;
551 
552  if ((*s & 0x80) == 0)
553  len = 1;
554  else if ((*s & 0xe0) == 0xc0)
555  len = 2;
556  else if ((*s & 0xf0) == 0xe0)
557  len = 3;
558  else if ((*s & 0xf8) == 0xf0)
559  len = 4;
560 #ifdef NOT_USED
561  else if ((*s & 0xfc) == 0xf8)
562  len = 5;
563  else if ((*s & 0xfe) == 0xfc)
564  len = 6;
565 #endif
566  else
567  len = 1;
568  return len;
569 }

◆ pg_valid_client_encoding()

int pg_valid_client_encoding ( const char *  name)

Definition at line 487 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding().

488 {
489  int enc;
490 
491  if ((enc = pg_char_to_encoding(name)) < 0)
492  return -1;
493 
494  if (!PG_VALID_FE_ENCODING(enc))
495  return -1;
496 
497  return enc;
498 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:551
struct pg_encoding enc
Definition: encode.c:522
#define PG_VALID_FE_ENCODING(_enc)
Definition: pg_wchar.h:305
const char * name
Definition: encode.c:521

◆ pg_valid_server_encoding()

int pg_valid_server_encoding ( const char *  name)

Definition at line 501 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().

502 {
503  int enc;
504 
505  if ((enc = pg_char_to_encoding(name)) < 0)
506  return -1;
507 
508  if (!PG_VALID_BE_ENCODING(enc))
509  return -1;
510 
511  return enc;
512 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:551
struct pg_encoding enc
Definition: encode.c:522
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
const char * name
Definition: encode.c:521

◆ pg_valid_server_encoding_id()

int pg_valid_server_encoding_id ( int  encoding)

Definition at line 515 of file encnames.c.

516 {
518 }
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
int32 encoding
Definition: pg_database.h:41

◆ pg_verify_mbstr()

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

Definition at line 1925 of file wchar.c.

References pg_verify_mbstr_len().

Referenced by LogicalOutputWrite(), pg_any_to_server(), pg_do_encoding_conversion(), pg_server_to_any(), and t_readline().

1926 {
1927  return pg_verify_mbstr_len(encoding, mbstr, len, noError) >= 0;
1928 }
int pg_verify_mbstr_len(int encoding, const char *mbstr, int len, bool noError)
Definition: wchar.c:1942
int32 encoding
Definition: pg_database.h:41

◆ pg_verify_mbstr_len()

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

Definition at line 1942 of file wchar.c.

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

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

1943 {
1944  mbverifier mbverify;
1945  int mb_len;
1946 
1948 
1949  /*
1950  * In single-byte encodings, we need only reject nulls (\0).
1951  */
1952  if (pg_encoding_max_length(encoding) <= 1)
1953  {
1954  const char *nullpos = memchr(mbstr, 0, len);
1955 
1956  if (nullpos == NULL)
1957  return len;
1958  if (noError)
1959  return -1;
1960  report_invalid_encoding(encoding, nullpos, 1);
1961  }
1962 
1963  /* fetch function pointer just once */
1964  mbverify = pg_wchar_table[encoding].mbverify;
1965 
1966  mb_len = 0;
1967 
1968  while (len > 0)
1969  {
1970  int l;
1971 
1972  /* fast path for ASCII-subset characters */
1973  if (!IS_HIGHBIT_SET(*mbstr))
1974  {
1975  if (*mbstr != '\0')
1976  {
1977  mb_len++;
1978  mbstr++;
1979  len--;
1980  continue;
1981  }
1982  if (noError)
1983  return -1;
1984  report_invalid_encoding(encoding, mbstr, len);
1985  }
1986 
1987  l = (*mbverify) ((const unsigned char *) mbstr, len);
1988 
1989  if (l < 0)
1990  {
1991  if (noError)
1992  return -1;
1993  report_invalid_encoding(encoding, mbstr, len);
1994  }
1995 
1996  mbstr += l;
1997  len -= l;
1998  mb_len++;
1999  }
2000  return mb_len;
2001 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1075
int pg_encoding_max_length(int encoding)
Definition: wchar.c:1868
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
int(* mbverifier)(const unsigned char *mbstr, int len)
Definition: pg_wchar.h:371
#define Assert(condition)
Definition: c.h:732
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
mbverifier mbverify
Definition: pg_wchar.h:381

◆ pg_verifymbstr()

bool pg_verifymbstr ( const char *  mbstr,
int  len,
bool  noError 
)

Definition at line 1914 of file wchar.c.

References GetDatabaseEncoding(), and pg_verify_mbstr_len().

Referenced by char2wchar(), CopyReadAttributesText(), plperl_spi_exec(), plperl_spi_prepare(), plperl_spi_query(), PLy_cursor_query(), PLy_output(), PLy_spi_execute_query(), PLy_spi_prepare(), PLyObject_AsString(), read_text_file(), and spg_text_leaf_consistent().

1915 {
1916  return
1917  pg_verify_mbstr_len(GetDatabaseEncoding(), mbstr, len, noError) >= 0;
1918 }
int pg_verify_mbstr_len(int encoding, const char *mbstr, int len, bool noError)
Definition: wchar.c:1942
int GetDatabaseEncoding(void)
Definition: mbutils.c:996

◆ pg_wchar2mb()

int pg_wchar2mb ( const pg_wchar from,
char *  to 
)

Definition at line 730 of file mbutils.c.

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

731 {
732  return pg_wchar_table[DatabaseEncoding->encoding].wchar2mb_with_len(from, (unsigned char *) to, pg_wchar_strlen(from));
733 }
size_t pg_wchar_strlen(const pg_wchar *str)
Definition: wstrncmp.c:70
wchar2mb_with_len_converter wchar2mb_with_len
Definition: pg_wchar.h:377
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74

◆ pg_wchar2mb_with_len()

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

Definition at line 737 of file mbutils.c.

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

Referenced by build_regexp_match_result(), build_regexp_split_result(), convertPgWchar(), and regexp_fixed_prefix().

738 {
739  return pg_wchar_table[DatabaseEncoding->encoding].wchar2mb_with_len(from, (unsigned char *) to, len);
740 }
wchar2mb_with_len_converter wchar2mb_with_len
Definition: pg_wchar.h:377
pg_enc encoding
Definition: pg_wchar.h:329
const pg_wchar_tbl pg_wchar_table[]
Definition: wchar.c:1777
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74

◆ pg_wchar_strlen()

size_t pg_wchar_strlen ( const pg_wchar wstr)

Definition at line 70 of file wstrncmp.c.

Referenced by pg_wchar2mb().

71 {
72  const pg_wchar *s;
73 
74  for (s = str; *s; ++s)
75  ;
76  return (s - str);
77 }
unsigned int pg_wchar
Definition: mbprint.c:31

◆ pg_wchar_strncmp()

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

Definition at line 40 of file wstrncmp.c.

41 {
42  if (n == 0)
43  return 0;
44  do
45  {
46  if (*s1 != *s2++)
47  return (*s1 - *(s2 - 1));
48  if (*s1++ == 0)
49  break;
50  } while (--n != 0);
51  return 0;
52 }
char * s1
char * s2

◆ PrepareClientEncoding()

int PrepareClientEncoding ( int  encoding)

Definition at line 103 of file mbutils.c.

References backend_startup_complete, ConvProcInfo::c_encoding, 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().

104 {
105  int current_server_encoding;
106  ListCell *lc;
107 
109  return -1;
110 
111  /* Can't do anything during startup, per notes above */
113  return 0;
114 
115  current_server_encoding = GetDatabaseEncoding();
116 
117  /*
118  * Check for cases that require no conversion function.
119  */
120  if (current_server_encoding == encoding ||
121  current_server_encoding == PG_SQL_ASCII ||
123  return 0;
124 
125  if (IsTransactionState())
126  {
127  /*
128  * If we're in a live transaction, it's safe to access the catalogs,
129  * so look up the functions. We repeat the lookup even if the info is
130  * already cached, so that we can react to changes in the contents of
131  * pg_conversion.
132  */
133  Oid to_server_proc,
134  to_client_proc;
135  ConvProcInfo *convinfo;
136  MemoryContext oldcontext;
137 
138  to_server_proc = FindDefaultConversionProc(encoding,
139  current_server_encoding);
140  if (!OidIsValid(to_server_proc))
141  return -1;
142  to_client_proc = FindDefaultConversionProc(current_server_encoding,
143  encoding);
144  if (!OidIsValid(to_client_proc))
145  return -1;
146 
147  /*
148  * Load the fmgr info into TopMemoryContext (could still fail here)
149  */
151  sizeof(ConvProcInfo));
152  convinfo->s_encoding = current_server_encoding;
153  convinfo->c_encoding = encoding;
154  fmgr_info_cxt(to_server_proc, &convinfo->to_server_info,
156  fmgr_info_cxt(to_client_proc, &convinfo->to_client_info,
158 
159  /* Attach new info to head of list */
161  ConvProcList = lcons(convinfo, ConvProcList);
162  MemoryContextSwitchTo(oldcontext);
163 
164  /*
165  * We cannot yet remove any older entry for the same encoding pair,
166  * since it could still be in use. SetClientEncoding will clean up.
167  */
168 
169  return 0; /* success */
170  }
171  else
172  {
173  /*
174  * If we're not in a live transaction, the only thing we can do is
175  * restore a previous setting using the cache. This covers all
176  * transaction-rollback cases. The only case it might not work for is
177  * trying to change client_encoding on the fly by editing
178  * postgresql.conf and SIGHUP'ing. Which would probably be a stupid
179  * thing to do anyway.
180  */
181  foreach(lc, ConvProcList)
182  {
183  ConvProcInfo *oldinfo = (ConvProcInfo *) lfirst(lc);
184 
185  if (oldinfo->s_encoding == current_server_encoding &&
186  oldinfo->c_encoding == encoding)
187  return 0;
188  }
189 
190  return -1; /* it's not cached, so fail */
191  }
192 }
FmgrInfo to_server_info
Definition: mbutils.c:57
FmgrInfo to_client_info
Definition: mbutils.c:58
static bool backend_startup_complete
Definition: mbutils.c:83
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
int s_encoding
Definition: mbutils.c:55
static List * ConvProcList
Definition: mbutils.c:61
#define PG_VALID_FE_ENCODING(_enc)
Definition: pg_wchar.h:305
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:134
MemoryContext TopMemoryContext
Definition: mcxt.c:44
int GetDatabaseEncoding(void)
Definition: mbutils.c:996
List * lcons(void *datum, List *list)
Definition: list.c:453
#define lfirst(lc)
Definition: pg_list.h:190
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:3673
bool IsTransactionState(void)
Definition: xact.c:356
int32 encoding
Definition: pg_database.h:41
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:771
int c_encoding
Definition: mbutils.c:56

◆ report_invalid_encoding()

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

Definition at line 2043 of file wchar.c.

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

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(), local2local(), LocalToUtf(), mic2big5(), mic2euc_cn(), mic2euc_jp(), mic2euc_kr(), mic2euc_tw(), mic2latin(), mic2latin_with_table(), mic2sjis(), pg_verify_mbstr_len(), shift_jis_20042euc_jis_2004(), sjis2euc_jp(), sjis2mic(), utf8_to_iso8859_1(), and UtfToLocal().

2044 {
2045  int l = pg_encoding_mblen(encoding, mbstr);
2046  char buf[8 * 5 + 1];
2047  char *p = buf;
2048  int j,
2049  jlimit;
2050 
2051  jlimit = Min(l, len);
2052  jlimit = Min(jlimit, 8); /* prevent buffer overrun */
2053 
2054  for (j = 0; j < jlimit; j++)
2055  {
2056  p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
2057  if (j < jlimit - 1)
2058  p += sprintf(p, " ");
2059  }
2060 
2061  ereport(ERROR,
2062  (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
2063  errmsg("invalid byte sequence for encoding \"%s\": %s",
2065  buf)));
2066 }
#define Min(x, y)
Definition: c.h:904
int errcode(int sqlerrcode)
Definition: elog.c:570
#define sprintf
Definition: port.h:194
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1833
#define ereport(elevel, rest)
Definition: elog.h:141
int32 encoding
Definition: pg_database.h:41
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ report_untranslatable_char()

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

Definition at line 2075 of file wchar.c.

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

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

2077 {
2078  int l = pg_encoding_mblen(src_encoding, mbstr);
2079  char buf[8 * 5 + 1];
2080  char *p = buf;
2081  int j,
2082  jlimit;
2083 
2084  jlimit = Min(l, len);
2085  jlimit = Min(jlimit, 8); /* prevent buffer overrun */
2086 
2087  for (j = 0; j < jlimit; j++)
2088  {
2089  p += sprintf(p, "0x%02x", (unsigned char) mbstr[j]);
2090  if (j < jlimit - 1)
2091  p += sprintf(p, " ");
2092  }
2093 
2094  ereport(ERROR,
2095  (errcode(ERRCODE_UNTRANSLATABLE_CHARACTER),
2096  errmsg("character with byte sequence %s in encoding \"%s\" has no equivalent in encoding \"%s\"",
2097  buf,
2098  pg_enc2name_tbl[src_encoding].name,
2099  pg_enc2name_tbl[dest_encoding].name)));
2100 }
#define Min(x, y)
Definition: c.h:904
int errcode(int sqlerrcode)
Definition: elog.c:570
#define sprintf
Definition: port.h:194
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
int pg_encoding_mblen(int encoding, const char *mbstr)
Definition: wchar.c:1833
#define ereport(elevel, rest)
Definition: elog.h:141
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ SetClientEncoding()

int SetClientEncoding ( int  encoding)

Definition at line 201 of file mbutils.c.

References backend_startup_complete, ConvProcInfo::c_encoding, encoding, foreach_delete_current, GetDatabaseEncoding(), lfirst, 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(), InitializeClientEncoding(), and ParallelWorkerMain().

202 {
203  int current_server_encoding;
204  bool found;
205  ListCell *lc;
206 
208  return -1;
209 
210  /* Can't do anything during startup, per notes above */
212  {
214  return 0;
215  }
216 
217  current_server_encoding = GetDatabaseEncoding();
218 
219  /*
220  * Check for cases that require no conversion function.
221  */
222  if (current_server_encoding == encoding ||
223  current_server_encoding == PG_SQL_ASCII ||
225  {
227  ToServerConvProc = NULL;
228  ToClientConvProc = NULL;
229  return 0;
230  }
231 
232  /*
233  * Search the cache for the entry previously prepared by
234  * PrepareClientEncoding; if there isn't one, we lose. While at it,
235  * release any duplicate entries so that repeated Prepare/Set cycles don't
236  * leak memory.
237  */
238  found = false;
239  foreach(lc, ConvProcList)
240  {
241  ConvProcInfo *convinfo = (ConvProcInfo *) lfirst(lc);
242 
243  if (convinfo->s_encoding == current_server_encoding &&
244  convinfo->c_encoding == encoding)
245  {
246  if (!found)
247  {
248  /* Found newest entry, so set up */
250  ToServerConvProc = &convinfo->to_server_info;
251  ToClientConvProc = &convinfo->to_client_info;
252  found = true;
253  }
254  else
255  {
256  /* Duplicate entry, release it */
258  pfree(convinfo);
259  }
260  }
261  }
262 
263  if (found)
264  return 0; /* success */
265  else
266  return -1; /* it's not cached, so fail */
267 }
FmgrInfo to_server_info
Definition: mbutils.c:57
FmgrInfo to_client_info
Definition: mbutils.c:58
static bool backend_startup_complete
Definition: mbutils.c:83
static int pending_client_encoding
Definition: mbutils.c:84
static FmgrInfo * ToServerConvProc
Definition: mbutils.c:67
static const pg_enc2name * ClientEncoding
Definition: mbutils.c:73
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
int s_encoding
Definition: mbutils.c:55
void pfree(void *pointer)
Definition: mcxt.c:1031
static List * ConvProcList
Definition: mbutils.c:61
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
#define PG_VALID_FE_ENCODING(_enc)
Definition: pg_wchar.h:305
int GetDatabaseEncoding(void)
Definition: mbutils.c:996
#define lfirst(lc)
Definition: pg_list.h:190
int32 encoding
Definition: pg_database.h:41
static FmgrInfo * ToClientConvProc
Definition: mbutils.c:68
int c_encoding
Definition: mbutils.c:56

◆ SetDatabaseEncoding()

void SetDatabaseEncoding ( int  encoding)

Definition at line 890 of file mbutils.c.

References Assert, elog, encoding, pg_enc2name::encoding, ERROR, pg_enc2name_tbl, and PG_VALID_BE_ENCODING.

Referenced by CheckMyDatabase().

891 {
893  elog(ERROR, "invalid database encoding: %d", encoding);
894 
897 }
#define ERROR
Definition: elog.h:43
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
pg_enc encoding
Definition: pg_wchar.h:329
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
#define Assert(condition)
Definition: c.h:732
int32 encoding
Definition: pg_database.h:41
static const pg_enc2name * DatabaseEncoding
Definition: mbutils.c:74
#define elog(elevel,...)
Definition: elog.h:226

◆ SetMessageEncoding()

void SetMessageEncoding ( int  encoding)

Definition at line 900 of file mbutils.c.

References Assert, CurrentMemoryContext, elog, encoding, pg_enc2name::encoding, GetDatabaseEncoding(), GetMessageEncoding(), i, LOG, pg_enc2gettext::name, name, pg_enc2gettext_tbl, pg_enc2name_tbl, pg_get_encoding_from_locale(), PG_SQL_ASCII, pg_strcasecmp(), PG_VALID_ENCODING, setlocale, and write_stderr.

Referenced by pg_perm_setlocale().

901 {
902  /* Some calls happen before we can elog()! */
904 
907 }
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:307
pg_enc encoding
Definition: pg_wchar.h:329
#define Assert(condition)
Definition: c.h:732
int32 encoding
Definition: pg_database.h:41
static const pg_enc2name * MessageEncoding
Definition: mbutils.c:75

◆ unicode_to_utf8()

unsigned char* unicode_to_utf8 ( pg_wchar  c,
unsigned char *  utf8string 
)

Definition at line 482 of file wchar.c.

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

483 {
484  if (c <= 0x7F)
485  {
486  utf8string[0] = c;
487  }
488  else if (c <= 0x7FF)
489  {
490  utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
491  utf8string[1] = 0x80 | (c & 0x3F);
492  }
493  else if (c <= 0xFFFF)
494  {
495  utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
496  utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
497  utf8string[2] = 0x80 | (c & 0x3F);
498  }
499  else
500  {
501  utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
502  utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
503  utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
504  utf8string[3] = 0x80 | (c & 0x3F);
505  }
506 
507  return utf8string;
508 }
char * c

◆ utf8_to_unicode()

pg_wchar utf8_to_unicode ( const unsigned char *  c)

Definition at line 751 of file wchar.c.

Referenced by pg_saslprep(), and pg_utf_dsplen().

752 {
753  if ((*c & 0x80) == 0)
754  return (pg_wchar) c[0];
755  else if ((*c & 0xe0) == 0xc0)
756  return (pg_wchar) (((c[0] & 0x1f) << 6) |
757  (c[1] & 0x3f));
758  else if ((*c & 0xf0) == 0xe0)
759  return (pg_wchar) (((c[0] & 0x0f) << 12) |
760  ((c[1] & 0x3f) << 6) |
761  (c[2] & 0x3f));
762  else if ((*c & 0xf8) == 0xf0)
763  return (pg_wchar) (((c[0] & 0x07) << 18) |
764  ((c[1] & 0x3f) << 12) |
765  ((c[2] & 0x3f) << 6) |
766  (c[3] & 0x3f));
767  else
768  /* that is an invalid code on purpose */
769  return 0xffffffff;
770 }
char * c
unsigned int pg_wchar
Definition: mbprint.c:31

◆ UtfToLocal()

void UtfToLocal ( const unsigned char *  utf,
int  len,
unsigned char *  iso,
const pg_mb_radix_tree map,
const pg_utf_to_local_combined cmap,
int  cmapsize,
utf_local_conversion_func  conv_func,
int  encoding 
)

Definition at line 429 of file conv.c.

References pg_utf_to_local_combined::code, compare3(), elog, ereport, errcode(), errmsg(), ERROR, pg_mb_radix_conv(), PG_UTF8, pg_utf8_islegal(), pg_utf_mblen(), PG_VALID_ENCODING, report_invalid_encoding(), report_untranslatable_char(), and store_coded_char().

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().

435 {
436  uint32 iutf;
437  int l;
438  const pg_utf_to_local_combined *cp;
439 
441  ereport(ERROR,
442  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
443  errmsg("invalid encoding number: %d", encoding)));
444 
445  for (; len > 0; len -= l)
446  {
447  unsigned char b1 = 0;
448  unsigned char b2 = 0;
449  unsigned char b3 = 0;
450  unsigned char b4 = 0;
451 
452  /* "break" cases all represent errors */
453  if (*utf == '\0')
454  break;
455 
456  l = pg_utf_mblen(utf);
457  if (len < l)
458  break;
459 
460  if (!pg_utf8_islegal(utf, l))
461  break;
462 
463  if (l == 1)
464  {
465  /* ASCII case is easy, assume it's one-to-one conversion */
466  *iso++ = *utf++;
467  continue;
468  }
469 
470  /* collect coded char of length l */
471  if (l == 2)
472  {
473  b3 = *utf++;
474  b4 = *utf++;
475  }
476  else if (l == 3)
477  {
478  b2 = *utf++;
479  b3 = *utf++;
480  b4 = *utf++;
481  }
482  else if (l == 4)
483  {
484  b1 = *utf++;
485  b2 = *utf++;
486  b3 = *utf++;
487  b4 = *utf++;
488  }
489  else
490  {
491  elog(ERROR, "unsupported character length %d", l);
492  iutf = 0; /* keep compiler quiet */
493  }
494  iutf = (b1 << 24 | b2 << 16 | b3 << 8 | b4);
495 
496  /* First, try with combined map if possible */
497  if (cmap && len > l)
498  {
499  const unsigned char *utf_save = utf;
500  int len_save = len;
501  int l_save = l;
502 
503  /* collect next character, same as above */
504  len -= l;
505 
506  l = pg_utf_mblen(utf);
507  if (len < l)
508  break;
509 
510  if (!pg_utf8_islegal(utf, l))
511  break;
512 
513  /* We assume ASCII character cannot be in combined map */
514  if (l > 1)
515  {
516  uint32 iutf2;
517  uint32 cutf[2];
518 
519  if (l == 2)
520  {
521  iutf2 = *utf++ << 8;
522  iutf2 |= *utf++;
523  }
524  else if (l == 3)
525  {
526  iutf2 = *utf++ << 16;
527  iutf2 |= *utf++ << 8;
528  iutf2 |= *utf++;
529  }
530  else if (l == 4)
531  {
532  iutf2 = *utf++ << 24;
533  iutf2 |= *utf++ << 16;
534  iutf2 |= *utf++ << 8;
535  iutf2 |= *utf++;
536  }
537  else
538  {
539  elog(ERROR, "unsupported character length %d", l);
540  iutf2 = 0; /* keep compiler quiet */
541  }
542 
543  cutf[0] = iutf;
544  cutf[1] = iutf2;
545 
546  cp = bsearch(cutf, cmap, cmapsize,
548 
549  if (cp)
550  {
551  iso = store_coded_char(iso, cp->code);
552  continue;
553  }
554  }
555 
556  /* fail, so back up to reprocess second character next time */
557  utf = utf_save;
558  len = len_save;
559  l = l_save;
560  }
561 
562  /* Now check ordinary map */
563  if (map)
564  {
565  uint32 converted = pg_mb_radix_conv(map, l, b1, b2, b3, b4);
566 
567  if (converted)
568  {
569  iso = store_coded_char(iso, converted);
570  continue;
571  }
572  }
573 
574  /* if there's a conversion function, try that */
575  if (conv_func)
576  {
577  uint32 converted = (*conv_func) (iutf);
578 
579  if (converted)
580  {
581  iso = store_coded_char(iso, converted);
582  continue;
583  }
584  }
585 
586  /* failed to translate this character */
588  (const char *) (utf - l), len);
589  }
590 
591  /* if we broke out of loop early, must be invalid input */
592  if (len > 0)
593  report_invalid_encoding(PG_UTF8, (const char *) utf, len);
594 
595  *iso = '\0';
596 }
bool pg_utf8_islegal(const unsigned char *source, int length)
Definition: wchar.c:1506
int errcode(int sqlerrcode)
Definition: elog.c:570
static unsigned char * store_coded_char(unsigned char *dest, uint32 code)
Definition: conv.c:278
#define ERROR
Definition: elog.h:43
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2075
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:301
static uint32 pg_mb_radix_conv(const pg_mb_radix_tree *rt, int l, unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4)
Definition: conv.c:298
unsigned int uint32
Definition: c.h:358
#define ereport(elevel, rest)
Definition: elog.h:141
static int compare3(const void *p1, const void *p2)
Definition: conv.c:245
int32 encoding
Definition: pg_database.h:41
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:2043
int pg_utf_mblen(const unsigned char *s)
Definition: wchar.c:548
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226

Variable Documentation

◆ pg_enc2gettext_tbl

const pg_enc2gettext pg_enc2gettext_tbl[]

Definition at line 359 of file encnames.c.

Referenced by SetMessageEncoding().

◆ pg_enc2name_tbl

◆ pg_wchar_table