PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
euc_cn_and_mic.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
Include dependency graph for euc_cn_and_mic.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (euc_cn_to_mic)
 
 PG_FUNCTION_INFO_V1 (mic_to_euc_cn)
 
static void euc_cn2mic (const unsigned char *euc, unsigned char *p, int len)
 
static void mic2euc_cn (const unsigned char *mic, unsigned char *p, int len)
 
Datum euc_cn_to_mic (PG_FUNCTION_ARGS)
 
Datum mic_to_euc_cn (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

static void euc_cn2mic ( const unsigned char *  euc,
unsigned char *  p,
int  len 
)
static

Definition at line 69 of file euc_cn_and_mic.c.

References IS_HIGHBIT_SET, LC_GB2312_80, PG_EUC_CN, and report_invalid_encoding().

Referenced by euc_cn_to_mic().

70 {
71  int c1;
72 
73  while (len > 0)
74  {
75  c1 = *euc;
76  if (IS_HIGHBIT_SET(c1))
77  {
78  if (len < 2 || !IS_HIGHBIT_SET(euc[1]))
79  report_invalid_encoding(PG_EUC_CN, (const char *) euc, len);
80  *p++ = LC_GB2312_80;
81  *p++ = c1;
82  *p++ = euc[1];
83  euc += 2;
84  len -= 2;
85  }
86  else
87  { /* should be ASCII */
88  if (c1 == 0)
89  report_invalid_encoding(PG_EUC_CN, (const char *) euc, len);
90  *p++ = c1;
91  euc++;
92  len--;
93  }
94  }
95  *p = '\0';
96 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:969
#define LC_GB2312_80
Definition: pg_wchar.h:130
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:1995
Datum euc_cn_to_mic ( PG_FUNCTION_ARGS  )

Definition at line 38 of file euc_cn_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, euc_cn2mic(), PG_EUC_CN, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_VOID.

39 {
40  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
41  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
42  int len = PG_GETARG_INT32(4);
43 
45 
46  euc_cn2mic(src, dest, len);
47 
49 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
static void euc_cn2mic(const unsigned char *euc, unsigned char *p, int len)
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
static void mic2euc_cn ( const unsigned char *  mic,
unsigned char *  p,
int  len 
)
static

Definition at line 102 of file euc_cn_and_mic.c.

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

Referenced by mic_to_euc_cn().

103 {
104  int c1;
105 
106  while (len > 0)
107  {
108  c1 = *mic;
109  if (IS_HIGHBIT_SET(c1))
110  {
111  if (c1 != LC_GB2312_80)
113  (const char *) mic, len);
114  if (len < 3 || !IS_HIGHBIT_SET(mic[1]) || !IS_HIGHBIT_SET(mic[2]))
116  (const char *) mic, len);
117  mic++;
118  *p++ = *mic++;
119  *p++ = *mic++;
120  len -= 3;
121  }
122  else
123  { /* should be ASCII */
124  if (c1 == 0)
126  (const char *) mic, len);
127  *p++ = c1;
128  mic++;
129  len--;
130  }
131  }
132  *p = '\0';
133 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:969
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2027
#define LC_GB2312_80
Definition: pg_wchar.h:130
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:1995
Datum mic_to_euc_cn ( PG_FUNCTION_ARGS  )

Definition at line 52 of file euc_cn_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, mic2euc_cn(), PG_EUC_CN, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_VOID.

53 {
54  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
55  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
56  int len = PG_GETARG_INT32(4);
57 
59 
60  mic2euc_cn(src, dest, len);
61 
63 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
static void mic2euc_cn(const unsigned char *mic, unsigned char *p, int len)
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
PG_FUNCTION_INFO_V1 ( euc_cn_to_mic  )
PG_FUNCTION_INFO_V1 ( mic_to_euc_cn  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 18 of file euc_cn_and_mic.c.