1
/*-------------------------------------------------------------------------
3
* SHIFT_JIS_2004 <--> UTF8
5
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
6
* Portions Copyright (c) 1994, Regents of the University of California
11
*-------------------------------------------------------------------------
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"
24
PG_FUNCTION_INFO_V1(shift_jis_2004_to_utf8);
25
PG_FUNCTION_INFO_V1(utf8_to_shift_jis_2004);
27
extern Datum shift_jis_2004_to_utf8(PG_FUNCTION_ARGS);
28
extern Datum utf8_to_shift_jis_2004(PG_FUNCTION_ARGS);
32
* INTEGER, -- source encoding id
33
* INTEGER, -- destination encoding id
34
* CSTRING, -- source string (null terminated C string)
35
* CSTRING, -- destination string (null terminated C string)
36
* INTEGER -- source string length
41
shift_jis_2004_to_utf8(PG_FUNCTION_ARGS)
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);
47
CHECK_ENCODING_CONVERSION_ARGS(PG_SHIFT_JIS_2004, PG_UTF8);
49
LocalToUtf(src, dest, LUmapSHIFT_JIS_2004, LUmapSHIFT_JIS_2004_combined,
50
sizeof(LUmapSHIFT_JIS_2004) / sizeof(pg_local_to_utf),
51
sizeof(LUmapSHIFT_JIS_2004_combined) / sizeof(pg_local_to_utf_combined),
52
PG_SHIFT_JIS_2004, len);
58
utf8_to_shift_jis_2004(PG_FUNCTION_ARGS)
60
unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
61
unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
62
int len = PG_GETARG_INT32(4);
64
CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SHIFT_JIS_2004);
66
UtfToLocal(src, dest, ULmapSHIFT_JIS_2004, ULmapSHIFT_JIS_2004_combined,
67
sizeof(ULmapSHIFT_JIS_2004) / sizeof(pg_utf_to_local),
68
sizeof(ULmapSHIFT_JIS_2004_combined) / sizeof(pg_utf_to_local_combined),
69
PG_SHIFT_JIS_2004, len);