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

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (euc_kr_to_mic)
 
 PG_FUNCTION_INFO_V1 (mic_to_euc_kr)
 
static void euc_kr2mic (const unsigned char *euc, unsigned char *p, int len)
 
static void mic2euc_kr (const unsigned char *mic, unsigned char *p, int len)
 
Datum euc_kr_to_mic (PG_FUNCTION_ARGS)
 
Datum mic_to_euc_kr (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

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

Definition at line 69 of file euc_kr_and_mic.c.

References IS_HIGHBIT_SET, LC_KS5601, pg_encoding_verifymb(), PG_EUC_KR, and report_invalid_encoding().

Referenced by euc_kr_to_mic().

70 {
71  int c1;
72  int l;
73 
74  while (len > 0)
75  {
76  c1 = *euc;
77  if (IS_HIGHBIT_SET(c1))
78  {
79  l = pg_encoding_verifymb(PG_EUC_KR, (const char *) euc, len);
80  if (l != 2)
82  (const char *) euc, len);
83  *p++ = LC_KS5601;
84  *p++ = c1;
85  *p++ = euc[1];
86  euc += 2;
87  len -= 2;
88  }
89  else
90  { /* should be ASCII */
91  if (c1 == 0)
93  (const char *) euc, len);
94  *p++ = c1;
95  euc++;
96  len--;
97  }
98  }
99  *p = '\0';
100 }
int pg_encoding_verifymb(int encoding, const char *mbstr, int len)
Definition: wchar.c:1809
#define IS_HIGHBIT_SET(ch)
Definition: c.h:973
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:1995
#define LC_KS5601
Definition: pg_wchar.h:132
Datum euc_kr_to_mic ( PG_FUNCTION_ARGS  )

Definition at line 38 of file euc_kr_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, euc_kr2mic(), PG_EUC_KR, 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_kr2mic(src, dest, len);
47 
49 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:492
static void euc_kr2mic(const unsigned char *euc, unsigned char *p, int len)
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
static void mic2euc_kr ( const unsigned char *  mic,
unsigned char *  p,
int  len 
)
static

Definition at line 106 of file euc_kr_and_mic.c.

References IS_HIGHBIT_SET, LC_KS5601, pg_encoding_verifymb(), PG_EUC_KR, PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by mic_to_euc_kr().

107 {
108  int c1;
109  int l;
110 
111  while (len > 0)
112  {
113  c1 = *mic;
114  if (!IS_HIGHBIT_SET(c1))
115  {
116  /* ASCII */
117  if (c1 == 0)
119  (const char *) mic, len);
120  *p++ = c1;
121  mic++;
122  len--;
123  continue;
124  }
125  l = pg_encoding_verifymb(PG_MULE_INTERNAL, (const char *) mic, len);
126  if (l < 0)
128  (const char *) mic, len);
129  if (c1 == LC_KS5601)
130  {
131  *p++ = mic[1];
132  *p++ = mic[2];
133  }
134  else
136  (const char *) mic, len);
137  mic += l;
138  len -= l;
139  }
140  *p = '\0';
141 }
int pg_encoding_verifymb(int encoding, const char *mbstr, int len)
Definition: wchar.c:1809
#define IS_HIGHBIT_SET(ch)
Definition: c.h:973
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: wchar.c:2027
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: wchar.c:1995
#define LC_KS5601
Definition: pg_wchar.h:132
Datum mic_to_euc_kr ( PG_FUNCTION_ARGS  )

Definition at line 52 of file euc_kr_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, mic2euc_kr(), PG_EUC_KR, 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_kr(src, dest, len);
61 
63 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:492
static void mic2euc_kr(const unsigned char *mic, unsigned char *p, int len)
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
PG_FUNCTION_INFO_V1 ( euc_kr_to_mic  )
PG_FUNCTION_INFO_V1 ( mic_to_euc_kr  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 18 of file euc_kr_and_mic.c.