PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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_MODULE_MAGIC_EXT (.name="euc_kr_and_mic",.version=PG_VERSION)
 
 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)
 

Function Documentation

◆ euc_kr2mic()

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

Definition at line 79 of file euc_kr_and_mic.c.

80{
81 const unsigned char *start = euc;
82 int c1;
83 int l;
84
85 while (len > 0)
86 {
87 c1 = *euc;
88 if (IS_HIGHBIT_SET(c1))
89 {
90 l = pg_encoding_verifymbchar(PG_EUC_KR, (const char *) euc, len);
91 if (l != 2)
92 {
93 if (noError)
94 break;
96 (const char *) euc, len);
97 }
98 *p++ = LC_KS5601;
99 *p++ = c1;
100 *p++ = euc[1];
101 euc += 2;
102 len -= 2;
103 }
104 else
105 { /* should be ASCII */
106 if (c1 == 0)
107 {
108 if (noError)
109 break;
111 (const char *) euc, len);
112 }
113 *p++ = c1;
114 euc++;
115 len--;
116 }
117 }
118 *p = '\0';
119
120 return euc - start;
121}
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1126
return str start
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1699
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:2189

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 44 of file euc_kr_and_mic.c.

45{
46 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
47 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
48 int len = PG_GETARG_INT32(4);
49 bool noError = PG_GETARG_BOOL(5);
50 int converted;
51
53
54 converted = euc_kr2mic(src, dest, len, noError);
55
56 PG_RETURN_INT32(converted);
57}
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 127 of file euc_kr_and_mic.c.

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

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 60 of file euc_kr_and_mic.c.

61{
62 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
63 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
64 int len = PG_GETARG_INT32(4);
65 bool noError = PG_GETARG_BOOL(5);
66 int converted;
67
69
70 converted = mic2euc_kr(src, dest, len, noError);
71
72 PG_RETURN_INT32(converted);
73}
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  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "euc_kr_and_mic",
version = PG_VERSION 
)