PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
utf8_and_sjis2004.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * SHIFT_JIS_2004 <--> UTF8
4  *
5  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  * IDENTIFICATION
9  * src/backend/utils/mb/conversion_procs/utf8_and_sjis2004/utf8_and_sjis2004.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #include "postgres.h"
15 #include "fmgr.h"
16 #include "mb/pg_wchar.h"
17 #include "../../Unicode/shift_jis_2004_to_utf8.map"
18 #include "../../Unicode/utf8_to_shift_jis_2004.map"
19 #include "../../Unicode/shift_jis_2004_to_utf8_combined.map"
20 #include "../../Unicode/utf8_to_shift_jis_2004_combined.map"
21 
23 
26 
27 /* ----------
28  * conv_proc(
29  * INTEGER, -- source encoding id
30  * INTEGER, -- destination encoding id
31  * CSTRING, -- source string (null terminated C string)
32  * CSTRING, -- destination string (null terminated C string)
33  * INTEGER -- source string length
34  * ) returns VOID;
35  * ----------
36  */
37 Datum
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  LocalToUtf(src, len, dest,
47  LUmapSHIFT_JIS_2004, lengthof(LUmapSHIFT_JIS_2004),
48  LUmapSHIFT_JIS_2004_combined, lengthof(LUmapSHIFT_JIS_2004_combined),
49  NULL,
51 
53 }
54 
55 Datum
57 {
58  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
59  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
60  int len = PG_GETARG_INT32(4);
61 
63 
64  UtfToLocal(src, len, dest,
65  ULmapSHIFT_JIS_2004, lengthof(ULmapSHIFT_JIS_2004),
66  ULmapSHIFT_JIS_2004_combined, lengthof(ULmapSHIFT_JIS_2004_combined),
67  NULL,
69 
71 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
#define lengthof(array)
Definition: c.h:557
void UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_utf_to_local *map, int mapsize, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:390
PG_FUNCTION_INFO_V1(shift_jis_2004_to_utf8)
void LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_local_to_utf *map, int mapsize, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:576
Datum utf8_to_shift_jis_2004(PG_FUNCTION_ARGS)
Datum shift_jis_2004_to_utf8(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC
uintptr_t Datum
Definition: postgres.h:374
#define PG_RETURN_VOID()
Definition: fmgr.h:293
#define NULL
Definition: c.h:226
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150