PostgreSQL Source Code  git master
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 int euc_kr2mic (const unsigned char *euc, unsigned char *p, int len, bool noError)
 
static int mic2euc_kr (const unsigned char *mic, unsigned char *p, int len, bool noError)
 
Datum euc_kr_to_mic (PG_FUNCTION_ARGS)
 
Datum mic_to_euc_kr (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ euc_kr2mic()

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

Definition at line 76 of file euc_kr_and_mic.c.

77 {
78  const unsigned char *start = euc;
79  int c1;
80  int l;
81 
82  while (len > 0)
83  {
84  c1 = *euc;
85  if (IS_HIGHBIT_SET(c1))
86  {
87  l = pg_encoding_verifymbchar(PG_EUC_KR, (const char *) euc, len);
88  if (l != 2)
89  {
90  if (noError)
91  break;
93  (const char *) euc, len);
94  }
95  *p++ = LC_KS5601;
96  *p++ = c1;
97  *p++ = euc[1];
98  euc += 2;
99  len -= 2;
100  }
101  else
102  { /* should be ASCII */
103  if (c1 == 0)
104  {
105  if (noError)
106  break;
108  (const char *) euc, len);
109  }
110  *p++ = c1;
111  euc++;
112  len--;
113  }
114  }
115  *p = '\0';
116 
117  return euc - start;
118 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1158
return str start
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1698
const void size_t len
@ PG_EUC_KR
Definition: pg_wchar.h:229
#define LC_KS5601
Definition: pg_wchar.h:135
int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len)
Definition: wchar.c:2103

References IS_HIGHBIT_SET, LC_KS5601, len, pg_encoding_verifymbchar(), PG_EUC_KR, report_invalid_encoding(), and start.

Referenced by euc_kr_to_mic().

◆ euc_kr_to_mic()

Datum euc_kr_to_mic ( PG_FUNCTION_ARGS  )

Definition at line 41 of file euc_kr_and_mic.c.

42 {
43  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
44  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
45  int len = PG_GETARG_INT32(4);
46  bool noError = PG_GETARG_BOOL(5);
47  int converted;
48 
50 
51  converted = euc_kr2mic(src, dest, len, noError);
52 
53  PG_RETURN_INT32(converted);
54 }
static int euc_kr2mic(const unsigned char *euc, unsigned char *p, int len, bool noError)
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
@ PG_MULE_INTERNAL
Definition: pg_wchar.h:233
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, euc_kr2mic(), len, PG_EUC_KR, PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_INT32.

◆ mic2euc_kr()

static int mic2euc_kr ( const unsigned char *  mic,
unsigned char *  p,
int  len,
bool  noError 
)
static

Definition at line 124 of file euc_kr_and_mic.c.

125 {
126  const unsigned char *start = mic;
127  int c1;
128  int l;
129 
130  while (len > 0)
131  {
132  c1 = *mic;
133  if (!IS_HIGHBIT_SET(c1))
134  {
135  /* ASCII */
136  if (c1 == 0)
137  {
138  if (noError)
139  break;
141  (const char *) mic, len);
142  }
143  *p++ = c1;
144  mic++;
145  len--;
146  continue;
147  }
148  l = pg_encoding_verifymbchar(PG_MULE_INTERNAL, (const char *) mic, len);
149  if (l < 0)
150  {
151  if (noError)
152  break;
154  (const char *) mic, len);
155  }
156  if (c1 == LC_KS5601)
157  {
158  *p++ = mic[1];
159  *p++ = mic[2];
160  }
161  else
162  {
163  if (noError)
164  break;
166  (const char *) mic, len);
167  }
168  mic += l;
169  len -= l;
170  }
171  *p = '\0';
172 
173  return mic - start;
174 }
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
Definition: mbutils.c:1730

References IS_HIGHBIT_SET, LC_KS5601, len, pg_encoding_verifymbchar(), PG_EUC_KR, PG_MULE_INTERNAL, report_invalid_encoding(), report_untranslatable_char(), and start.

Referenced by mic_to_euc_kr().

◆ mic_to_euc_kr()

Datum mic_to_euc_kr ( PG_FUNCTION_ARGS  )

Definition at line 57 of file euc_kr_and_mic.c.

58 {
59  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
60  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
61  int len = PG_GETARG_INT32(4);
62  bool noError = PG_GETARG_BOOL(5);
63  int converted;
64 
66 
67  converted = mic2euc_kr(src, dest, len, noError);
68 
69  PG_RETURN_INT32(converted);
70 }
static int mic2euc_kr(const unsigned char *mic, unsigned char *p, int len, bool noError)

References CHECK_ENCODING_CONVERSION_ARGS, generate_unaccent_rules::dest, len, mic2euc_kr(), PG_EUC_KR, PG_GETARG_BOOL, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_INT32.

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( euc_kr_to_mic  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( mic_to_euc_kr  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 18 of file euc_kr_and_mic.c.